Introduce urcu_assert and registration check
[urcu.git] / urcu / static / urcu.h
index b5fc09f93553578ae32f660b9c65a49a9ea3517f..fbba46cde9afdc6bff0c4b337a22afc78d40fea7 100644 (file)
@@ -42,6 +42,7 @@
 #include <urcu/futex.h>
 #include <urcu/tls-compat.h>
 #include <urcu/rand-compat.h>
+#include <urcu/debug.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -79,12 +80,6 @@ enum rcu_state {
        RCU_READER_INACTIVE,
 };
 
-#ifdef DEBUG_RCU
-#define rcu_assert(args...)    assert(args)
-#else
-#define rcu_assert(args...)
-#endif
-
 /*
  * RCU memory barrier broadcast group. Currently, only broadcast to all process
  * threads is supported (group 0).
@@ -157,6 +152,8 @@ struct rcu_reader {
        /* Data used for registry */
        struct cds_list_head node __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
        pthread_t tid;
+       /* Reader registered flag, for internal checks. */
+       unsigned int registered:1;
 };
 
 extern DECLARE_URCU_TLS(struct rcu_reader, rcu_reader);
@@ -168,8 +165,13 @@ static inline void wake_up_gp(void)
 {
        if (caa_unlikely(uatomic_read(&rcu_gp.futex) == -1)) {
                uatomic_set(&rcu_gp.futex, 0);
-               futex_async(&rcu_gp.futex, FUTEX_WAKE, 1,
-                     NULL, NULL, 0);
+               /*
+                * Ignoring return value until we can make this function
+                * return something (because urcu_die() is not publicly
+                * exposed).
+                */
+               (void) futex_async(&rcu_gp.futex, FUTEX_WAKE, 1,
+                               NULL, NULL, 0);
        }
 }
 
@@ -219,6 +221,7 @@ static inline void _rcu_read_lock(void)
 {
        unsigned long tmp;
 
+       urcu_assert(URCU_TLS(rcu_reader).registered);
        cmm_barrier();
        tmp = URCU_TLS(rcu_reader).ctr;
        _rcu_read_lock_update(tmp);
@@ -252,6 +255,7 @@ static inline void _rcu_read_unlock(void)
 {
        unsigned long tmp;
 
+       urcu_assert(URCU_TLS(rcu_reader).registered);
        tmp = URCU_TLS(rcu_reader).ctr;
        _rcu_read_unlock_update_and_wakeup(tmp);
        cmm_barrier();  /* Ensure the compiler does not reorder us with mutex */
This page took 0.022821 seconds and 4 git commands to generate.