qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/7] qemu/queue: add some useful QLIST_ and QTAILQ_ macros


From: Max Reitz
Subject: Re: [PATCH 1/7] qemu/queue: add some useful QLIST_ and QTAILQ_ macros
Date: Wed, 10 Feb 2021 18:07:37 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0

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 <vsementsov@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.
   */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]