diff mbox

[7/8] Add QLIST_INSERT_TAIL

Message ID 3e4c0272ca8046d7fc893c2bf76d6e7c2f5b4690.1273843151.git.jan.kiszka@siemens.com
State New
Headers show

Commit Message

Jan Kiszka May 14, 2010, 1:20 p.m. UTC
As the QLIST has not tail pointer, this requires list walking. Still
useful when lists are short or insertion time doesn't matter.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 qemu-queue.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

Comments

Paolo Bonzini May 16, 2010, 9:38 a.m. UTC | #1
On 05/14/2010 03:20 PM, Jan Kiszka wrote:
> As the QLIST has not tail pointer, this requires list walking. Still
> useful when lists are short or insertion time doesn't matter.

True, but why not switch to QTAIL instead?

Paolo
Jan Kiszka May 16, 2010, 10:16 a.m. UTC | #2
Paolo Bonzini wrote:
> On 05/14/2010 03:20 PM, Jan Kiszka wrote:
>> As the QLIST has not tail pointer, this requires list walking. Still
>> useful when lists are short or insertion time doesn't matter.
> 
> True, but why not switch to QTAIL instead?

Would be more invasive, but I can do so if it's preferred.

Jan
diff mbox

Patch

diff --git a/qemu-queue.h b/qemu-queue.h
index 1d07745..99ed1f6 100644
--- a/qemu-queue.h
+++ b/qemu-queue.h
@@ -122,6 +122,15 @@  struct {                                                                \
         (elm)->field.le_prev = &(head)->lh_first;                       \
 } while (/*CONSTCOND*/0)
 
+#define QLIST_INSERT_TAIL(head, elm, field) do {                        \
+        typeof((head)->lh_first) *qlist_lastptr = &(head)->lh_first;    \
+        while (*qlist_lastptr)                                          \
+            qlist_lastptr = &(*qlist_lastptr)->field.le_next;           \
+        (elm)->field.le_next = NULL;                                    \
+        *qlist_lastptr = (elm);                                         \
+        (elm)->field.le_prev = qlist_lastptr;                           \
+} while (/*CONSTCOND*/0)
+
 #define QLIST_REMOVE(elm, field) do {                                   \
         if ((elm)->field.le_next != NULL)                               \
                 (elm)->field.le_next->field.le_prev =                   \