1 #ifndef __SSIATOMICS_HH__ 2 #define __SSIATOMICS_HH__ 34 #undef NEED_ATOMIC_MUTEX 39 #if __cplusplus >= 201103L 41 #define Atomic(type) std::atomic<type> 42 #define Atomic_IMP "C++11" 44 #define Atomic_DEC(x) x.fetch_sub(1,std::memory_order_relaxed) 45 #define Atomic_GET(x) x.load(std::memory_order_relaxed) 46 #define Atomic_GET_STRICT(x) x.load(std::memory_order_acquire) 47 #define Atomic_INC(x) x.fetch_add(1,std::memory_order_relaxed) 48 #define Atomic_SET(x,y) x.store(y,std::memory_order_relaxed) 49 #define Atomic_SET_STRICT(x,y) x.store(y,std::memory_order_release) 50 #define Atomic_ZAP(x) x.store(0,std::memory_order_relaxed) 56 #elif __GNUC__ == 4 && __GNUC_MINOR__ > 6 57 #define Atomic(type) type 58 #define Atomic_IMP "gnu-atomic" 60 #define Atomic_DEC(x) __atomic_fetch_sub(&x,1,__ATOMIC_RELAXED) 61 #define Atomic_GET(x) __atomic_load_n (&x, __ATOMIC_RELAXED) 62 #define Atomic_GET_STRICT(x) __atomic_load_n (&x, __ATOMIC_ACQUIRE) 63 #define Atomic_INC(x) __atomic_fetch_add(&x,1,__ATOMIC_RELAXED) 64 #define Atomic_SET(x,y) __atomic_store_n (&x,y,__ATOMIC_RELAXED) 65 #define Atomic_SET_STRICT(x,y) __atomic_store_n (&x,y,__ATOMIC_RELEASE) 66 #define Atomic_ZAP(x) __atomic_store_n (&x,0,__ATOMIC_RELAXED) 75 #define Atomic(type) type 76 #define Atomic_IMP "gnu-sync" 78 #define Atomic_DEC(x) __sync_fetch_and_sub(&x, 1) 79 #define Atomic_GET(x) __sync_fetch_and_or (&x, 0) 80 #define Atomic_GET_STRICT(x) __sync_fetch_and_or (&x, 0) 81 #define Atomic_INC(x) __sync_fetch_and_add(&x, 1) 82 #define Atomic_SET(x,y) x=y,__sync_synchronize() 83 #define Atomic_SET_STRICT(x,y) __sync_synchronize(),x=y,__sync_synchronize() 84 #define Atomic_ZAP(x) __sync_fetch_and_and(&x, 0) 91 #define NEED_ATOMIC_MUTEX 1 92 #define Atomic_IMP "missing" 93 #define Atomic(type) type 94 #define Atomic_BEG(x) pthread_mutex_lock(x) 95 #define Atomic_DEC(x) x-- 96 #define Atomic_GET(x) x 97 #define Atomic_INC(x) x++ 98 #define Atomic_SET(x,y) x = y 99 #define Atomic_ZAP(x) x = 0 100 #define Atomic_END(x) pthread_mutex_unlock(x) 114 inline bool TryLock() {
return pthread_mutex_trylock( &
cs ) == 0;}
116 inline void Lock() {pthread_mutex_lock(&
cs);}
124 if (mt ==
Simple) rc = pthread_mutex_init(&
cs, NULL);
125 else {pthread_mutexattr_t attr;
126 if (!(rc = pthread_mutexattr_init(&attr)))
127 {pthread_mutexattr_settype(&attr,
128 PTHREAD_MUTEX_RECURSIVE);
129 rc = pthread_mutex_init(&
cs, &attr);
132 if (rc)
throw strerror(rc);
163 {
if (mutex) mutex->Lock();
void Lock()
Definition: XrdSsiAtomics.hh:116
Definition: XrdSsiAtomics.hh:110
XrdSsiMutex * mtx
Definition: XrdSsiAtomics.hh:173
XrdSsiMutexMon(XrdSsiMutex *mutex=0)
Definition: XrdSsiAtomics.hh:162
bool TryLock()
Definition: XrdSsiAtomics.hh:114
Definition: XrdSsiAtomics.hh:120
Definition: XrdSsiAtomics.hh:120
MutexType
Definition: XrdSsiAtomics.hh:120
void Lock(XrdSsiMutex &mutex)
Definition: XrdSsiAtomics.hh:158
Definition: XrdSsiAtomics.hh:146
pthread_mutex_t cs
Definition: XrdSsiAtomics.hh:139
~XrdSsiMutexMon()
Definition: XrdSsiAtomics.hh:171
~XrdSsiMutex()
Definition: XrdSsiAtomics.hh:135
XrdSsiMutexMon(XrdSsiMutex &mutex)
Definition: XrdSsiAtomics.hh:166
void UnLock()
Definition: XrdSsiAtomics.hh:160
void Lock(XrdSsiMutex *mutex)
Definition: XrdSsiAtomics.hh:150
void UnLock()
Definition: XrdSsiAtomics.hh:118
XrdSsiMutex(MutexType mt=Simple)
Definition: XrdSsiAtomics.hh:122