Go to the documentation of this file.
21 #include "../SDL_internal.h"
23 #if defined(__WIN32__) || defined(__WINRT__)
24 #include "../core/windows/SDL_windows.h"
31 #if !defined(HAVE_GCC_ATOMICS) && defined(__SOLARIS__)
35 #if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
36 #include <xmmintrin.h>
39 #if defined(__WATCOMC__) && defined(__386__)
41 extern _inline
int _SDL_xchg_watcom(
volatile int *
a,
int v);
42 #pragma aux _SDL_xchg_watcom = \
43 "lock xchg [ecx], eax" \
53 #if SDL_ATOMIC_DISABLED
57 if (!_spinlock_mutex) {
71 #elif defined(_MSC_VER)
73 return (InterlockedExchange((
long*)
lock, 1) == 0);
75 #elif defined(__WATCOMC__) && defined(__386__)
76 return _SDL_xchg_watcom(
lock, 1) == 0;
78 #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
79 return (__sync_lock_test_and_set(
lock, 1) == 0);
81 #elif defined(__GNUC__) && defined(__arm__) && \
82 (defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \
83 defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5TE__) || \
84 defined(__ARM_ARCH_5TEJ__))
86 __asm__ __volatile__ (
88 :
"=&r,&r" (
result) :
"r,0" (1),
"r,r" (
lock) :
"memory");
91 #elif defined(__GNUC__) && defined(__arm__)
93 __asm__ __volatile__ (
94 "ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
95 :
"=&r" (
result) :
"r" (1),
"r" (
lock) :
"cc",
"memory");
98 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
100 __asm__ __volatile__(
101 "lock ; xchgl %0, (%1)\n"
102 :
"=r" (
result) :
"r" (
lock),
"0" (1) :
"cc",
"memory");
105 #elif defined(__MACOSX__) || defined(__IPHONEOS__)
107 return OSAtomicCompareAndSwap32Barrier(0, 1,
lock);
109 #elif defined(__SOLARIS__) && defined(_LP64)
113 #elif defined(__SOLARIS__) && !defined(_LP64)
118 #error Please implement for your platform.
124 #if (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))
125 #define PAUSE_INSTRUCTION() __asm__ __volatile__("pause\n")
126 #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
127 #define PAUSE_INSTRUCTION() _mm_pause()
128 #elif defined(__WATCOMC__) && defined(__386__)
131 #pragma aux PAUSE_INSTRUCTION = "db 0f3h,90h"
133 #define PAUSE_INSTRUCTION()
155 #if defined(_MSC_VER)
159 #elif defined(__WATCOMC__) && defined(__386__)
163 #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
164 __sync_lock_release(
lock);
166 #elif defined(__SOLARIS__)
void SDL_AtomicLock(SDL_SpinLock *lock)
Lock a spin lock by setting it to a non-zero value.
SDL_bool SDL_AtomicTryLock(SDL_SpinLock *lock)
Try to lock a spin lock by setting it to a non-zero value.
GLboolean GLboolean GLboolean GLboolean a
void SDL_AtomicUnlock(SDL_SpinLock *lock)
Unlock a spin lock by setting it to 0. Always returns immediately.
#define SDL_COMPILE_TIME_ASSERT(name, x)
#define SDL_CompilerBarrier()
#define PAUSE_INSTRUCTION()
unsigned long long uint64_t