Rename likely/unlikely to caa_likely/caa_unlikely
[urcu.git] / urcu / static / urcu.h
index 3161a40088836c92a65edbdc8445385913afe0bb..7ae018596ec89c9bbcf56b22340d100f0998357b 100644 (file)
@@ -31,8 +31,8 @@
 
 #include <stdlib.h>
 #include <pthread.h>
-#include <syscall.h>
 #include <unistd.h>
+#include <stdint.h>
 
 #include <urcu/compiler.h>
 #include <urcu/arch.h>
@@ -50,9 +50,17 @@ extern "C" {
 #define RCU_MEMBARRIER
 #endif
 
+/*
+ * RCU_MEMBARRIER is only possibly available on Linux. Fallback to RCU_MB
+ * otherwise.
+ */
+#if !defined(__linux__) && defined(RCU_MEMBARRIER)
+#undef RCU_MEMBARRIER
+#define RCU_MB
+#endif
+
 #ifdef RCU_MEMBARRIER
-#include <unistd.h>
-#include <sys/syscall.h>
+#include <syscall.h>
 
 /* If the headers do not support SYS_membarrier, statically use RCU_MB */
 #ifdef SYS_membarrier
@@ -87,18 +95,6 @@ extern "C" {
 #define SIGRCU SIGUSR1
 #endif
 
-/*
- * If a reader is really non-cooperative and refuses to commit its
- * rcu_active_readers count to memory (there is no barrier in the reader
- * per-se), kick it after a few loops waiting for it.
- */
-#define KICK_READER_LOOPS 10000
-
-/*
- * Active attempts to check for reader Q.S. before calling futex().
- */
-#define RCU_QS_ACTIVE_ATTEMPTS 100
-
 #ifdef DEBUG_RCU
 #define rcu_assert(args...)    assert(args)
 #else
@@ -143,7 +139,7 @@ static inline void debug_yield_write(void)
 
 static inline void debug_yield_init(void)
 {
-       rand_yield = time(NULL) ^ pthread_self();
+       rand_yield = time(NULL) ^ (unsigned long) pthread_self();
 }
 #else
 static inline void debug_yield_read(void)
@@ -180,7 +176,7 @@ extern int has_sys_membarrier;
 
 static inline void smp_mb_slave(int group)
 {
-       if (likely(has_sys_membarrier))
+       if (caa_likely(has_sys_membarrier))
                cmm_barrier();
        else
                cmm_smp_mb();
@@ -228,14 +224,14 @@ struct rcu_reader {
 
 extern struct rcu_reader __thread rcu_reader;
 
-extern int gp_futex;
+extern int32_t gp_futex;
 
 /*
  * Wake-up waiting synchronize_rcu(). Called from many concurrent threads.
  */
 static inline void wake_up_gp(void)
 {
-       if (unlikely(uatomic_read(&gp_futex) == -1)) {
+       if (caa_unlikely(uatomic_read(&gp_futex) == -1)) {
                uatomic_set(&gp_futex, 0);
                futex_async(&gp_futex, FUTEX_WAKE, 1,
                      NULL, NULL, 0);
@@ -265,7 +261,7 @@ static inline void _rcu_read_lock(void)
         * rcu_gp_ctr is
         *   RCU_GP_COUNT | (~RCU_GP_CTR_PHASE or RCU_GP_CTR_PHASE)
         */
-       if (likely(!(tmp & RCU_GP_CTR_NEST_MASK))) {
+       if (caa_likely(!(tmp & RCU_GP_CTR_NEST_MASK))) {
                _CMM_STORE_SHARED(rcu_reader.ctr, _CMM_LOAD_SHARED(rcu_gp_ctr));
                /*
                 * Set active readers count for outermost nesting level before
@@ -286,7 +282,7 @@ static inline void _rcu_read_unlock(void)
         * Finish using rcu before decrementing the pointer.
         * See smp_mb_master().
         */
-       if (likely((tmp & RCU_GP_CTR_NEST_MASK) == RCU_GP_COUNT)) {
+       if (caa_likely((tmp & RCU_GP_CTR_NEST_MASK) == RCU_GP_COUNT)) {
                smp_mb_slave(RCU_MB_GROUP);
                _CMM_STORE_SHARED(rcu_reader.ctr, rcu_reader.ctr - RCU_GP_COUNT);
                /* write rcu_reader.ctr before read futex */
This page took 0.023213 seconds and 4 git commands to generate.