diff options
author | Ben Gamari <ben@smart-cactus.org> | 2020-10-29 22:55:15 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2020-10-30 14:02:19 -0400 |
commit | f7b45cde43f47f94b77411477aabdb56f8f63d66 (patch) | |
tree | d07d2662001281e4d640de60c4f7f2f35cd3638d | |
parent | 105d43db7bb7f399be3e5474d207e330d1b2da5a (diff) | |
download | haskell-f7b45cde43f47f94b77411477aabdb56f8f63d66.tar.gz |
rts: Use relaxed ordering on spinlock counterswip/tsan/storage
-rw-r--r-- | includes/stg/SMP.h | 2 | ||||
-rw-r--r-- | rts/SpinLock.c | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/includes/stg/SMP.h b/includes/stg/SMP.h index fa52a913c4..8eff276e60 100644 --- a/includes/stg/SMP.h +++ b/includes/stg/SMP.h @@ -440,6 +440,7 @@ load_load_barrier(void) { // Relaxed atomic operations. #define RELAXED_LOAD(ptr) __atomic_load_n(ptr, __ATOMIC_RELAXED) #define RELAXED_STORE(ptr,val) __atomic_store_n(ptr, val, __ATOMIC_RELAXED) +#define RELAXED_ADD(ptr,val) __atomic_add_fetch(ptr, val, __ATOMIC_RELAXED) // Acquire/release atomic operations #define ACQUIRE_LOAD(ptr) __atomic_load_n(ptr, __ATOMIC_ACQUIRE) @@ -466,6 +467,7 @@ EXTERN_INLINE void load_load_barrier () {} /* nothing */ // Relaxed atomic operations #define RELAXED_LOAD(ptr) *ptr #define RELAXED_STORE(ptr,val) *ptr = val +#define RELAXED_ADD(ptr,val) *ptr += val // Acquire/release atomic operations #define ACQUIRE_LOAD(ptr) *ptr diff --git a/rts/SpinLock.c b/rts/SpinLock.c index 314918257f..5289694aa7 100644 --- a/rts/SpinLock.c +++ b/rts/SpinLock.c @@ -30,10 +30,10 @@ void acquire_spin_lock_slow_path(SpinLock * p) for (uint32_t i = 0; i < SPIN_COUNT; i++) { StgWord32 r = cas((StgVolatilePtr)&(p->lock), 1, 0); if (r != 0) return; - IF_PROF_SPIN(__atomic_fetch_add(&p->spin, 1, __ATOMIC_RELAXED)); + IF_PROF_SPIN(RELAXED_ADD(&p->spin, 1)); busy_wait_nop(); } - IF_PROF_SPIN(__atomic_fetch_add(&p->yield, 1, __ATOMIC_RELAXED)); + IF_PROF_SPIN(RELAXED_ADD(&p->yield, 1)); yieldThread(); } while (1); } |