freebsd-dev/contrib/libcxxrt/atomic.h
Dimitry Andric f2dc4184d2 Import libcxxrt master 00bc29eb6513624824a6d7db2ebc768a4216a604.
Interesting fixes:
76584a0  Reorganize code to use only 32bit atomic ops for 32bit platforms
30d2ae5  Implement __cxa_throw_bad_array_new_length

Reviewed by:	bapt
MFC after:	1 month
Differential Revision: https://reviews.freebsd.org/D1390
2014-12-30 20:01:06 +00:00

31 lines
784 B
C

#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_builtin(__c11_atomic_exchange)
#define ATOMIC_SWAP(addr, val)\
__c11_atomic_exchange(reinterpret_cast<_Atomic(__typeof__(val))*>(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_builtin(__c11_atomic_load)
#define ATOMIC_LOAD(addr)\
__c11_atomic_load(reinterpret_cast<_Atomic(__typeof__(*addr))*>(addr), __ATOMIC_ACQUIRE)
#else
#define ATOMIC_LOAD(addr)\
(__sync_synchronize(), *addr)
#endif