18 #ifndef HL_SPINLOCKOLD_H 19 #define HL_SPINLOCKOLD_H 33 #if defined(__APPLE__) 34 #include <libkern/OSAtomic.h> 41 #if !defined(NO_INLINE) 42 #pragma inline_depth(255) 43 #define NO_INLINE __declspec(noinline) 44 #define INLINE __forceinline 45 #define inline __forceinline 46 #endif // !defined(NO_INLINE) 50 #endif // defined(_MSC_VER) 53 #if defined(__SUNPRO_CC) 55 extern "C" size_t MyInterlockedExchange (
size_t * oldval,
59 #if defined(_WIN32) && !defined(_WIN64) 62 #define _WIN32_WINNT 0x0500 71 #define _MM_PAUSE {__asm{_emit 0xf3};__asm {_emit 0x90}} 74 #elif defined(__GNUC__) 76 #define _MM_PAUSE { asm (".byte 0xf3; .byte 0x90" : : : "memory"); } 82 #endif // defined(_WIN32) && !defined(_WIN64) 96 #if defined(__APPLE__) 97 :
mutex (OS_SPINLOCK_INIT)
121 #if defined(_WIN32) && !defined(_WIN64) 123 #elif defined(__GNUC__) 124 asm volatile (
"" : : :
"memory");
131 #if !defined(__SUNPRO_CC) 137 #if 0 // defined(__APPLE__) 144 const int MAX_SPIN = 1000;
146 if (MyInterlockedExchange (const_cast<size_t *>(&mutex),
LOCKED)
151 while ((mutex ==
LOCKED) && (count < MAX_SPIN)) {
155 if (count == MAX_SPIN) {
170 #elif defined(__SVR4) 191 #if !defined(__SUNPRO_CC) // && !defined(__APPLE__) 196 #if defined(_WIN32) && defined(_MSC_VER) 197 return InterlockedExchange ((
volatile LONG *) oldval, newval);
202 #elif defined(__sparc) 203 asm volatile (
"swap [%1],%0" 205 :
"r" (oldval),
"0" (newval)
208 #elif defined(__i386__) 209 asm volatile (
"lock; xchgl %0, %1" 211 :
"m" (*oldval),
"0" (newval)
215 newval = test_and_set (oldval, newval);
217 #elif defined(__x86_64__) 219 asm volatile (
"lock; xchgq %0, %1" 221 :
"m" (*oldval),
"0" (newval)
224 #elif defined(__ppc) || defined(__powerpc__) || defined(PPC) 228 "La..%=0: lwarx %0,0,%1 ;" 235 :
"r"(oldval),
"r"(newval)
239 #elif defined(__arm__) 244 "swp %0,%2,[%1] \n\t" 247 :
"r"(oldval),
"r"(newval)
250 #elif defined(__APPLE__) 251 size_t oldValue = *oldval;
252 bool swapped = OSAtomicCompareAndSwapLongBarrier (oldValue, newval, (
volatile long *) oldval);
259 #error "No spin lock implementation is available for this platform." 267 #endif // _SPINLOCK_H_
void yieldProcessor(void)
static size_t MyInterlockedExchange(size_t *, size_t)
int count(int &result, const cub_regex_object ®, const std::string &src, const int position, const INTL_CODESET codeset)
static int getNumProcessors()
bool onMultiprocessor(void)
Architecture-independent wrapper to get number of CPUs.
NO_INLINE void contendedLock()