From 42a3f1f99827c1bd73270966d4fffd6157809a7c Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sat, 6 Nov 2010 15:09:29 -0400 Subject: [PATCH] Add compiler barriers to read-side for mutex ordering Ensure that mutex acquisition/release is not reordered wrt rcu read lock/unlock. No impact in practice because pthreads lock/unlock primitives act as memory barriers. But we should provide the same guarantees we are expecting from other locking primitives, hence this modification. Signed-off-by: Mathieu Desnoyers --- urcu-bp-static.h | 2 ++ urcu-qsbr-static.h | 2 ++ urcu-static.h | 2 ++ 3 files changed, 6 insertions(+) diff --git a/urcu-bp-static.h b/urcu-bp-static.h index 515be28..6d7e3c8 100644 --- a/urcu-bp-static.h +++ b/urcu-bp-static.h @@ -175,6 +175,7 @@ static inline void _rcu_read_lock(void) if (unlikely(!rcu_reader)) rcu_bp_register(); + barrier(); /* Ensure the compiler does not reorder us with mutex */ tmp = rcu_reader->ctr; /* * rcu_gp_ctr is @@ -199,6 +200,7 @@ static inline void _rcu_read_unlock(void) */ smp_mb(); _STORE_SHARED(rcu_reader->ctr, rcu_reader->ctr - RCU_GP_COUNT); + barrier(); /* Ensure the compiler does not reorder us with mutex */ } #ifdef __cplusplus diff --git a/urcu-qsbr-static.h b/urcu-qsbr-static.h index 0413617..147eb18 100644 --- a/urcu-qsbr-static.h +++ b/urcu-qsbr-static.h @@ -187,10 +187,12 @@ static inline void _rcu_thread_offline(void) STORE_SHARED(rcu_reader.ctr, 0); smp_mb(); /* write rcu_reader.ctr before read futex */ wake_up_gp(); + barrier(); /* Ensure the compiler does not reorder us with mutex */ } static inline void _rcu_thread_online(void) { + barrier(); /* Ensure the compiler does not reorder us with mutex */ _STORE_SHARED(rcu_reader.ctr, LOAD_SHARED(rcu_gp_ctr)); smp_mb(); } diff --git a/urcu-static.h b/urcu-static.h index dce15b7..eea39bb 100644 --- a/urcu-static.h +++ b/urcu-static.h @@ -259,6 +259,7 @@ static inline void _rcu_read_lock(void) { unsigned long tmp; + barrier(); /* Ensure the compiler does not reorder us with mutex */ tmp = rcu_reader.ctr; /* * rcu_gp_ctr is @@ -294,6 +295,7 @@ static inline void _rcu_read_unlock(void) } else { _STORE_SHARED(rcu_reader.ctr, rcu_reader.ctr - RCU_GP_COUNT); } + barrier(); /* Ensure the compiler does not reorder us with mutex */ } #ifdef __cplusplus -- 2.34.1