After, `urcu_<flavor>_synchronize_rcu()` must be called. When it
returns, the old values are not in usage anymore.
+As an alternative to `urcu_<flavor>_synchronize_rcu()`,
+it is also possible to use the urcu polling mechanism to wait for a
+grace period to elapse. This can be done by using
+`urcu_<flavor>_start_poll_synchronize_rcu()`
+to start the grace period polling, and then invoke
+`urcu_<flavor>_poll_state_synchronize_rcu()`, which returns true if
+the grace period has completed, false otherwise.
+
### Usage of `liburcu-defer`
urcu/urcu-signal.h \
urcu/wfcqueue.h \
urcu/wfqueue.h \
- urcu/wfstack.h
+ urcu/wfstack.h \
+ urcu/urcu-poll.h
# Don't distribute generated headers
nobase_nodist_include_HEADERS = urcu/config.h
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <urcu/urcu-poll.h>
+
#ifdef __cplusplus
extern "C" {
#endif
void (*register_rculfhash_atfork)(struct urcu_atfork *atfork);
void (*unregister_rculfhash_atfork)(struct urcu_atfork *atfork);
+
+ struct urcu_gp_poll_state (*update_start_poll_synchronize_rcu)(void);
+ bool (*update_poll_state_synchronize_rcu)(struct urcu_gp_poll_state state);
};
#define DEFINE_RCU_FLAVOR(x) \
.barrier = rcu_barrier, \
.register_rculfhash_atfork = urcu_register_rculfhash_atfork, \
.unregister_rculfhash_atfork = urcu_unregister_rculfhash_atfork,\
+ .update_start_poll_synchronize_rcu = start_poll_synchronize_rcu,\
+ .update_poll_state_synchronize_rcu = poll_state_synchronize_rcu,\
}
extern const struct rcu_flavor_struct rcu_flavor;
#undef urcu_register_rculfhash_atfork
#undef urcu_unregister_rculfhash_atfork
+
+#undef start_poll_synchronize_rcu
+#undef poll_state_synchronize_rcu
#define urcu_unregister_rculfhash_atfork \
urcu_bp_unregister_rculfhash_atfork
+#define start_poll_synchronize_rcu urcu_bp_start_poll_synchronize_rcu
+#define poll_state_synchronize_rcu urcu_bp_poll_state_synchronize_rcu
+
/* Compat identifiers for prior undocumented multiflavor usage */
#ifndef URCU_NO_COMPAT_IDENTIFIERS
#define urcu_unregister_rculfhash_atfork \
urcu_mb_unregister_rculfhash_atfork
+#define start_poll_synchronize_rcu urcu_mb_start_poll_synchronize_rcu
+#define poll_state_synchronize_rcu urcu_mb_poll_state_synchronize_rcu
+
/* Compat identifiers for prior undocumented multiflavor usage */
#ifndef URCU_NO_COMPAT_IDENTIFIERS
#define urcu_unregister_rculfhash_atfork \
urcu_memb_unregister_rculfhash_atfork
+#define start_poll_synchronize_rcu urcu_memb_start_poll_synchronize_rcu
+#define poll_state_synchronize_rcu urcu_memb_poll_state_synchronize_rcu
+
/* Compat identifiers for prior undocumented multiflavor usage */
#ifndef URCU_NO_COMPAT_IDENTIFIERS
#define urcu_unregister_rculfhash_atfork \
urcu_qsbr_unregister_rculfhash_atfork
+#define start_poll_synchronize_rcu urcu_qsbr_start_poll_synchronize_rcu
+#define poll_state_synchronize_rcu urcu_qsbr_poll_state_synchronize_rcu
+
+
/* Compat identifiers for prior undocumented multiflavor usage */
#ifndef URCU_NO_COMPAT_IDENTIFIERS
#define urcu_unregister_rculfhash_atfork \
urcu_signal_unregister_rculfhash_atfork
+#define start_poll_synchronize_rcu urcu_signal_start_poll_synchronize_rcu
+#define poll_state_synchronize_rcu urcu_signal_poll_state_synchronize_rcu
+
/* Compat identifiers for prior undocumented multiflavor usage */
#ifndef URCU_NO_COMPAT_IDENTIFIERS
#include <stdlib.h>
#include <pthread.h>
+#include <stdbool.h>
#include <urcu/map/urcu-bp.h>
* publication headers.
*/
#include <urcu/pointer.h>
+#include <urcu/urcu-poll.h>
#ifdef __cplusplus
extern "C" {
extern void urcu_bp_synchronize_rcu(void);
+/*
+ * RCU grace period polling API.
+ */
+extern struct urcu_gp_poll_state urcu_bp_start_poll_synchronize_rcu(void);
+extern bool urcu_bp_poll_state_synchronize_rcu(struct urcu_gp_poll_state state);
+
/*
* urcu_bp_before_fork, urcu_bp_after_fork_parent and urcu_bp_after_fork_child
* should be called around fork() system calls when the child process is not
#include <stdlib.h>
#include <pthread.h>
+#include <stdbool.h>
/*
* See urcu/pointer.h and urcu/static/pointer.h for pointer
* publication headers.
*/
#include <urcu/pointer.h>
+#include <urcu/urcu-poll.h>
#ifdef __cplusplus
extern "C" {
extern void urcu_mb_synchronize_rcu(void);
+/*
+ * RCU grace period polling API.
+ */
+extern struct urcu_gp_poll_state urcu_mb_start_poll_synchronize_rcu(void);
+extern bool urcu_mb_poll_state_synchronize_rcu(struct urcu_gp_poll_state state);
+
/*
* Reader thread registration.
*/
#include <stdlib.h>
#include <pthread.h>
+#include <stdbool.h>
/*
* See urcu/pointer.h and urcu/static/pointer.h for pointer
* publication headers.
*/
#include <urcu/pointer.h>
+#include <urcu/urcu-poll.h>
#ifdef __cplusplus
extern "C" {
extern void urcu_memb_synchronize_rcu(void);
+/*
+ * RCU grace period polling API.
+ */
+extern struct urcu_gp_poll_state urcu_memb_start_poll_synchronize_rcu(void);
+extern bool urcu_memb_poll_state_synchronize_rcu(struct urcu_gp_poll_state state);
+
/*
* Reader thread registration.
*/
--- /dev/null
+#ifndef _URCU_POLL_H
+#define _URCU_POLL_H
+
+/*
+ * urcu-poll.h
+ *
+ * Userspace RCU polling header
+ *
+ * Copyright (c) 2023 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+struct urcu_gp_poll_state {
+ unsigned long grace_period_id;
+};
+
+#endif /* _URCU_POLL_H */
#include <stdlib.h>
#include <pthread.h>
+#include <stdbool.h>
#include <urcu/config.h>
* publication headers.
*/
#include <urcu/pointer.h>
+#include <urcu/urcu-poll.h>
#ifdef __cplusplus
extern "C" {
extern void urcu_qsbr_synchronize_rcu(void);
+/*
+ * RCU grace period polling API.
+ */
+extern struct urcu_gp_poll_state urcu_qsbr_start_poll_synchronize_rcu(void);
+extern bool urcu_qsbr_poll_state_synchronize_rcu(struct urcu_gp_poll_state state);
+
/*
* Reader thread registration.
*/
#include <stdlib.h>
#include <pthread.h>
+#include <stdbool.h>
/*
* See urcu/pointer.h and urcu/static/pointer.h for pointer
* publication headers.
*/
#include <urcu/pointer.h>
+#include <urcu/urcu-poll.h>
#ifdef __cplusplus
extern "C" {
extern void urcu_signal_synchronize_rcu(void);
+/*
+ * RCU grace period polling API.
+ */
+extern struct urcu_gp_poll_state urcu_signal_start_poll_synchronize_rcu(void);
+extern bool urcu_signal_poll_state_synchronize_rcu(struct urcu_gp_poll_state state);
+
/*
* Reader thread registration.
*/
EXTRA_DIST = \
urcu-call-rcu-impl.h \
urcu-defer-impl.h \
+ urcu-poll-impl.h \
rculfhash-internal.h
#include "urcu-call-rcu-impl.h"
#include "urcu-defer-impl.h"
+#include "urcu-poll-impl.h"
--- /dev/null
+/*
+ * urcu-poll-impl.h
+ *
+ * Userspace RCU library - Grace period polling API
+ *
+ * Copyright (c) 2023 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <pthread.h>
+#include <stdbool.h>
+
+#include <urcu/urcu-poll.h>
+#include <urcu/call-rcu.h>
+
+struct urcu_poll_worker_state {
+ struct urcu_gp_poll_state current_state;
+ struct urcu_gp_poll_state latest_target; /* Most recent snapshot taken */
+ struct rcu_head rcu_head;
+ pthread_mutex_t lock;
+ bool active;
+};
+
+static struct urcu_poll_worker_state poll_worker_gp_state = {
+ .lock = PTHREAD_MUTEX_INITIALIZER,
+};
+
+static
+void urcu_poll_worker_cb(struct rcu_head *head __attribute__((unused)))
+{
+ mutex_lock(&poll_worker_gp_state.lock);
+ /* A new grace period has been reached. */
+ poll_worker_gp_state.current_state.grace_period_id++;
+ if ((long)(poll_worker_gp_state.latest_target.grace_period_id - poll_worker_gp_state.current_state.grace_period_id) >= 0) {
+ /* Need to re-queue. */
+ call_rcu(&poll_worker_gp_state.rcu_head, urcu_poll_worker_cb);
+ } else {
+ /* No user waiting for a target grace period. */
+ poll_worker_gp_state.active = false;
+ }
+ mutex_unlock(&poll_worker_gp_state.lock);
+}
+
+/*
+ * Start polling on grace period. If no worker is currently active,
+ * snapshot the current value and start a worker callback. If the worker
+ * is currently active, snapshot the current value + 1, and set this
+ * value as the latest snapshot, which will cause the worker to re-queue
+ * itself with call_rcu to issue one more grace period.
+ *
+ * Because it uses call_rcu, it needs to be called from a registered RCU
+ * thread.
+ */
+struct urcu_gp_poll_state start_poll_synchronize_rcu(void)
+{
+ struct urcu_gp_poll_state new_target_gp_state;
+ bool was_active = false;
+
+ mutex_lock(&poll_worker_gp_state.lock);
+ new_target_gp_state.grace_period_id = poll_worker_gp_state.current_state.grace_period_id;
+ was_active = poll_worker_gp_state.active;
+ if (!was_active)
+ poll_worker_gp_state.active = true;
+ else
+ new_target_gp_state.grace_period_id++;
+ poll_worker_gp_state.latest_target.grace_period_id = new_target_gp_state.grace_period_id;
+ if (!was_active)
+ call_rcu(&poll_worker_gp_state.rcu_head, urcu_poll_worker_cb);
+ mutex_unlock(&poll_worker_gp_state.lock);
+ return new_target_gp_state;
+}
+
+/*
+ * Poll the grace period state. Return true if quiescence was reached
+ * since the snapshot was taken, return false if quiescence was not
+ * reached since snapshot.
+ */
+bool poll_state_synchronize_rcu(struct urcu_gp_poll_state target_gp_state)
+{
+ bool target_gp_reached = false;
+
+ mutex_lock(&poll_worker_gp_state.lock);
+ if ((long)(target_gp_state.grace_period_id - poll_worker_gp_state.current_state.grace_period_id) < 0)
+ target_gp_reached = true;
+ mutex_unlock(&poll_worker_gp_state.lock);
+ return target_gp_reached;
+}
#include "urcu-call-rcu-impl.h"
#include "urcu-defer-impl.h"
+#include "urcu-poll-impl.h"
#include "urcu-call-rcu-impl.h"
#include "urcu-defer-impl.h"
+#include "urcu-poll-impl.h"