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(__WATCOMC__) && defined(__386__)
37 extern _inline
int _SDL_xchg_watcom(
volatile int *
a,
int v);
38 #pragma aux _SDL_xchg_watcom = \
49 #if SDL_ATOMIC_DISABLED
53 if (!_spinlock_mutex) {
67 #elif defined(_MSC_VER)
69 return (InterlockedExchange((
long*)lock, 1) == 0);
71 #elif defined(__WATCOMC__) && defined(__386__)
72 return _SDL_xchg_watcom(lock, 1) == 0;
74 #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
75 return (__sync_lock_test_and_set(lock, 1) == 0);
77 #elif defined(__GNUC__) && defined(__arm__) && \
78 (defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \
79 defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5TE__) || \
80 defined(__ARM_ARCH_5TEJ__))
82 __asm__ __volatile__ (
84 :
"=&r,&r" (result) :
"r,0" (1),
"r,r" (lock) :
"memory");
87 #elif defined(__GNUC__) && defined(__arm__)
89 __asm__ __volatile__ (
90 "ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
91 :
"=&r" (result) :
"r" (1),
"r" (lock) :
"cc",
"memory");
94 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
97 "lock ; xchgl %0, (%1)\n"
98 :
"=r" (result) :
"r" (lock),
"0" (1) :
"cc",
"memory");
101 #elif defined(__MACOSX__) || defined(__IPHONEOS__)
103 return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
105 #elif defined(__SOLARIS__) && defined(_LP64)
109 #elif defined(__SOLARIS__) && !defined(_LP64)
114 #error Please implement for your platform.
131 #if defined(_MSC_VER)
135 #elif defined(__WATCOMC__) && defined(__386__)
139 #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
140 __sync_lock_release(lock);
142 #elif defined(__SOLARIS__)
#define SDL_CompilerBarrier()
void SDL_AtomicLock(SDL_SpinLock *lock)
Lock a spin lock by setting it to a non-zero value.
void SDL_AtomicUnlock(SDL_SpinLock *lock)
Unlock a spin lock by setting it to 0. Always returns immediately.
unsigned long long uint64_t
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
#define SDL_COMPILE_TIME_ASSERT(name, x)