[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-ppc] [PATCH v2 03/11] rcu_queue: add RCU QSIMPLEQ
From: |
Emilio G. Cota |
Subject: |
[Qemu-ppc] [PATCH v2 03/11] rcu_queue: add RCU QSIMPLEQ |
Date: |
Sun, 19 Aug 2018 05:13:27 -0400 |
Signed-off-by: Emilio G. Cota <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 6881ea5274..e0395c989a 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
--
2.17.1
- [Qemu-ppc] [PATCH v2 00/11] convert CPU list to RCU, Emilio G. Cota, 2018/08/19
- [Qemu-ppc] [PATCH v2 01/11] rcu_queue: use atomic_set in QLIST_REMOVE_RCU, Emilio G. Cota, 2018/08/19
- [Qemu-ppc] [PATCH v2 06/11] test-rcu-list: access counters with atomics, Emilio G. Cota, 2018/08/19
- [Qemu-ppc] [PATCH v2 04/11] rcu_queue: add RCU QTAILQ, Emilio G. Cota, 2018/08/19
- [Qemu-ppc] [PATCH v2 07/11] test-rcu-list: abstract the list implementation, Emilio G. Cota, 2018/08/19
- [Qemu-ppc] [PATCH v2 05/11] test-rcu-list: access goflag with atomics, Emilio G. Cota, 2018/08/19
- [Qemu-ppc] [PATCH v2 03/11] rcu_queue: add RCU QSIMPLEQ,
Emilio G. Cota <=
- [Qemu-ppc] [PATCH v2 02/11] rcu_queue: remove barrier from QLIST_EMPTY_RCU, Emilio G. Cota, 2018/08/19
- [Qemu-ppc] [PATCH v2 09/11] tests: add test-rcu-tailq, Emilio G. Cota, 2018/08/19
- [Qemu-ppc] [PATCH v2 08/11] tests: add test-list-simpleq, Emilio G. Cota, 2018/08/19
- [Qemu-ppc] [PATCH v2 11/11] qom: convert the CPU list to RCU, Emilio G. Cota, 2018/08/19
- [Qemu-ppc] [PATCH v2 10/11] spapr: do not use CPU_FOREACH_REVERSE, Emilio G. Cota, 2018/08/19
- Re: [Qemu-ppc] [PATCH v2 00/11] convert CPU list to RCU, Paolo Bonzini, 2018/08/20