xrootd
|
00001 #ifndef _XRDSYSATOMICS_ 00002 #define _XRDSYSATOMICS_ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d S y s A t o m i c s . h h */ 00006 /* */ 00007 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 /* The following instruction acronyms are used: 00014 AtomicCAS() -> Compare And [if equal] Set 00015 AtomicDTZ() -> Decrease To Zero 00016 AtomicFAZ() -> Fetch And Zero 00017 AtomicISM() -> Increase and Set Maximum 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