xref: /minix3/external/bsd/libc++/dist/libcxxrt/src/atomic.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
14684ddb6SLionel Sambuc 
24684ddb6SLionel Sambuc #ifndef __has_builtin
34684ddb6SLionel Sambuc #define __has_builtin(x) 0
44684ddb6SLionel Sambuc #endif
54684ddb6SLionel Sambuc #ifndef __has_feature
64684ddb6SLionel Sambuc #define __has_feature(x) 0
74684ddb6SLionel Sambuc #endif
84684ddb6SLionel Sambuc /**
94684ddb6SLionel Sambuc  * Swap macro that enforces a happens-before relationship with a corresponding
104684ddb6SLionel Sambuc  * ATOMIC_LOAD.
114684ddb6SLionel Sambuc  */
124684ddb6SLionel Sambuc #if __has_builtin(__c11_atomic_exchange)
134684ddb6SLionel Sambuc #define ATOMIC_SWAP(addr, val)\
14*0a6a1f1dSLionel Sambuc 	__c11_atomic_exchange(reinterpret_cast<_Atomic(__typeof__(val))*>(addr), val, __ATOMIC_ACQ_REL)
154684ddb6SLionel Sambuc #elif __has_builtin(__sync_swap)
164684ddb6SLionel Sambuc #define ATOMIC_SWAP(addr, val)\
174684ddb6SLionel Sambuc 	__sync_swap(addr, val)
184684ddb6SLionel Sambuc #else
194684ddb6SLionel Sambuc #define ATOMIC_SWAP(addr, val)\
204684ddb6SLionel Sambuc 	__sync_lock_test_and_set(addr, val)
214684ddb6SLionel Sambuc #endif
224684ddb6SLionel Sambuc 
234684ddb6SLionel Sambuc #if __has_builtin(__c11_atomic_load)
244684ddb6SLionel Sambuc #define ATOMIC_LOAD(addr)\
25*0a6a1f1dSLionel Sambuc 	__c11_atomic_load(reinterpret_cast<_Atomic(__typeof__(*addr))*>(addr), __ATOMIC_ACQUIRE)
264684ddb6SLionel Sambuc #else
274684ddb6SLionel Sambuc #define ATOMIC_LOAD(addr)\
284684ddb6SLionel Sambuc 	(__sync_synchronize(), *addr)
294684ddb6SLionel Sambuc #endif
304684ddb6SLionel Sambuc 
31