diff mbox series

[PULL,v2,25/73] queue: add QTAILQ_REMOVE_SEVERAL

Message ID 20191025063713.23374-26-alex.bennee@linaro.org
State Accepted
Commit 050ec8cc18f020b3231db3311241cd3534e7a15f
Headers show
Series tcg plugins and testing updates | expand

Commit Message

Alex Bennée Oct. 25, 2019, 6:36 a.m. UTC
From: "Emilio G. Cota" <cota@braap.org>


This is faster than removing elements one by one.

Will gain a user soon.

Signed-off-by: Emilio G. Cota <cota@braap.org>

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


-- 
2.20.1
diff mbox series

Patch

diff --git a/include/qemu/queue.h b/include/qemu/queue.h
index 73bf4a984d8..4764d93ea3f 100644
--- a/include/qemu/queue.h
+++ b/include/qemu/queue.h
@@ -420,6 +420,16 @@  union {                                                                 \
         (elm)->field.tqe_circ.tql_prev = NULL;                          \
 } while (/*CONSTCOND*/0)
 
+/* remove @left, @right and all elements in between from @head */
+#define QTAILQ_REMOVE_SEVERAL(head, left, right, field) do {            \
+        if (((right)->field.tqe_next) != NULL)                          \
+            (right)->field.tqe_next->field.tqe_circ.tql_prev =          \
+                (left)->field.tqe_circ.tql_prev;                        \
+        else                                                            \
+            (head)->tqh_circ.tql_prev = (left)->field.tqe_circ.tql_prev; \
+        (left)->field.tqe_circ.tql_prev->tql_next = (right)->field.tqe_next; \
+    } while (/*CONSTCOND*/0)
+
 #define QTAILQ_FOREACH(var, head, field)                                \
         for ((var) = ((head)->tqh_first);                               \
                 (var);                                                  \