Add compiler barriers to read-side for mutex ordering
authorMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Sat, 6 Nov 2010 19:09:29 +0000 (15:09 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Sat, 6 Nov 2010 19:09:29 +0000 (15:09 -0400)
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 <mathieu.desnoyers@efficios.com>
urcu-bp-static.h
urcu-qsbr-static.h
urcu-static.h

index 515be288d6b75011a1428994343d641e2cf9f330..6d7e3c874cff4c60f869a15f368324b3b080efde 100644 (file)
@@ -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 
index 041361799b89694b8f9e8c9f7af0d142d040a44e..147eb18b94357ee885216d3db65f252d54143944 100644 (file)
@@ -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();
 }
index dce15b7122cad8c3c44c3d7881cf97b81c92fb3e..eea39bb0641f8b5d295a46dd4f316761a6e85d21 100644 (file)
@@ -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
This page took 0.025985 seconds and 4 git commands to generate.