X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=urcu%2Fstatic%2Furcu-bp.h;h=c7f532640e3c0feab165cb5a699c4c3760df011d;hb=52c75091b18f3cc398b765570a94aaa870afcd51;hp=a2f73687d0a1995e5b3207b9f3fd3b970499d961;hpb=a5a9f428a238e790d6c97299bc214b5cca815cd7;p=urcu.git diff --git a/urcu/static/urcu-bp.h b/urcu/static/urcu-bp.h index a2f7368..c7f5326 100644 --- a/urcu/static/urcu-bp.h +++ b/urcu/static/urcu-bp.h @@ -58,14 +58,20 @@ extern "C" { #define rcu_assert(args...) #endif +enum rcu_state { + RCU_READER_ACTIVE_CURRENT, + RCU_READER_ACTIVE_OLD, + RCU_READER_INACTIVE, +}; + #ifdef DEBUG_YIELD #include #include #include #include -#define YIELD_READ (1 << 0) -#define YIELD_WRITE (1 << 1) +#define RCU_YIELD_READ (1 << 0) +#define RCU_YIELD_WRITE (1 << 1) /* * Updates without RCU_MB are much slower. Account this in @@ -74,37 +80,37 @@ extern "C" { /* maximum sleep delay, in us */ #define MAX_SLEEP 50 -extern unsigned int yield_active; -extern DECLARE_URCU_TLS(unsigned int, rand_yield); +extern unsigned int rcu_yield_active; +extern DECLARE_URCU_TLS(unsigned int, rcu_rand_yield); -static inline void debug_yield_read(void) +static inline void rcu_debug_yield_read(void) { - if (yield_active & YIELD_READ) - if (rand_r(&URCU_TLS(rand_yield)) & 0x1) - usleep(rand_r(&URCU_TLS(rand_yield)) % MAX_SLEEP); + if (rcu_yield_active & RCU_YIELD_READ) + if (rand_r(&URCU_TLS(rcu_rand_yield)) & 0x1) + usleep(rand_r(&URCU_TLS(rcu_rand_yield)) % MAX_SLEEP); } -static inline void debug_yield_write(void) +static inline void rcu_debug_yield_write(void) { - if (yield_active & YIELD_WRITE) - if (rand_r(&URCU_TLS(rand_yield)) & 0x1) - usleep(rand_r(&URCU_TLS(rand_yield)) % MAX_SLEEP); + if (rcu_yield_active & RCU_YIELD_WRITE) + if (rand_r(&URCU_TLS(rcu_rand_yield)) & 0x1) + usleep(rand_r(&URCU_TLS(rcu_rand_yield)) % MAX_SLEEP); } -static inline void debug_yield_init(void) +static inline void rcu_debug_yield_init(void) { - URCU_TLS(rand_yield) = time(NULL) ^ pthread_self(); + URCU_TLS(rcu_rand_yield) = time(NULL) ^ (unsigned long) pthread_self(); } #else -static inline void debug_yield_read(void) +static inline void rcu_debug_yield_read(void) { } -static inline void debug_yield_write(void) +static inline void rcu_debug_yield_write(void) { } -static inline void debug_yield_init(void) +static inline void rcu_debug_yield_init(void) { } @@ -129,11 +135,11 @@ extern void rcu_bp_register(void); * Using a int rather than a char to eliminate false register dependencies * causing stalls on some architectures. */ -extern long rcu_gp_ctr; +extern unsigned long rcu_gp_ctr; struct rcu_reader { /* Data used by both reader and synchronize_rcu() */ - long ctr; + unsigned long ctr; /* Data used for registry */ struct cds_list_head node __attribute__((aligned(CAA_CACHE_LINE_SIZE))); pthread_t tid; @@ -147,19 +153,22 @@ struct rcu_reader { */ extern DECLARE_URCU_TLS(struct rcu_reader *, rcu_reader); -static inline int rcu_old_gp_ongoing(long *value) +static inline enum rcu_state rcu_reader_state(unsigned long *ctr) { - long v; + unsigned long v; - if (value == NULL) - return 0; + if (ctr == NULL) + return RCU_READER_INACTIVE; /* * Make sure both tests below are done on the same version of *value * to insure consistency. */ - v = CMM_LOAD_SHARED(*value); - return (v & RCU_GP_CTR_NEST_MASK) && - ((v ^ rcu_gp_ctr) & RCU_GP_CTR_PHASE); + v = CMM_LOAD_SHARED(*ctr); + if (!(v & RCU_GP_CTR_NEST_MASK)) + return RCU_READER_INACTIVE; + if (!((v ^ rcu_gp_ctr) & RCU_GP_CTR_PHASE)) + return RCU_READER_ACTIVE_CURRENT; + return RCU_READER_ACTIVE_OLD; } /* @@ -190,7 +199,7 @@ static inline void _rcu_read_lock_update(unsigned long tmp) */ static inline void _rcu_read_lock(void) { - long tmp; + unsigned long tmp; if (caa_unlikely(!URCU_TLS(rcu_reader))) rcu_bp_register(); /* If not yet registered. */