X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu%2Fstatic%2Furcu.h;h=6c8b92602234b97d27a4cb462ec0ec06c56a62c7;hp=f32f300e599d95b922cbf043cc3a839e234190d5;hb=882f335739b978d1c55be2faeed077f315afe5d7;hpb=1de4df4b770e5e90440008becc5e14a15c75c6e0 diff --git a/urcu/static/urcu.h b/urcu/static/urcu.h index f32f300..6c8b926 100644 --- a/urcu/static/urcu.h +++ b/urcu/static/urcu.h @@ -96,6 +96,12 @@ extern "C" { #define SIGRCU SIGUSR1 #endif +enum rcu_state { + RCU_READER_ACTIVE_CURRENT, + RCU_READER_ACTIVE_OLD, + RCU_READER_INACTIVE, +}; + #ifdef DEBUG_RCU #define rcu_assert(args...) assert(args) #else @@ -239,7 +245,7 @@ static inline void wake_up_gp(void) } } -static inline int rcu_gp_ongoing(unsigned long *ctr) +static inline enum rcu_state rcu_reader_state(unsigned long *ctr) { unsigned long v; @@ -248,8 +254,11 @@ static inline int rcu_gp_ongoing(unsigned long *ctr) * to insure consistency. */ v = CMM_LOAD_SHARED(*ctr); - return (v & RCU_GP_CTR_NEST_MASK) && - ((v ^ rcu_gp_ctr) & RCU_GP_CTR_PHASE); + 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; } /* @@ -320,6 +329,18 @@ static inline void _rcu_read_unlock(void) cmm_barrier(); /* Ensure the compiler does not reorder us with mutex */ } +/* + * Returns whether within a RCU read-side critical section. + * + * This function is less than 10 lines long. The intent is that this + * function meets the 10-line criterion for LGPL, allowing this function + * to be invoked directly from non-LGPL code. + */ +static inline int _rcu_read_ongoing(void) +{ + return URCU_TLS(rcu_reader).ctr & RCU_GP_CTR_NEST_MASK; +} + #ifdef __cplusplus } #endif