From da70b5079ea7749cde99cc26feefa888b0225054 Mon Sep 17 00:00:00 2001 From: raiqarasool Date: Tue, 1 Oct 2024 15:53:40 -0400 Subject: [PATCH] Resolved overwriting of lock during multithreading --- src/libraries/JANA/Compatibility/JLockService.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libraries/JANA/Compatibility/JLockService.h b/src/libraries/JANA/Compatibility/JLockService.h index 44122875b..fb7b3e1a1 100644 --- a/src/libraries/JANA/Compatibility/JLockService.h +++ b/src/libraries/JANA/Compatibility/JLockService.h @@ -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); @@ -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; @@ -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; }