7b9fef1391
* Don't call the _fast version of the TLS accessor in terminate() or unexpected(). 1) TLS may not have been set up yet. 2) When we're in one of these functions, Really Bad Stuff has happened and potentially saving a few cycles really isn't important. * Merge in fixes from FreeBSD trunk to make atomics work with recent clang. MFC after: 1 week
30 lines
747 B
C
30 lines
747 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((_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((_Atomic(__typeof__(*addr))*)addr, __ATOMIC_ACQUIRE)
|
|
#else
|
|
#define ATOMIC_LOAD(addr)\
|
|
(__sync_synchronize(), *addr)
|
|
#endif
|