qsbr urcu: make it safe to call rcu_sychronize from a registered thread
authorMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Tue, 15 Sep 2009 20:39:35 +0000 (16:39 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Tue, 15 Sep 2009 20:39:35 +0000 (16:39 -0400)
Actually, the proper way to deal with threads registered as readers but also
calling synchronize_rcu() is to mark them as offline while the synchronize is in
progress.

Else, since calling rcu_sychronize will increment urcu_gp_ctr, we will be
stupidly waiting for ourselves and deadlock.

Original-patch-from: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
urcu-qsbr.c

index c0f055441930ab8718cd4d4347325bd6671dc2fc..4ce2f9acdea1e1758f626f3dc14630922ab65be6 100644 (file)
@@ -148,12 +148,27 @@ static void wait_for_quiescent_state(void)
 
 void synchronize_rcu(void)
 {
+       int was_online;
+
+       was_online = rcu_reader_qs_gp & 1;
+
+       /*
+        * Mark the writer thread offline to make sure we don't wait for
+        * our own quiescent state. This allows using synchronize_rcu() in
+        * threads registered as readers.
+        */
+       if (was_online)
+               _rcu_thread_offline();
+
        internal_urcu_lock();
        force_mb_all_threads();
        urcu_gp_ctr += 2;
        wait_for_quiescent_state();
        force_mb_all_threads();
        internal_urcu_unlock();
+
+       if (was_online)
+               _rcu_thread_online();
 }
 
 /*
This page took 0.026145 seconds and 4 git commands to generate.