Expose nop QSBR read lock to non-GPL/LGPL programs
[urcu.git] / urcu-qsbr.c
index 14733ab21e1b61d10bf93ecc082967cdf9d717cd..ccecab4e7b02b63d80f6c87085486dee0a5452f5 100644 (file)
@@ -32,6 +32,7 @@
 #include <errno.h>
 #include <poll.h>
 
+#define BUILD_QSBR_LIB
 #include "urcu-qsbr-static.h"
 /* Do not #define _LGPL_SOURCE to ensure we can emit the wrapper symbols */
 #include "urcu-qsbr.h"
@@ -145,12 +146,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.023574 seconds and 4 git commands to generate.