00001 #ifndef _XRDSYSATOMICS_
00002 #define _XRDSYSATOMICS_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_ATOMICS
00021 #define AtomicBeg(Mtx)
00022 #define AtomicEnd(Mtx)
00023 #define AtomicAdd(x, y) __sync_fetch_and_add(&x, y)
00024 #define AtomicCAS(x, y, z) __sync_bool_compare_and_swap(&x, y, z)
00025 #define AtomicDec(x) __sync_fetch_and_sub(&x, 1)
00026 #define AtomicDTZ(x) if (!(__sync_fetch_and_sub(&x, 1))) AtomicFAZ(x)
00027 #define AtomicFAZ(x) __sync_fetch_and_and(&x, 0)
00028 #define AtomicGet(x) __sync_fetch_and_or(&x, 0)
00029 #define AtomicInc(x) __sync_fetch_and_add(&x, 1)
00030 #define AtomicISM(x, y) AtomicCAS(y, AtomicInc(x), x)
00031 #define AtomicSub(x, y) __sync_fetch_and_sub(&x, y)
00032 #else
00033 #define AtomicBeg(Mtx) Mtx.Lock()
00034 #define AtomicEnd(Mtx) Mtx.UnLock()
00035 #define AtomicAdd(x, y) x += y
00036 #define AtomicCAS(x, y, z) if (x == y) x = z
00037 #define AtomicDTZ(x) if (!(x--)) x = 0
00038 #define AtomicDec(x) x--
00039 #define AtomicFAZ(x) x; x = 0
00040 #define AtomicGet(x) x
00041 #define AtomicInc(x) x++
00042 #define AtomicISM(x, y) if (y == x++) y = x
00043 #define AtomicSub(x, y) x -= y
00044 #endif
00045 #endif