Go to the documentation of this file. 1 #ifndef _XRDSYSATOMICS_
2 #define _XRDSYSATOMICS_
48 #define AtomicBeg(Mtx)
49 #define AtomicEnd(Mtx)
50 #define AtomicAdd(x, y) __sync_fetch_and_add(&x, y)
51 #define AtomicFAdd(w,x,y) w = __sync_fetch_and_add(&x, y)
52 #define AtomicCAS(x, y, z) __sync_bool_compare_and_swap(&x, y, z)
53 #define AtomicDec(x) __sync_fetch_and_sub(&x, 1)
54 #define AtomicFAZ(x) __sync_fetch_and_and(&x, 0)
55 #define AtomicFZAP(w,x) w = __sync_fetch_and_and(&x, 0)
56 #define AtomicGet(x) __sync_fetch_and_or(&x, 0)
57 #define AtomicInc(x) __sync_fetch_and_add(&x, 1)
58 #define AtomicSub(x, y) __sync_fetch_and_sub(&x, y)
59 #define AtomicFSub(w,x,y) w = __sync_fetch_and_sub(&x, y)
60 #define AtomicZAP(x) __sync_fetch_and_and(&x, 0)
61 #define AtomicRet(mtx, x) return AtomicGet(x)
63 #define AtomicBeg(Mtx) Mtx.Lock()
64 #define AtomicEnd(Mtx) Mtx.UnLock()
65 #define AtomicAdd(x, y) x += y // When assigning use AtomicFAdd!
66 #define AtomicFAdd(w,x,y) {w = x; x += y;}
67 #define AtomicCAS(x, y, z) if (x == y) x = z
68 #define AtomicDec(x) x--
69 #define AtomicFAZ(x) x; x = 0 // Braces when used with if-else!
70 #define AtomicFZAP(w,x) {w = x; x = 0;}
71 #define AtomicGet(x) x
72 #define AtomicInc(x) x++
73 #define AtomicSub(x, y) x -= y // When assigning use AtomicFSub!
74 #define AtomicFSub(w,x,y) {w = x; x -= y;}
75 #define AtomicZAP(x) x = 0
76 #define AtomicRet(mtx, x) {mtx.Lock(); int _ ## x = x; \
77 mtx.UnLock(); return _ ## x;}
89 #if __cplusplus >= 201103L
91 #define CPP_ATOMIC_LOAD(x, order) x.load(order)
92 #define CPP_ATOMIC_STORE(x, val, order) x.store(val, order)
93 #define CPP_ATOMIC_TYPE(kind) std::atomic<kind>
95 #define CPP_ATOMIC_LOAD(x, order) x
96 #define CPP_ATOMIC_STORE(x, val, order) x = val
97 #define CPP_ATOMIC_TYPE(kind) kind