X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=urcu-qsbr.c;h=8d8a9cf05ced0fd18ef9943110dc22a2e6e05e87;hb=2d47d69ea0876148b5628aa8f7bd9f030a8c5d2f;hp=87cf41d7ee70f274dc6676af06e3c122dd986222;hpb=6d841bc23fc94345fe76651d73c1a3f821a85aa7;p=urcu.git diff --git a/urcu-qsbr.c b/urcu-qsbr.c index 87cf41d..8d8a9cf 100644 --- a/urcu-qsbr.c +++ b/urcu-qsbr.c @@ -52,6 +52,11 @@ int32_t gp_futex; */ unsigned long rcu_gp_ctr = RCU_GP_ONLINE; +/* + * Active attempts to check for reader Q.S. before calling futex(). + */ +#define RCU_QS_ACTIVE_ATTEMPTS 100 + /* * Written to only by each individual reader. Read by both the reader and the * writers. @@ -145,26 +150,33 @@ static void update_counter_and_wait(void) */ for (;;) { wait_loops++; - if (wait_loops == RCU_QS_ACTIVE_ATTEMPTS) { - uatomic_dec(&gp_futex); + if (wait_loops >= RCU_QS_ACTIVE_ATTEMPTS) { + uatomic_set(&gp_futex, -1); + /* + * Write futex before write waiting (the other side + * reads them in the opposite order). + */ + cmm_smp_wmb(); + cds_list_for_each_entry(index, ®istry, node) { + _CMM_STORE_SHARED(index->waiting, 1); + } /* Write futex before read reader_gp */ cmm_smp_mb(); } - cds_list_for_each_entry_safe(index, tmp, ®istry, node) { if (!rcu_gp_ongoing(&index->ctr)) cds_list_move(&index->node, &qsreaders); } if (cds_list_empty(®istry)) { - if (wait_loops == RCU_QS_ACTIVE_ATTEMPTS) { + if (wait_loops >= RCU_QS_ACTIVE_ATTEMPTS) { /* Read reader_gp before write futex */ cmm_smp_mb(); uatomic_set(&gp_futex, 0); } break; } else { - if (wait_loops == RCU_QS_ACTIVE_ATTEMPTS) { + if (wait_loops >= RCU_QS_ACTIVE_ATTEMPTS) { wait_gp(); } else { #ifndef HAS_INCOHERENT_CACHES