From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v2 2/5] qemu-queue: add QSLIST
Date: Fri, 13 Jan 2012 17:34:02 +0100 [thread overview]
Message-ID: <1326472445-25966-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1326472445-25966-1-git-send-email-pbonzini@redhat.com>
Based on http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/sys/queue.h?rev=1.53
with only the prefix change.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
qemu-queue.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/qemu-queue.h b/qemu-queue.h
index 2214230..6021057 100644
--- a/qemu-queue.h
+++ b/qemu-queue.h
@@ -2,8 +2,8 @@
/*
* Qemu version: Copy from netbsd, removed debug code, removed some of
- * the implementations. Left in lists, simple queues, tail queues and
- * circular queues.
+ * the implementations. Left in singly-linked lists, lists, simple
+ * queues, tail queues and circular queues.
*/
/*
@@ -41,9 +41,19 @@
#define QEMU_SYS_QUEUE_H_
/*
- * This file defines four types of data structures:
+ * This file defines five types of data structures: singly-linked lists,
* lists, simple queues, tail queues, and circular queues.
*
+ * A singly-linked list is headed by a single forward pointer. The
+ * elements are singly linked for minimum space and pointer manipulation
+ * overhead at the expense of O(n) removal for arbitrary elements. New
+ * elements can be added to the list after an existing element or at the
+ * head of the list. Elements being removed from the head of the list
+ * should use the explicit macro for this purpose for optimum
+ * efficiency. A singly-linked list may only be traversed in the forward
+ * direction. Singly-linked lists are ideal for applications with large
+ * datasets and few or no removals or for implementing a LIFO queue.
+ *
* A list is headed by a single forward pointer (or an array of forward
* pointers for a hash table header). The elements are doubly linked
* so that an arbitrary element can be removed without a need to
@@ -161,6 +171,64 @@ struct { \
/*
+ * Singly-linked List definitions.
+ */
+#define QSLIST_HEAD(name, type) \
+struct name { \
+ struct type *slh_first; /* first element */ \
+}
+
+#define QSLIST_HEAD_INITIALIZER(head) \
+ { NULL }
+
+#define QSLIST_ENTRY(type) \
+struct { \
+ struct type *sle_next; /* next element */ \
+}
+
+/*
+ * Singly-linked List functions.
+ */
+#define QSLIST_INIT(head) do { \
+ (head)->slh_first = NULL; \
+} while (/*CONSTCOND*/0)
+
+#define QSLIST_INSERT_AFTER(slistelm, elm, field) do { \
+ (elm)->field.sle_next = (slistelm)->field.sle_next; \
+ (slistelm)->field.sle_next = (elm); \
+} while (/*CONSTCOND*/0)
+
+#define QSLIST_INSERT_HEAD(head, elm, field) do { \
+ (elm)->field.sle_next = (head)->slh_first; \
+ (head)->slh_first = (elm); \
+} while (/*CONSTCOND*/0)
+
+#define QSLIST_REMOVE_HEAD(head, field) do { \
+ (head)->slh_first = (head)->slh_first->field.sle_next; \
+} while (/*CONSTCOND*/0)
+
+#define QSLIST_REMOVE_AFTER(slistelm, field) do { \
+ (slistelm)->field.sle_next = \
+ QSLIST_NEXT(QSLIST_NEXT((slistelm), field), field); \
+} while (/*CONSTCOND*/0)
+
+#define QSLIST_FOREACH(var, head, field) \
+ for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
+
+#define QSLIST_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = QSLIST_FIRST((head)); \
+ (var) && ((tvar) = QSLIST_NEXT((var), field), 1); \
+ (var) = (tvar))
+
+/*
+ * Singly-linked List access methods.
+ */
+#define QSLIST_EMPTY(head) ((head)->slh_first == NULL)
+#define QSLIST_FIRST(head) ((head)->slh_first)
+#define QSLIST_NEXT(elm, field) ((elm)->field.sle_next)
+
+
+/*
* Simple queue definitions.
*/
#define QSIMPLEQ_HEAD(name, type) \
--
1.7.7.1
next prev parent reply other threads:[~2012-01-13 16:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-13 16:34 [Qemu-devel] [PATCH v2 0/5] qemu-queue cleanups Paolo Bonzini
2012-01-13 16:34 ` [Qemu-devel] [PATCH v2 1/5] notifier: switch to QLIST Paolo Bonzini
2012-01-13 16:34 ` Paolo Bonzini [this message]
2012-01-13 16:34 ` [Qemu-devel] [PATCH v2 3/5] qemu-queue: drop QCIRCLEQ Paolo Bonzini
2012-01-13 16:44 ` Peter Maydell
2012-01-13 17:05 ` Paolo Bonzini
2012-01-13 19:11 ` Paolo Bonzini
2012-01-13 16:34 ` [Qemu-devel] [PATCH v2 4/5] coroutine: switch to QSLIST Paolo Bonzini
2012-01-13 16:34 ` [Qemu-devel] [PATCH v2 5/5] block: use QSLIST for the AIO free list Paolo Bonzini
2012-02-17 16:03 ` Anthony Liguori
2012-02-15 9:05 ` [Qemu-devel] [PATCH v2 0/5] qemu-queue cleanups Paolo Bonzini
2012-02-17 18:15 ` Anthony Liguori
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=1326472445-25966-3-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@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).