Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Implemented x86 and x86-64 spinlock inline asm.

Favor it over Mac OS X API for Intel systems (but not GCC atomic intrinsics).

This might get us a little further on Cygwin builds, too.
  • Loading branch information
icculus committed Sep 18, 2011
1 parent a865a25 commit d7f33c956e513478bea85e57d4ef5f477002a8b1
Showing with 13 additions and 4 deletions.
  1. +13 −4 src/atomic/SDL_spinlock.c
@@ -55,9 +55,6 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
return (InterlockedExchange((long*)lock, 1) == 0);

#elif defined(__MACOSX__)
return OSAtomicCompareAndSwap32Barrier(0, 1, lock);

#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
return (__sync_lock_test_and_set(lock, 1) == 0);

@@ -77,10 +74,22 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
return (result == 0);

#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
int result;
__asm__ __volatile__(
"lock ; xchgl %0, (%1)\n"
: "=r" (result) : "r" (lock), "0" (1) : "cc", "memory");
return (result == 0);

#elif defined(__MACOSX__)
/* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */
return OSAtomicCompareAndSwap32Barrier(0, 1, lock);

#elif HAVE_PTHREAD_SPINLOCK
/* pthread instructions */
return (pthread_spin_trylock(lock) == 0);
#else

#else
#error Please implement for your platform.
return SDL_FALSE;
#endif

0 comments on commit d7f33c9

Please sign in to comment.