Commit 523659e2 authored by Georgios Bitzes's avatar Georgios Bitzes Committed by Elvin Sindrilaru

COMMON: Fix data-race on mRdLockCounter / mWrLockCounter

HAVE_ATOMICS was not defined in all compilation units using GetReadLockCounter / GetWriteLockCounter, resulting in racy reads. Changed the two counters to use std::atomic instead. WARNING: ThreadSanitizer: data race (pid=25899) Atomic write of size 8 at 0x7f6ef3633948 by thread T189 (mutexes: write M2048): #0 __tsan_atomic64_fetch_add <null> (libtsan.so.0+0x000000064c50) #1 eos::common::RWMutex::LockWrite() /afs/cern.ch/user/g/gbitzes/dev/eos-dev/common/RWMutex.cc:378 (libeosCommon.so.4+0x000000044014) #2 eos::common::RWMutexWriteLock::RWMutexWriteLock(eos::common::RWMutex&) /afs/cern.ch/user/g/gbitzes/dev/eos-dev/common/RWMutex.cc:1259 (libeosCommon.so.4+0x000000044309) #3 XrdMgmOfs::FsConfigListener() /afs/cern.ch/user/g/gbitzes/dev/eos-dev/mgm/XrdMgmOfs/FsConfigListener.cc:212 (libXrdEosMgm.so+0x0000004b5641) #4 XrdMgmOfs::StartMgmFsConfigListener(void*) /afs/cern.ch/user/g/gbitzes/dev/eos-dev/mgm/XrdMgmOfs.cc:664 (libXrdEosMgm.so+0x0000004b7c15) #5 XrdSysThread_Xeq <null> (libXrdUtils.so.2+0x00000002d75e) #6 <null> <null> (libtsan.so.0+0x0000000257eb) Previous read of size 8 at 0x7f6ef3633948 by thread T187: #0 eos::mgm::Stat::Circulate() /afs/cern.ch/user/g/gbitzes/dev/eos-dev/mgm/Stat.cc:1195 (libXrdEosMgm.so+0x000000580e8b) #1 XrdMgmOfs::StartMgmStats(void*) /afs/cern.ch/user/g/gbitzes/dev/eos-dev/mgm/XrdMgmOfs.cc:653 (libXrdEosMgm.so+0x000000484c35) #2 XrdSysThread_Xeq <null> (libXrdUtils.so.2+0x00000002d75e) #3 <null> <null> (libtsan.so.0+0x0000000257eb) Location is global 'eos::mgm::FsView::gFsView' of size 2400 at 0x7f6ef36335e0 (libXrdEosMgm.so+0x000000b5d948)
parent c84510bd
......@@ -70,7 +70,7 @@ pthread_rwlock_t RWMutex::mOrderChkLock;
// what = mRd or mWr
#define EOS_RWMUTEX_TIMER_STOP_AND_UPDATE(what) \
AtomicInc(what##LockCounter); \
(what##LockCounter)++; \
if(issampled) { \
tstamp = Timing::GetNowInNs() - tstamp; \
if(mEnableTiming) { \
......
......@@ -177,7 +177,7 @@ public:
//----------------------------------------------------------------------------
inline uint64_t GetReadLockCounter()
{
return AtomicGet(mRdLockCounter);
return mRdLockCounter.load();
}
//----------------------------------------------------------------------------
......@@ -185,7 +185,7 @@ public:
//----------------------------------------------------------------------------
inline uint64_t GetWriteLockCounter()
{
return AtomicGet(mWrLockCounter);
return mWrLockCounter.load();
}
#ifdef EOS_INSTRUMENTED_RWMUTEX
......@@ -473,8 +473,8 @@ private:
pthread_rwlock_t rwlock;
pthread_rwlockattr_t attr;
struct timespec wlocktime;
uint64_t mRdLockCounter;
uint64_t mWrLockCounter;
std::atomic<uint64_t> mRdLockCounter;
std::atomic<uint64_t> mWrLockCounter;
bool mPreferRd; ///< If true reads go ahead of wr and are reentrant
#ifdef EOS_INSTRUMENTED_RWMUTEX
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment