Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/libcxxrt/atomic.h
#ifndef __has_builtin | #ifndef __has_builtin | ||||
#define __has_builtin(x) 0 | #define __has_builtin(x) 0 | ||||
#endif | #endif | ||||
#ifndef __has_feature | #ifndef __has_feature | ||||
#define __has_feature(x) 0 | #define __has_feature(x) 0 | ||||
#endif | #endif | ||||
/** | /** | ||||
* Swap macro that enforces a happens-before relationship with a corresponding | * Swap macro that enforces a happens-before relationship with a corresponding | ||||
* ATOMIC_LOAD. | * ATOMIC_LOAD. | ||||
*/ | */ | ||||
#if __has_builtin(__c11_atomic_exchange) | #if __has_builtin(__c11_atomic_exchange) | ||||
#define ATOMIC_SWAP(addr, val)\ | #define ATOMIC_SWAP(addr, val)\ | ||||
__c11_atomic_exchange((_Atomic(__typeof__(val))*)addr, val, __ATOMIC_ACQ_REL) | __c11_atomic_exchange(reinterpret_cast<_Atomic(__typeof__(val))*>(addr), val, __ATOMIC_ACQ_REL) | ||||
#elif __has_builtin(__sync_swap) | #elif __has_builtin(__sync_swap) | ||||
#define ATOMIC_SWAP(addr, val)\ | #define ATOMIC_SWAP(addr, val)\ | ||||
__sync_swap(addr, val) | __sync_swap(addr, val) | ||||
#else | #else | ||||
#define ATOMIC_SWAP(addr, val)\ | #define ATOMIC_SWAP(addr, val)\ | ||||
__sync_lock_test_and_set(addr, val) | __sync_lock_test_and_set(addr, val) | ||||
#endif | #endif | ||||
#if __has_builtin(__c11_atomic_load) | #if __has_builtin(__c11_atomic_load) | ||||
#define ATOMIC_LOAD(addr)\ | #define ATOMIC_LOAD(addr)\ | ||||
__c11_atomic_load((_Atomic(__typeof__(*addr))*)addr, __ATOMIC_ACQUIRE) | __c11_atomic_load(reinterpret_cast<_Atomic(__typeof__(*addr))*>(addr), __ATOMIC_ACQUIRE) | ||||
#else | #else | ||||
#define ATOMIC_LOAD(addr)\ | #define ATOMIC_LOAD(addr)\ | ||||
(__sync_synchronize(), *addr) | (__sync_synchronize(), *addr) | ||||
#endif | #endif | ||||