1
2#ifndef __has_builtin
3#define __has_builtin(x) 0
4#endif
5#ifndef __has_feature
6#define __has_feature(x) 0
7#endif
8/**
9 * Swap macro that enforces a happens-before relationship with a corresponding
10 * ATOMIC_LOAD.
11 */
12#if __has_builtin(__c11_atomic_exchange)
13#define ATOMIC_SWAP(addr, val)\
14	__c11_atomic_exchange(reinterpret_cast<_Atomic(__typeof__(val))*>(addr), val, __ATOMIC_ACQ_REL)
15#elif __has_builtin(__sync_swap)
16#define ATOMIC_SWAP(addr, val)\
17	__sync_swap(addr, val)
18#else
19#define ATOMIC_SWAP(addr, val)\
20	__sync_lock_test_and_set(addr, val)
21#endif
22
23#if __has_builtin(__c11_atomic_load)
24#define ATOMIC_LOAD(addr)\
25	__c11_atomic_load(reinterpret_cast<_Atomic(__typeof__(*addr))*>(addr), __ATOMIC_ACQUIRE)
26#else
27#define ATOMIC_LOAD(addr)\
28	(__sync_synchronize(), *addr)
29#endif
30
31