qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org
Subject: [Qemu-devel] [PATCH 5/8] qemu-queue: really simplify QSIMPLEQ
Date: Mon,  2 Jan 2012 19:00:34 +0100	[thread overview]
Message-ID: <1325527237-24146-6-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1325527237-24146-1-git-send-email-pbonzini@redhat.com>

QSIMPLEQ is still relatively heavyweight when used as a free list,
compared to a simple singly-linked list.  One disadvantage is that
it requires an initializer macro, unlike for example QLIST.

The patch removes the double links so that there is a "really really
simple" queue type.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-queue.h |   57 +++++++++------------------------------------------------
 1 files changed, 9 insertions(+), 48 deletions(-)

diff --git a/qemu-queue.h b/qemu-queue.h
index 2214230..5f5b63a 100644
--- a/qemu-queue.h
+++ b/qemu-queue.h
@@ -51,12 +51,11 @@
  * or after an existing element or at the head of the list. A list
  * may only be traversed in the forward direction.
  *
- * A simple queue is headed by a pair of pointers, one the head of the
- * list and the other to the tail of the list. The elements are singly
- * linked to save space, so elements can only be removed from the
- * head of the list. New elements can be added to the list after
- * an existing element, at the head of the list, or at the end of the
- * list. A simple queue may only be traversed in the forward direction.
+ * A simple queue is headed by a single forward pointer, and the elements
+ * are also singly linked to save space.  Elements can only be removed
+ * from the head of the list. New elements can be added to the list after
+ * an existing element or at the head of the list.   A simple queue may
+ * only be traversed in the forward direction.
  *
  * A tail queue is headed by a pair of pointers, one to the head of the
  * list and the other to the tail of the list. The elements are doubly
@@ -166,11 +165,10 @@ struct {                                                                \
 #define QSIMPLEQ_HEAD(name, type)                                       \
 struct name {                                                           \
     struct type *sqh_first;    /* first element */                      \
-    struct type **sqh_last;    /* addr of last next element */          \
 }
 
 #define QSIMPLEQ_HEAD_INITIALIZER(head)                                 \
-    { NULL, &(head).sqh_first }
+    { NULL }
 
 #define QSIMPLEQ_ENTRY(type)                                            \
 struct {                                                                \
@@ -182,43 +180,20 @@ struct {                                                                \
  */
 #define QSIMPLEQ_INIT(head) do {                                        \
     (head)->sqh_first = NULL;                                           \
-    (head)->sqh_last = &(head)->sqh_first;                              \
 } while (/*CONSTCOND*/0)
 
 #define QSIMPLEQ_INSERT_HEAD(head, elm, field) do {                     \
-    if (((elm)->field.sqe_next = (head)->sqh_first) == NULL)            \
-        (head)->sqh_last = &(elm)->field.sqe_next;                      \
+    (elm)->field.sqe_next = (head)->sqh_first;                          \
     (head)->sqh_first = (elm);                                          \
 } while (/*CONSTCOND*/0)
 
-#define QSIMPLEQ_INSERT_TAIL(head, elm, field) do {                     \
-    (elm)->field.sqe_next = NULL;                                       \
-    *(head)->sqh_last = (elm);                                          \
-    (head)->sqh_last = &(elm)->field.sqe_next;                          \
-} while (/*CONSTCOND*/0)
-
 #define QSIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do {           \
-    if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)    \
-        (head)->sqh_last = &(elm)->field.sqe_next;                      \
+    (elm)->field.sqe_next = (listelm)->field.sqe_next;                  \
     (listelm)->field.sqe_next = (elm);                                  \
 } while (/*CONSTCOND*/0)
 
 #define QSIMPLEQ_REMOVE_HEAD(head, field) do {                          \
-    if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL)\
-        (head)->sqh_last = &(head)->sqh_first;                          \
-} while (/*CONSTCOND*/0)
-
-#define QSIMPLEQ_REMOVE(head, elm, type, field) do {                    \
-    if ((head)->sqh_first == (elm)) {                                   \
-        QSIMPLEQ_REMOVE_HEAD((head), field);                            \
-    } else {                                                            \
-        struct type *curelm = (head)->sqh_first;                        \
-        while (curelm->field.sqe_next != (elm))                         \
-            curelm = curelm->field.sqe_next;                            \
-        if ((curelm->field.sqe_next =                                   \
-            curelm->field.sqe_next->field.sqe_next) == NULL)            \
-                (head)->sqh_last = &(curelm)->field.sqe_next;           \
-    }                                                                   \
+     (head)->sqh_first = (head)->sqh_first->field.sqe_next;             \
 } while (/*CONSTCOND*/0)
 
 #define QSIMPLEQ_FOREACH(var, head, field)                              \
@@ -231,20 +206,6 @@ struct {                                                                \
         (var) && ((next = ((var)->field.sqe_next)), 1);                 \
         (var) = (next))
 
-#define QSIMPLEQ_CONCAT(head1, head2) do {                              \
-    if (!QSIMPLEQ_EMPTY((head2))) {                                     \
-        *(head1)->sqh_last = (head2)->sqh_first;                        \
-        (head1)->sqh_last = (head2)->sqh_last;                          \
-        QSIMPLEQ_INIT((head2));                                         \
-    }                                                                   \
-} while (/*CONSTCOND*/0)
-
-#define QSIMPLEQ_LAST(head, type, field)                                \
-    (QSIMPLEQ_EMPTY((head)) ?                                           \
-        NULL :                                                          \
-            ((struct type *)(void *)                                    \
-        ((char *)((head)->sqh_last) - offsetof(struct type, field))))
-
 /*
  * Simple queue access methods.
  */
-- 
1.7.7.1

  parent reply	other threads:[~2012-01-02 18:01 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-02 18:00 [Qemu-devel] [PATCH 0/8] qemu-queue cleanups Paolo Bonzini
2012-01-02 18:00 ` [Qemu-devel] [PATCH 1/8] notifier: switch to QLIST Paolo Bonzini
2012-01-03 11:54   ` Stefan Hajnoczi
2012-01-03 11:59     ` Paolo Bonzini
2012-01-03 12:09       ` Stefan Hajnoczi
2012-01-02 18:00 ` [Qemu-devel] [PATCH 2/8] block-migration: switch to QTAILQ Paolo Bonzini
2012-01-02 18:00 ` [Qemu-devel] [PATCH 3/8] qed: " Paolo Bonzini
2012-01-02 18:00 ` [Qemu-devel] [PATCH 4/8] ccid: " Paolo Bonzini
2012-01-02 18:00 ` Paolo Bonzini [this message]
2012-01-03 12:04   ` [Qemu-devel] [Qemu-trivial] [PATCH 5/8] qemu-queue: really simplify QSIMPLEQ Stefan Hajnoczi
2012-01-13 16:04   ` [Qemu-devel] " Peter Maydell
2012-01-02 18:00 ` [Qemu-devel] [PATCH 6/8] qemu-queue: drop QCIRCLEQ Paolo Bonzini
2012-01-02 18:00 ` [Qemu-devel] [PATCH 7/8] coroutine: switch to QSIMPLEQ Paolo Bonzini
2012-01-02 18:00 ` [Qemu-devel] [PATCH 8/8] block: use QSIMPLEQ for the AIO free list Paolo Bonzini
2012-01-03 12:07 ` [Qemu-devel] [Qemu-trivial] [PATCH 0/8] qemu-queue cleanups Stefan Hajnoczi
2012-01-13 15:47 ` [Qemu-devel] " Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1325527237-24146-6-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).