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)
113inline bool TryLock() {
return pthread_mutex_trylock( &
cs ) == 0;}
115inline void Lock() {pthread_mutex_lock(&
cs);}
123 if (mt ==
Simple) rc = pthread_mutex_init(&
cs, NULL);
124 else {pthread_mutexattr_t attr;
125 if (!(rc = pthread_mutexattr_init(&attr)))
126 {pthread_mutexattr_settype(&attr,
127 PTHREAD_MUTEX_RECURSIVE);
128 rc = pthread_mutex_init(&
cs, &attr);
167 {
if (mutex) mutex->Lock();
Definition XrdSsiAtomics.hh:149
XrdSsiMutexMon(XrdSsiMutex &mutex)
Definition XrdSsiAtomics.hh:170
~XrdSsiMutexMon()
Definition XrdSsiAtomics.hh:175
void Lock(XrdSsiMutex &mutex)
Definition XrdSsiAtomics.hh:160
XrdSsiMutex * mtx
Definition XrdSsiAtomics.hh:177
XrdSsiMutexMon(XrdSsiMutex *mutex=0)
Definition XrdSsiAtomics.hh:166
void UnLock()
Definition XrdSsiAtomics.hh:164
void Lock(XrdSsiMutex *mutex)
Definition XrdSsiAtomics.hh:152
void Reset()
Definition XrdSsiAtomics.hh:162
Definition XrdSsiAtomics.hh:110
void UnLock()
Definition XrdSsiAtomics.hh:117
MutexType
Definition XrdSsiAtomics.hh:119
@ Recursive
Definition XrdSsiAtomics.hh:119
@ Simple
Definition XrdSsiAtomics.hh:119
XrdSsiMutex(MutexType mt=Simple)
Definition XrdSsiAtomics.hh:121
bool TryLock()
Definition XrdSsiAtomics.hh:113
void Lock()
Definition XrdSsiAtomics.hh:115
const char * Errno2Text(int ecode)
~XrdSsiMutex()
Definition XrdSsiAtomics.hh:134
pthread_mutex_t cs
Definition XrdSsiAtomics.hh:138