Go to the source code of this file.
◆ SDL_AtomicLock()
Lock a spin lock by setting it to a non-zero value.
- Parameters
-
Definition at line 120 of file SDL_spinlock.c.
References SDL_AtomicTryLock(), and SDL_Delay.
SDL_bool SDL_AtomicTryLock(SDL_SpinLock *lock)
Try to lock a spin lock by setting it to a non-zero value.
◆ SDL_AtomicTryLock()
Try to lock a spin lock by setting it to a non-zero value.
- Parameters
-
- Returns
- SDL_TRUE if the lock succeeded, SDL_FALSE if the lock is already held.
Definition at line 47 of file SDL_spinlock.c.
References lock, SDL_COMPILE_TIME_ASSERT, SDL_CreateMutex, SDL_FALSE, SDL_LockMutex, SDL_TRUE, and SDL_UnlockMutex.
Referenced by SDL_AtomicLock().
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.
unsigned long long uint64_t
#define SDL_COMPILE_TIME_ASSERT(name, x)
◆ SDL_AtomicUnlock()
Unlock a spin lock by setting it to 0. Always returns immediately.
- Parameters
-
Definition at line 129 of file SDL_spinlock.c.
References SDL_CompilerBarrier.
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()