summaryrefslogtreecommitdiff
path: root/src/atomic.h
blob: bcd8a47ac89df3886b442e41876455a1c233b138 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#ifndef __has_feature
#define __has_feature(x) 0
#endif
/**
 * Swap macro that enforces a happens-before relationship with a corresponding
 * ATOMIC_LOAD.
 */
#if __has_feature(cxx_atomic)
#define ATOMIC_SWAP(addr, val)\
	__atomic_exchange(addr, val, __ATOMIC_ACQ_REL)
#elif __has_builtin(__sync_swap)
#define ATOMIC_SWAP(addr, val)\
	__sync_swap(addr, val)
#else
#define ATOMIC_SWAP(addr, val)\
	__sync_lock_test_and_set(addr, val)
#endif

#if __has_feature(cxx_atomic)
#define ATOMIC_LOAD(addr)\
	__atomic_load(addr, __ATOMIC_ACQUIRE)
#else
#define ATOMIC_LOAD(addr)\
	(__sync_synchronize(), *addr)
#endif