queue: add QSIMPLEQ_PREPEND()
authorStefan Hajnoczi <stefanha@redhat.com>
Thu, 22 Mar 2018 15:28:32 +0000 (15:28 +0000)
committerStefan Hajnoczi <stefanha@redhat.com>
Tue, 27 Mar 2018 12:05:28 +0000 (13:05 +0100)
QSIMPLEQ_CONCAT(a, b) joins a = a + b.  The new QSIMPLEQ_PREPEND(a, b)
API joins a = b + a.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 20180322152834.12656-2-stefanha@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
include/qemu/queue.h

index aa270d2b38283bab9b44a3aac40b79dbdac2ec35..59fd1203a1a323637fe16009c5b0a1f3cd7319a9 100644 (file)
@@ -324,6 +324,14 @@ struct {                                                                \
     }                                                                   \
 } while (/*CONSTCOND*/0)
 
+#define QSIMPLEQ_PREPEND(head1, head2) do {                             \
+    if (!QSIMPLEQ_EMPTY((head2))) {                                     \
+        *(head2)->sqh_last = (head1)->sqh_first;                        \
+        (head1)->sqh_first = (head2)->sqh_first;                          \
+        QSIMPLEQ_INIT((head2));                                         \
+    }                                                                   \
+} while (/*CONSTCOND*/0)
+
 #define QSIMPLEQ_LAST(head, type, field)                                \
     (QSIMPLEQ_EMPTY((head)) ?                                           \
         NULL :                                                          \