X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu-qsbr.c;h=dac664935d7b898bd3dcce494845c7471c09749d;hp=5c6eaa014721267da7de5f85fff22835d41a80b2;hb=bc6c15bba37d0e6192c006c4d9815201b36d1988;hpb=8fd3b21900597654e15eb8cda2e97606a4b1d9bf diff --git a/urcu-qsbr.c b/urcu-qsbr.c index 5c6eaa0..dac6649 100644 --- a/urcu-qsbr.c +++ b/urcu-qsbr.c @@ -39,6 +39,8 @@ static pthread_mutex_t urcu_mutex = PTHREAD_MUTEX_INITIALIZER; +int gp_futex; + /* * Global grace period counter. */ @@ -99,6 +101,27 @@ static void internal_urcu_unlock(void) } } +/* + * synchronize_rcu() waiting. Single thread. + */ +static void wait_gp(struct reader_registry *index) +{ + atomic_dec(&gp_futex); + smp_mb(); /* Write futex before read reader_gp */ + if (!rcu_gp_ongoing(index->rcu_reader_qs_gp)) { + /* Read reader_gp before write futex */ + smp_mb(); + /* Callbacks are queued, don't wait. */ + atomic_set(&gp_futex, 0); + } else { + /* Read reader_gp before read futex */ + smp_rmb(); + if (atomic_read(&gp_futex) == -1) + futex(&gp_futex, FUTEX_WAIT, -1, + NULL, NULL, 0); + } +} + static void wait_for_quiescent_state(void) { struct reader_registry *index; @@ -109,13 +132,19 @@ static void wait_for_quiescent_state(void) * Wait for each thread rcu_reader_qs_gp count to become 0. */ for (index = registry; index < registry + num_readers; index++) { + int wait_loops = 0; + + while (rcu_gp_ongoing(index->rcu_reader_qs_gp)) { + if (wait_loops++ == RCU_QS_ACTIVE_ATTEMPTS) { + wait_gp(index); + } else { #ifndef HAS_INCOHERENT_CACHES - while (rcu_gp_ongoing(index->rcu_reader_qs_gp)) - cpu_relax(); + cpu_relax(); #else /* #ifndef HAS_INCOHERENT_CACHES */ - while (rcu_gp_ongoing(index->rcu_reader_qs_gp)) - smp_mb(); + smp_mb(); #endif /* #else #ifndef HAS_INCOHERENT_CACHES */ + } + } } }