Skip to content

Commit

Permalink
Resolved overwriting of lock during multithreading
Browse files Browse the repository at this point in the history
  • Loading branch information
RaiqaRasool committed Oct 1, 2024
1 parent 95e6b8d commit da70b50
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/libraries/JANA/Compatibility/JLockService.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ inline pthread_rwlock_t *JLockService::RootFillLock(JEventProcessor *proc) {
/// are in use and all contending for the same root lock. You should
/// only use this when filling a histogram and not for creating. Use
/// RootWriteLock and RootUnLock for that.

pthread_rwlock_t *lock;

pthread_rwlock_rdlock(&m_root_fill_locks_lock);
Expand All @@ -236,8 +235,14 @@ inline pthread_rwlock_t *JLockService::RootFillLock(JEventProcessor *proc) {
pthread_rwlock_unlock(&m_root_fill_locks_lock);
lock = new pthread_rwlock_t;
pthread_rwlock_wrlock(&m_root_fill_locks_lock);
pthread_rwlock_init(lock, nullptr);
m_root_fill_rw_lock[proc] = lock;
auto iter_now = m_root_fill_rw_lock.find(proc);
if(iter_now == m_root_fill_rw_lock.end()){
pthread_rwlock_init(lock, nullptr);
m_root_fill_rw_lock[proc] = lock;
}
else{
lock = iter_now->second;
}
}
else {
lock = iter->second;
Expand Down Expand Up @@ -265,7 +270,7 @@ inline pthread_rwlock_t *JLockService::RootFillUnLock(JEventProcessor *proc) {
}
pthread_rwlock_t *lock = iter->second;
pthread_rwlock_unlock(&m_root_fill_locks_lock);
pthread_rwlock_unlock(m_root_fill_rw_lock[proc]);
pthread_rwlock_unlock(lock);
return lock;
}

Expand Down

0 comments on commit da70b50

Please sign in to comment.