On 29.01.21 17:50, Vladimir Sementsov-Ogievskiy wrote:
Add QLIST_FOREACH_FUNC_SAFE(), QTAILQ_FOREACH_FUNC_SAFE() and
QTAILQ_POP_HEAD(), to be used in following commit.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com>
---
include/qemu/queue.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/include/qemu/queue.h b/include/qemu/queue.h
index e029e7bf66..03e1fce85f 100644
--- a/include/qemu/queue.h
+++ b/include/qemu/queue.h
@@ -173,6 +173,13 @@ struct {
\
(var) && ((next_var) = ((var)->field.le_next), 1); \
(var) = (next_var))
+#define QLIST_FOREACH_FUNC_SAFE(head, field, func) do { \
+ typeof(*QLIST_FIRST(head)) *qffs_var, *qffs_next_var; \
+ QLIST_FOREACH_SAFE(qffs_var, (head), field, qffs_next_var) { \
+ (func)(qffs_var); \
+ } \
+} while (/*CONSTCOND*/0)
+
On one hand I have inexplicable reservations against adding these macros
if they’re only used one time in the next patch.
On the other, I have one clearly expressible reservation, and that’s the
fact that perhaps some future functions that could make use of this want
to take more arguments, like closures.
Could we make these function vararg macros? I.e., e.g.,
#define QLIST_FOREACH_FUNC_SAFE(head, field, func, ...) do {
...
(func)(qffs_var, ## __VA_ARGS__);
...
Max
/*
* List access methods.
*/
@@ -490,6 +497,13 @@ union {
\
(var) && ((prev_var) = QTAILQ_PREV(var, field), 1); \
(var) = (prev_var))
+#define QTAILQ_FOREACH_FUNC_SAFE(head, field, func) do { \
+ typeof(*QTAILQ_FIRST(head)) *qffs_var, *qffs_next_var; \
+ QTAILQ_FOREACH_SAFE(qffs_var, (head), field, qffs_next_var) { \
+ (func)(qffs_var); \
+ } \
+} while (/*CONSTCOND*/0)
+
/*
* Tail queue access methods.
*/