queue.h: Add QLIST_FIX_HEAD_PTR()
authorKevin Wolf <kwolf@redhat.com>
Wed, 10 Jun 2015 11:47:35 +0000 (13:47 +0200)
committerKevin Wolf <kwolf@redhat.com>
Fri, 12 Jun 2015 15:04:59 +0000 (17:04 +0200)
If the head of a list has been moved to a different memory location, the
le_prev link in the first list entry has to be fixed up. Provide a macro
that implements this fixup.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
include/qemu/queue.h

index f781aa20a83ee1d05f01fcaf87cfb1039c4ff0eb..a8d3cb8e6300542b7bcce5db3c672ddcdad8b10a 100644 (file)
@@ -117,6 +117,12 @@ struct {                                                                \
         }                                                               \
 } while (/*CONSTCOND*/0)
 
+#define QLIST_FIX_HEAD_PTR(head, field) do {                            \
+        if ((head)->lh_first != NULL) {                                 \
+            (head)->lh_first->field.le_prev = &(head)->lh_first;        \
+        }                                                               \
+} while (/*CONSTCOND*/0)
+
 #define QLIST_INSERT_AFTER(listelm, elm, field) do {                    \
         if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)  \
                 (listelm)->field.le_next->field.le_prev =               \