Index: src/atomic_builtins.h ================================================================== --- src/atomic_builtins.h +++ src/atomic_builtins.h @@ -12,12 +12,10 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -OF_ASSUME_NONNULL_BEGIN - static OF_INLINE int of_atomic_int_add(volatile int *_Nonnull p, int i) { return __atomic_add_fetch(p, i, __ATOMIC_RELAXED); } @@ -133,35 +131,21 @@ return __atomic_compare_exchange(p, &o, &n, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED); } static OF_INLINE void -of_memory_barrier_sync(void) +of_memory_barrier_full(void) { __atomic_thread_fence(__ATOMIC_SEQ_CST); } static OF_INLINE void -of_memory_barrier_enter(void) -{ - __atomic_thread_fence(__ATOMIC_SEQ_CST); -} - -static OF_INLINE void -of_memory_barrier_exit(void) -{ - __atomic_thread_fence(__ATOMIC_SEQ_CST); -} - -static OF_INLINE void -of_memory_barrier_producer(void) -{ - __atomic_thread_fence(__ATOMIC_SEQ_CST); -} - -static OF_INLINE void -of_memory_barrier_consumer(void) -{ - __atomic_thread_fence(__ATOMIC_SEQ_CST); -} - -OF_ASSUME_NONNULL_END +of_memory_barrier_acquire(void) +{ + __atomic_thread_fence(__ATOMIC_ACQUIRE); +} + +static OF_INLINE void +of_memory_barrier_release(void) +{ + __atomic_thread_fence(__ATOMIC_RELEASE); +} Index: src/atomic_no_threads.h ================================================================== --- src/atomic_no_threads.h +++ src/atomic_no_threads.h @@ -12,12 +12,10 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -OF_ASSUME_NONNULL_BEGIN - static OF_INLINE int of_atomic_int_add(volatile int *_Nonnull p, int i) { return (*p += i); } @@ -145,35 +143,21 @@ return false; } static OF_INLINE void -of_memory_barrier_sync(void) +of_memory_barrier(void) { /* nop */ } static OF_INLINE void -of_memory_barrier_enter(void) +of_memory_barrier_acquire(void) { /* nop */ } static OF_INLINE void -of_memory_barrier_exit(void) +of_memory_barrier_release(void) { /* nop */ } - -static OF_INLINE void -of_memory_barrier_producer(void) -{ - /* nop */ -} - -static OF_INLINE void -of_memory_barrier_consumer(void) -{ - /* nop */ -} - -OF_ASSUME_NONNULL_END Index: src/atomic_osatomic.h ================================================================== --- src/atomic_osatomic.h +++ src/atomic_osatomic.h @@ -14,12 +14,10 @@ * file. */ #include -OF_ASSUME_NONNULL_BEGIN - static OF_INLINE int of_atomic_int_add(volatile int *_Nonnull p, int i) { return OSAtomicAdd32(i, p); } @@ -140,35 +138,21 @@ { return OSAtomicCompareAndSwapPtr(o, n, p); } static OF_INLINE void -of_memory_barrier_sync(void) +of_memory_barrier(void) { OSMemoryBarrier(); } static OF_INLINE void -of_memory_barrier_enter(void) +of_memory_barrier_acquire(void) { OSMemoryBarrier(); } static OF_INLINE void -of_memory_barrier_exit(void) +of_memory_barrier_release(void) { OSMemoryBarrier(); } - -static OF_INLINE void -of_memory_barrier_producer(void) -{ - OSMemoryBarrier(); -} - -static OF_INLINE void -of_memory_barrier_consumer(void) -{ - OSMemoryBarrier(); -} - -OF_ASSUME_NONNULL_END Index: src/atomic_powerpc.h ================================================================== --- src/atomic_powerpc.h +++ src/atomic_powerpc.h @@ -12,12 +12,10 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -OF_ASSUME_NONNULL_BEGIN - static OF_INLINE int of_atomic_int_add(volatile int *_Nonnull p, int i) { __asm__ __volatile__ ( "0:\n\t" @@ -358,45 +356,27 @@ return r; } static OF_INLINE void -of_memory_barrier_sync(void) -{ - __asm__ __volatile__ ( - "sync" ::: "memory" - ); -} - -static OF_INLINE void -of_memory_barrier_enter(void) -{ - __asm__ __volatile__ ( - "sync" ::: "memory" - ); -} - -static OF_INLINE void -of_memory_barrier_exit(void) -{ - __asm__ __volatile__ ( - "sync" ::: "memory" - ); -} - -static OF_INLINE void -of_memory_barrier_producer(void) -{ - __asm__ __volatile__ ( - "sync" ::: "memory" - ); -} - -static OF_INLINE void -of_memory_barrier_consumer(void) -{ - __asm__ __volatile__ ( - "sync" ::: "memory" - ); -} - -OF_ASSUME_NONNULL_END +of_memory_barrier(void) +{ + __asm__ __volatile__ ( + "lwsync" ::: "memory" + ); +} + +static OF_INLINE void +of_memory_barrier_acquire(void) +{ + __asm__ __volatile__ ( + "lwsync" ::: "memory" + ); +} + +static OF_INLINE void +of_memory_barrier_release(void) +{ + __asm__ __volatile__ ( + "lwsync" ::: "memory" + ); +} Index: src/atomic_sync_builtins.h ================================================================== --- src/atomic_sync_builtins.h +++ src/atomic_sync_builtins.h @@ -12,12 +12,10 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -OF_ASSUME_NONNULL_BEGIN - static OF_INLINE int of_atomic_int_add(volatile int *_Nonnull p, int i) { return __sync_add_and_fetch(p, i); } @@ -130,35 +128,21 @@ { return __sync_bool_compare_and_swap(p, o, n); } static OF_INLINE void -of_memory_barrier_sync(void) +of_memory_barrier(void) { __sync_synchronize(); } static OF_INLINE void -of_memory_barrier_enter(void) +of_memory_barrier_acquire(void) { __sync_synchronize(); } static OF_INLINE void -of_memory_barrier_exit(void) +of_memory_barrier_release(void) { __sync_synchronize(); } - -static OF_INLINE void -of_memory_barrier_producer(void) -{ - __sync_synchronize(); -} - -static OF_INLINE void -of_memory_barrier_consumer(void) -{ - __sync_synchronize(); -} - -OF_ASSUME_NONNULL_END Index: src/atomic_x86.h ================================================================== --- src/atomic_x86.h +++ src/atomic_x86.h @@ -479,45 +479,25 @@ return r; } static OF_INLINE void -of_memory_barrier_sync(void) +of_memory_barrier(void) { __asm__ __volatile__ ( "mfence" ::: "memory" ); } static OF_INLINE void -of_memory_barrier_enter(void) -{ - __asm__ __volatile__ ( - "mfence" ::: "memory" - ); -} - -static OF_INLINE void -of_memory_barrier_exit(void) -{ - __asm__ __volatile__ ( - "mfence" ::: "memory" - ); -} - -static OF_INLINE void -of_memory_barrier_producer(void) -{ - __asm__ __volatile__ ( - "sfence" ::: "memory" - ); -} - -static OF_INLINE void -of_memory_barrier_consumer(void) -{ - __asm__ __volatile__ ( - "lfence" ::: "memory" - ); +of_memory_barrier_acquire(void) +{ + __asm__ __volatile__ ("" ::: "memory"); +} + +static OF_INLINE void +of_memory_barrier_release(void) +{ + __asm__ __volatile__ ("" ::: "memory"); } OF_ASSUME_NONNULL_END Index: src/threading.h ================================================================== --- src/threading.h +++ src/threading.h @@ -182,11 +182,11 @@ static OF_INLINE bool of_spinlock_trylock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) if (of_atomic_int_cmpswap(spinlock, 0, 1)) { - of_memory_barrier_enter(); + of_memory_barrier_acquire(); return true; } return false; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) @@ -221,11 +221,11 @@ of_spinlock_unlock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) bool ret = of_atomic_int_cmpswap(spinlock, 1, 0); - of_memory_barrier_exit(); + of_memory_barrier_release(); return ret; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return !pthread_spin_unlock(spinlock); #else Index: src/threading.m ================================================================== --- src/threading.m +++ src/threading.m @@ -31,11 +31,11 @@ of_once(of_once_t *control, void (*func)(void)) { if (of_atomic_int_cmpswap(control, 0, 1)) { func(); - of_memory_barrier_sync(); + of_memory_barrier(); of_atomic_int_inc(control); } else while (*control == 1) of_thread_yield();