[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 38/74] rcu_queue: add RCU QSIMPLEQ
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 38/74] rcu_queue: add RCU QSIMPLEQ |
Date: |
Tue, 21 Aug 2018 19:02:10 +0200 |
From: "Emilio G. Cota" <address@hidden>
Signed-off-by: Emilio G. Cota <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
include/qemu/rcu_queue.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/include/qemu/rcu_queue.h b/include/qemu/rcu_queue.h
index 6881ea5..e0395c9 100644
--- a/include/qemu/rcu_queue.h
+++ b/include/qemu/rcu_queue.h
@@ -128,6 +128,71 @@ extern "C" {
((next_var) = atomic_rcu_read(&(var)->field.le_next), 1); \
(var) = (next_var))
+/*
+ * RCU simple queue
+ */
+
+/* Simple queue access methods */
+#define QSIMPLEQ_EMPTY_RCU(head) (atomic_read(&(head)->sqh_first) == NULL)
+#define QSIMPLEQ_FIRST_RCU(head) atomic_rcu_read(&(head)->sqh_first)
+#define QSIMPLEQ_NEXT_RCU(elm, field) atomic_rcu_read(&(elm)->field.sqe_next)
+
+/* Simple queue functions */
+#define QSIMPLEQ_INSERT_HEAD_RCU(head, elm, field) do { \
+ (elm)->field.sqe_next = (head)->sqh_first; \
+ if ((elm)->field.sqe_next == NULL) { \
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+ } \
+ atomic_rcu_set(&(head)->sqh_first, (elm)); \
+} while (/*CONSTCOND*/0)
+
+#define QSIMPLEQ_INSERT_TAIL_RCU(head, elm, field) do { \
+ (elm)->field.sqe_next = NULL; \
+ atomic_rcu_set((head)->sqh_last, (elm)); \
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+} while (/*CONSTCOND*/0)
+
+#define QSIMPLEQ_INSERT_AFTER_RCU(head, listelm, elm, field) do { \
+ (elm)->field.sqe_next = (listelm)->field.sqe_next; \
+ if ((elm)->field.sqe_next == NULL) { \
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+ } \
+ atomic_rcu_set(&(listelm)->field.sqe_next, (elm)); \
+} while (/*CONSTCOND*/0)
+
+#define QSIMPLEQ_REMOVE_HEAD_RCU(head, field) do { \
+ atomic_set(&(head)->sqh_first, (head)->sqh_first->field.sqe_next); \
+ if ((head)->sqh_first == NULL) { \
+ (head)->sqh_last = &(head)->sqh_first; \
+ } \
+} while (/*CONSTCOND*/0)
+
+#define QSIMPLEQ_REMOVE_RCU(head, elm, type, field) do { \
+ if ((head)->sqh_first == (elm)) { \
+ QSIMPLEQ_REMOVE_HEAD_RCU((head), field); \
+ } else { \
+ struct type *curr = (head)->sqh_first; \
+ while (curr->field.sqe_next != (elm)) { \
+ curr = curr->field.sqe_next; \
+ } \
+ atomic_set(&curr->field.sqe_next, \
+ curr->field.sqe_next->field.sqe_next); \
+ if (curr->field.sqe_next == NULL) { \
+ (head)->sqh_last = &(curr)->field.sqe_next; \
+ } \
+ } \
+} while (/*CONSTCOND*/0)
+
+#define QSIMPLEQ_FOREACH_RCU(var, head, field) \
+ for ((var) = atomic_rcu_read(&(head)->sqh_first); \
+ (var); \
+ (var) = atomic_rcu_read(&(var)->field.sqe_next))
+
+#define QSIMPLEQ_FOREACH_SAFE_RCU(var, head, field, next) \
+ for ((var) = atomic_rcu_read(&(head)->sqh_first); \
+ (var) && ((next) = atomic_rcu_read(&(var)->field.sqe_next), 1); \
+ (var) = (next))
+
#ifdef __cplusplus
}
#endif
--
1.8.3.1
- [Qemu-devel] [PULL 17/74] seqlock: constify seqlock_read_begin, (continued)
- [Qemu-devel] [PULL 17/74] seqlock: constify seqlock_read_begin, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 43/74] tests: add test-list-simpleq, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 44/74] tests: add test-rcu-tailq, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 49/74] module: Use QEMU_MODULE_DIR as a search path, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 51/74] seqlock: add QemuLockable support, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 41/74] test-rcu-list: access counters with atomics, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 39/74] rcu_queue: add RCU QTAILQ, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 46/74] qom: convert the CPU list to RCU, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 23/74] tests/atomic_add-bench: add -p to enable sync profiler, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 52/74] cpus: protect TimerState writes with a spinlock, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 38/74] rcu_queue: add RCU QSIMPLEQ,
Paolo Bonzini <=
- [Qemu-devel] [PULL 45/74] spapr: do not use CPU_FOREACH_REVERSE, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 30/74] i386: Fix arch_query_cpu_model_expansion() leak, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 40/74] test-rcu-list: access goflag with atomics, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 42/74] test-rcu-list: abstract the list implementation, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 55/74] vhost-scsi: unify vhost-scsi get_features implementations, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 53/74] cpus: allow cpu_get_ticks out of BQL, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 50/74] cpus: protect all icount computation with seqlock, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 26/74] hmp-commands-info: add sync-profile, Paolo Bonzini, 2018/08/21