src/atomic/SDL_spinlock.c
changeset 5004 0c72ae7b7cb2
parent 5003 3a95a2b93eb3
child 5015 1bf9e38431ec
     1.1 --- a/src/atomic/SDL_spinlock.c	Sat Jan 15 12:41:59 2011 -0800
     1.2 +++ b/src/atomic/SDL_spinlock.c	Sun Jan 16 15:16:39 2011 -0800
     1.3 @@ -44,24 +44,22 @@
     1.4  #elif defined(__MACOSX__)
     1.5      return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
     1.6  
     1.7 -#elif defined(__GNUC__)
     1.8 -#if defined(__arm__)
     1.9 -#ifdef __ARM_ARCH_5__
    1.10 +#elif defined(HAVE_GCC_ATOMICS)
    1.11 +    return (__sync_lock_test_and_set(lock, 1) == 0);
    1.12 +
    1.13 +#elif defined(__GNUC__) && defined(__arm__) && defined(__ARM_ARCH_5__)
    1.14      int result;
    1.15      __asm__ __volatile__ (
    1.16          "swp %0, %1, [%2]\n"
    1.17          : "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory");
    1.18      return (result == 0);
    1.19 -#else
    1.20 +
    1.21 +#elif defined(__GNUC__) && defined(__arm__)
    1.22      int result;
    1.23      __asm__ __volatile__ (
    1.24          "ldrex %0, [%2]\nteq   %0, #0\nstrexeq %0, %1, [%2]"
    1.25          : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
    1.26      return (result == 0);
    1.27 -#endif
    1.28 -#else
    1.29 -    return (__sync_lock_test_and_set(lock, 1) == 0);
    1.30 -#endif
    1.31  
    1.32  #else
    1.33      /* Need CPU instructions for spinlock here! */
    1.34 @@ -81,19 +79,8 @@
    1.35  void
    1.36  SDL_AtomicUnlock(SDL_SpinLock *lock)
    1.37  {
    1.38 -#if defined(__WIN32__)
    1.39 +    /* Assuming atomic assignment operation and full memory barrier in lock */
    1.40      *lock = 0;
    1.41 -
    1.42 -#elif defined(__MACOSX__)
    1.43 -    *lock = 0;
    1.44 -
    1.45 -#elif defined(__GNUC__) && !defined(__arm__)
    1.46 -    __sync_lock_release(lock);
    1.47 -
    1.48 -#else
    1.49 -    /* Assuming memory barrier in lock and integral assignment operation */
    1.50 -    *lock = 0;
    1.51 -#endif
    1.52  }
    1.53  
    1.54  /* vi: set ts=4 sw=4 expandtab: */