Index: src/threading.h ================================================================== --- src/threading.h +++ src/threading.h @@ -181,11 +181,16 @@ static OF_INLINE bool of_spinlock_trylock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) - return of_atomic_int_cmpswap(spinlock, 0, 1); + if (of_atomic_int_cmpswap(spinlock, 0, 1)) { + of_memory_enter_barrier(); + return true; + } + + return false; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return !pthread_spin_trylock(spinlock); #else return of_mutex_trylock(spinlock); #endif @@ -214,11 +219,15 @@ static OF_INLINE bool of_spinlock_unlock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) - return of_atomic_int_cmpswap(spinlock, 1, 0); + bool ret = of_atomic_int_cmpswap(spinlock, 1, 0); + + of_memory_leave_barrier(); + + return ret; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return !pthread_spin_unlock(spinlock); #else return of_mutex_unlock(spinlock); #endif