atomic.h revision 245304
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_feature(cxx_atomic)
13#define ATOMIC_SWAP(addr, val)\
14	__atomic_exchange(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_feature(cxx_atomic)
24#define ATOMIC_LOAD(addr)\
25	__atomic_load(addr, __ATOMIC_ACQUIRE)
26#else
27#define ATOMIC_LOAD(addr)\
28	(__sync_synchronize(), *addr)
29#endif
30