src/atomic/SDL_spinlock.c
changeset 5557 c1ed57cbfd66
parent 5535 96594ac5fd1a
child 5956 c7aebf1841ca
equal deleted inserted replaced
5556:45a709ef443d 5557:c1ed57cbfd66
    75     __asm__ __volatile__ (
    75     __asm__ __volatile__ (
    76         "ldrex %0, [%2]\nteq   %0, #0\nstrexeq %0, %1, [%2]"
    76         "ldrex %0, [%2]\nteq   %0, #0\nstrexeq %0, %1, [%2]"
    77         : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
    77         : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
    78     return (result == 0);
    78     return (result == 0);
    79 
    79 
    80 #else
    80 #elif HAVE_PTHREAD_SPINLOCK
       
    81     /* pthread instructions */
       
    82     return (pthread_spin_trylock(lock) == 0);
       
    83 #else	
    81     /* Need CPU instructions for spinlock here! */
    84     /* Need CPU instructions for spinlock here! */
    82     __need_spinlock_implementation__
    85     __need_spinlock_implementation__
       
    86 	
    83 #endif
    87 #endif
    84 }
    88 }
    85 
    89 
    86 void
    90 void
    87 SDL_AtomicLock(SDL_SpinLock *lock)
    91 SDL_AtomicLock(SDL_SpinLock *lock)
    99     _ReadWriteBarrier();
   103     _ReadWriteBarrier();
   100     *lock = 0;
   104     *lock = 0;
   101 
   105 
   102 #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
   106 #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
   103     __sync_lock_release(lock);
   107     __sync_lock_release(lock);
   104 
   108     
       
   109 #elif HAVE_PTHREAD_SPINLOCK
       
   110     pthread_spin_unlock(lock);
       
   111 	
   105 #else
   112 #else
   106     *lock = 0;
   113     *lock = 0;
   107 #endif
   114 #endif
   108 }
   115 }
   109 
   116