From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:35081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rlk5A-0004R6-Ry for qemu-devel@nongnu.org; Fri, 13 Jan 2012 11:34:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rlk56-00079q-3h for qemu-devel@nongnu.org; Fri, 13 Jan 2012 11:34:24 -0500 Received: from mail-yx0-f173.google.com ([209.85.213.173]:33564) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rlk55-00079B-W0 for qemu-devel@nongnu.org; Fri, 13 Jan 2012 11:34:20 -0500 Received: by mail-yx0-f173.google.com with SMTP id l8so376293yen.4 for ; Fri, 13 Jan 2012 08:34:19 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 13 Jan 2012 17:34:02 +0100 Message-Id: <1326472445-25966-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1326472445-25966-1-git-send-email-pbonzini@redhat.com> References: <1326472445-25966-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v2 2/5] qemu-queue: add QSLIST List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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