#include "urcu/tls-compat.h"
#include "urcu-die.h"
+#include "urcu-wait.h"
/* Do not #define _LGPL_SOURCE to ensure we can emit the wrapper symbols */
#undef _LGPL_SOURCE
static CDS_LIST_HEAD(registry);
+/*
+ * Queue keeping threads awaiting to wait for a grace period. Contains
+ * struct gp_waiters_thread objects.
+ */
+static DEFINE_URCU_WAIT_QUEUE(gp_waiters);
+
static void mutex_lock(pthread_mutex_t *mutex)
{
int ret;
CDS_LIST_HEAD(cur_snap_readers);
CDS_LIST_HEAD(qsreaders);
unsigned long was_online;
+ DEFINE_URCU_WAIT_NODE(wait, URCU_WAIT_WAITING);
+ struct urcu_waiters waiters;
was_online = URCU_TLS(rcu_reader).ctr;
else
cmm_smp_mb();
+ /*
+ * Add ourself to gp_waiters queue of threads awaiting to wait
+ * for a grace period. Proceed to perform the grace period only
+ * if we are the first thread added into the queue.
+ */
+ if (urcu_wait_add(&gp_waiters, &wait) != 0) {
+ /* Not first in queue: will be awakened by another thread. */
+ urcu_adaptative_busy_wait(&wait);
+ goto gp_end;
+ }
+ /* We won't need to wake ourself up */
+ urcu_wait_set_state(&wait, URCU_WAIT_RUNNING);
+
mutex_lock(&rcu_gp_lock);
+ /*
+ * Move all waiters into our local queue.
+ */
+ urcu_move_waiters(&waiters, &gp_waiters);
+
if (cds_list_empty(®istry))
goto out;
cds_list_splice(&qsreaders, ®istry);
out:
mutex_unlock(&rcu_gp_lock);
-
+ urcu_wake_all_waiters(&waiters);
+gp_end:
/*
* Finish waiting for reader threads before letting the old ptr being
* freed.
{
CDS_LIST_HEAD(qsreaders);
unsigned long was_online;
+ DEFINE_URCU_WAIT_NODE(wait, URCU_WAIT_WAITING);
+ struct urcu_waiters waiters;
was_online = URCU_TLS(rcu_reader).ctr;
else
cmm_smp_mb();
+ /*
+ * Add ourself to gp_waiters queue of threads awaiting to wait
+ * for a grace period. Proceed to perform the grace period only
+ * if we are the first thread added into the queue.
+ */
+ if (urcu_wait_add(&gp_waiters, &wait) != 0) {
+ /* Not first in queue: will be awakened by another thread. */
+ urcu_adaptative_busy_wait(&wait);
+ goto gp_end;
+ }
+ /* We won't need to wake ourself up */
+ urcu_wait_set_state(&wait, URCU_WAIT_RUNNING);
+
mutex_lock(&rcu_gp_lock);
+
+ /*
+ * Move all waiters into our local queue.
+ */
+ urcu_move_waiters(&waiters, &gp_waiters);
+
if (cds_list_empty(®istry))
goto out;
cds_list_splice(&qsreaders, ®istry);
out:
mutex_unlock(&rcu_gp_lock);
-
+ urcu_wake_all_waiters(&waiters);
+gp_end:
if (was_online)
rcu_thread_online();
else