14cc2045aSjoerg 
24cc2045aSjoerg #ifndef __has_builtin
34cc2045aSjoerg #define __has_builtin(x) 0
44cc2045aSjoerg #endif
54cc2045aSjoerg #ifndef __has_feature
64cc2045aSjoerg #define __has_feature(x) 0
74cc2045aSjoerg #endif
84cc2045aSjoerg /**
94cc2045aSjoerg  * Swap macro that enforces a happens-before relationship with a corresponding
104cc2045aSjoerg  * ATOMIC_LOAD.
114cc2045aSjoerg  */
124cc2045aSjoerg #if __has_builtin(__c11_atomic_exchange)
134cc2045aSjoerg #define ATOMIC_SWAP(addr, val)\
14*5192b81bSjoerg 	__c11_atomic_exchange(reinterpret_cast<_Atomic(__typeof__(val))*>(addr), val, __ATOMIC_ACQ_REL)
154cc2045aSjoerg #elif __has_builtin(__sync_swap)
164cc2045aSjoerg #define ATOMIC_SWAP(addr, val)\
174cc2045aSjoerg 	__sync_swap(addr, val)
184cc2045aSjoerg #else
194cc2045aSjoerg #define ATOMIC_SWAP(addr, val)\
204cc2045aSjoerg 	__sync_lock_test_and_set(addr, val)
214cc2045aSjoerg #endif
224cc2045aSjoerg 
234cc2045aSjoerg #if __has_builtin(__c11_atomic_load)
244cc2045aSjoerg #define ATOMIC_LOAD(addr)\
25*5192b81bSjoerg 	__c11_atomic_load(reinterpret_cast<_Atomic(__typeof__(*addr))*>(addr), __ATOMIC_ACQUIRE)
264cc2045aSjoerg #else
274cc2045aSjoerg #define ATOMIC_LOAD(addr)\
284cc2045aSjoerg 	(__sync_synchronize(), *addr)
294cc2045aSjoerg #endif
30f6239462Sjoerg 
31