src/atomic/SDL_spinlock.c
changeset 5957 9a2b091abb2c
parent 5956 c7aebf1841ca
child 5998 e9b9ef14aef4
     1.1 --- a/src/atomic/SDL_spinlock.c	Sun Sep 18 02:55:45 2011 -0400
     1.2 +++ b/src/atomic/SDL_spinlock.c	Sun Sep 18 03:19:41 2011 -0400
     1.3 @@ -55,9 +55,6 @@
     1.4      SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
     1.5      return (InterlockedExchange((long*)lock, 1) == 0);
     1.6  
     1.7 -#elif defined(__MACOSX__)
     1.8 -    return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
     1.9 -
    1.10  #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
    1.11      return (__sync_lock_test_and_set(lock, 1) == 0);
    1.12  
    1.13 @@ -77,10 +74,22 @@
    1.14          : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
    1.15      return (result == 0);
    1.16  
    1.17 +#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
    1.18 +	int result;
    1.19 +	__asm__ __volatile__(
    1.20 +        "lock ; xchgl %0, (%1)\n"
    1.21 +        : "=r" (result) : "r" (lock), "0" (1) : "cc", "memory");
    1.22 +	return (result == 0);
    1.23 +
    1.24 +#elif defined(__MACOSX__)
    1.25 +    /* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */
    1.26 +    return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
    1.27 +
    1.28  #elif HAVE_PTHREAD_SPINLOCK
    1.29      /* pthread instructions */
    1.30      return (pthread_spin_trylock(lock) == 0);
    1.31 -#else	
    1.32 +
    1.33 +#else
    1.34  #error Please implement for your platform.
    1.35      return SDL_FALSE;
    1.36  #endif