Changeset View
Changeset View
Standalone View
Standalone View
contrib/compiler-rt/lib/builtins/atomic.c
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// | ||||
// Platform-specific lock implementation. Falls back to spinlocks if none is | // Platform-specific lock implementation. Falls back to spinlocks if none is | ||||
// defined. Each platform should define the Lock type, and corresponding | // defined. Each platform should define the Lock type, and corresponding | ||||
// lock() and unlock() functions. | // lock() and unlock() functions. | ||||
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// | ||||
#ifdef __FreeBSD__ | #ifdef __FreeBSD__ | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <machine/atomic.h> | |||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <machine/atomic.h> | |||||
luporl: Why did you need to change the include order of machine/atomic.h and sys/types.h? | |||||
Done Inline Actions"machine/atomic.h" uses types like "uint32_t" that are only defined in "sys/types.h", so it should come first alfredo: "machine/atomic.h" uses types like "uint32_t" that are only defined in "sys/types.h", so it… | |||||
Done Inline ActionsI think in accordance with style(9), machine/ includes should come after all sys/ includes. jhibbits: I think in accordance with style(9), machine/ includes should come after all sys/ includes. | |||||
#include <sys/umtx.h> | #include <sys/umtx.h> | ||||
typedef struct _usem Lock; | typedef struct _usem Lock; | ||||
__inline static void unlock(Lock *l) { | __inline static void unlock(Lock *l) { | ||||
__c11_atomic_store((_Atomic(uint32_t) *)&l->_count, 1, __ATOMIC_RELEASE); | __c11_atomic_store((_Atomic(uint32_t) *)&l->_count, 1, __ATOMIC_RELEASE); | ||||
__c11_atomic_thread_fence(__ATOMIC_SEQ_CST); | __c11_atomic_thread_fence(__ATOMIC_SEQ_CST); | ||||
if (l->_has_waiters) | if (l->_has_waiters) | ||||
_umtx_op(l, UMTX_OP_SEM_WAKE, 1, 0, 0); | _umtx_op(l, UMTX_OP_SEM_WAKE, 1, 0, 0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | static __inline Lock *lock_for_pointer(void *ptr) { | ||||
// Now use the high(er) set of bits to perturb the hash, so that we don't | // Now use the high(er) set of bits to perturb the hash, so that we don't | ||||
// get collisions from atomic fields in a single object | // get collisions from atomic fields in a single object | ||||
hash >>= 16; | hash >>= 16; | ||||
hash ^= low; | hash ^= low; | ||||
// Return a pointer to the word to use | // Return a pointer to the word to use | ||||
return locks + (hash & SPINLOCK_MASK); | return locks + (hash & SPINLOCK_MASK); | ||||
} | } | ||||
/// Macros for determining whether a size is lock free. Clang can not yet | /// Macros for determining whether a size is lock free. | ||||
/// codegen __atomic_is_lock_free(16), so for now we assume 16-byte values are | |||||
/// not lock free. | |||||
#define IS_LOCK_FREE_1 __c11_atomic_is_lock_free(1) | #define IS_LOCK_FREE_1 __c11_atomic_is_lock_free(1) | ||||
#define IS_LOCK_FREE_2 __c11_atomic_is_lock_free(2) | #define IS_LOCK_FREE_2 __c11_atomic_is_lock_free(2) | ||||
#define IS_LOCK_FREE_4 __c11_atomic_is_lock_free(4) | #define IS_LOCK_FREE_4 __c11_atomic_is_lock_free(4) | ||||
/// 32 bit PowerPC doesn't support 8-byte lock_free atomics | |||||
#if !defined(__powerpc64__) && (defined(__powerpc__) || defined(__powerpcspe__)) | |||||
Done Inline ActionsNo need for defined(powerpcspe), we just use powerpc for powerpcspe target. jhibbits: No need for defined(__powerpcspe__), we just use __powerpc__ for powerpcspe target. | |||||
#define IS_LOCK_FREE_8 __c11_atomic_is_lock_free(0) | |||||
Done Inline ActionsIs calling __c11_atomic_is_lock_free(0) really the right change here? luporl: Is calling `__c11_atomic_is_lock_free(0)` really the right change here?
To achieve the same… | |||||
#else | |||||
#define IS_LOCK_FREE_8 __c11_atomic_is_lock_free(8) | #define IS_LOCK_FREE_8 __c11_atomic_is_lock_free(8) | ||||
#endif | |||||
/// Clang can not yet codegen __atomic_is_lock_free(16), so for now we assume | |||||
/// 16-byte values are not lock free. | |||||
#define IS_LOCK_FREE_16 0 | #define IS_LOCK_FREE_16 0 | ||||
/// Macro that calls the compiler-generated lock-free versions of functions | /// Macro that calls the compiler-generated lock-free versions of functions | ||||
/// when they exist. | /// when they exist. | ||||
#define LOCK_FREE_CASES() \ | #define LOCK_FREE_CASES() \ | ||||
do { \ | do { \ | ||||
switch (size) { \ | switch (size) { \ | ||||
case 1: \ | case 1: \ | ||||
▲ Show 20 Lines • Show All 208 Lines • Show Last 20 Lines |
Why did you need to change the include order of machine/atomic.h and sys/types.h?