Commit 23cde8bb1265bc9dba63dac64055bd9857d7285f

Authored by aliguori
1 parent c6a6a5e3

Update sys-queue.h (Gerd Hoffmann)

 - got recent copy from netbsd.
 - deleted debug code.
 - deleted some list implementations, left in only the ones which
   qemu already has.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4973 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 338 additions and 241 deletions
audio/sys-queue.h
1 -/*  
2 - * Copyright (c) 1991, 1993  
3 - * The Regents of the University of California. All rights reserved.  
4 - *  
5 - * Redistribution and use in source and binary forms, with or without  
6 - * modification, are permitted provided that the following conditions  
7 - * are met:  
8 - * 1. Redistributions of source code must retain the above copyright  
9 - * notice, this list of conditions and the following disclaimer.  
10 - * 2. Redistributions in binary form must reproduce the above copyright  
11 - * notice, this list of conditions and the following disclaimer in the  
12 - * documentation and/or other materials provided with the distribution.  
13 - * 4. Neither the name of the University nor the names of its contributors  
14 - * may be used to endorse or promote products derived from this software  
15 - * without specific prior written permission.  
16 - *  
17 - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND  
18 - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  
19 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  
20 - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE  
21 - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  
22 - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS  
23 - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)  
24 - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT  
25 - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY  
26 - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF  
27 - * SUCH DAMAGE.  
28 - *  
29 - * @(#)queue.h 8.3 (Berkeley) 12/13/93  
30 - */  
31 -  
32 -#ifndef _SYS_QUEUE_H  
33 -#define _SYS_QUEUE_H 1  
34 -  
35 -/*  
36 - * This file defines three types of data structures: lists, tail queues,  
37 - * and circular queues.  
38 - *  
39 - * A list is headed by a single forward pointer (or an array of forward  
40 - * pointers for a hash table header). The elements are doubly linked  
41 - * so that an arbitrary element can be removed without a need to  
42 - * traverse the list. New elements can be added to the list after  
43 - * an existing element or at the head of the list. A list may only be  
44 - * traversed in the forward direction.  
45 - *  
46 - * A tail queue is headed by a pair of pointers, one to the head of the  
47 - * list and the other to the tail of the list. The elements are doubly  
48 - * linked so that an arbitrary element can be removed without a need to  
49 - * traverse the list. New elements can be added to the list after  
50 - * an existing element, at the head of the list, or at the end of the  
51 - * list. A tail queue may only be traversed in the forward direction.  
52 - *  
53 - * A circle queue is headed by a pair of pointers, one to the head of the  
54 - * list and the other to the tail of the list. The elements are doubly  
55 - * linked so that an arbitrary element can be removed without a need to  
56 - * traverse the list. New elements can be added to the list before or after  
57 - * an existing element, at the head of the list, or at the end of the list.  
58 - * A circle queue may be traversed in either direction, but has a more  
59 - * complex end of list detection.  
60 - *  
61 - * For details on the use of these macros, see the queue(3) manual page.  
62 - */  
63 -  
64 -/*  
65 - * List definitions.  
66 - */  
67 -#define LIST_HEAD(name, type) \  
68 -struct name { \  
69 - struct type *lh_first; /* first element */ \  
70 -}  
71 -  
72 -#define LIST_ENTRY(type) \  
73 -struct { \  
74 - struct type *le_next; /* next element */ \  
75 - struct type **le_prev; /* address of previous next element */ \  
76 -}  
77 -  
78 -/*  
79 - * List functions.  
80 - */  
81 -#define LIST_INIT(head) { \  
82 - (head)->lh_first = NULL; \  
83 -}  
84 -  
85 -#define LIST_INSERT_AFTER(listelm, elm, field) { \  
86 - if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \  
87 - (listelm)->field.le_next->field.le_prev = \  
88 - &(elm)->field.le_next; \  
89 - (listelm)->field.le_next = (elm); \  
90 - (elm)->field.le_prev = &(listelm)->field.le_next; \  
91 -}  
92 -  
93 -#define LIST_INSERT_HEAD(head, elm, field) { \  
94 - if (((elm)->field.le_next = (head)->lh_first) != NULL) \  
95 - (head)->lh_first->field.le_prev = &(elm)->field.le_next;\  
96 - (head)->lh_first = (elm); \  
97 - (elm)->field.le_prev = &(head)->lh_first; \  
98 -}  
99 -  
100 -#define LIST_REMOVE(elm, field) { \  
101 - if ((elm)->field.le_next != NULL) \  
102 - (elm)->field.le_next->field.le_prev = \  
103 - (elm)->field.le_prev; \  
104 - *(elm)->field.le_prev = (elm)->field.le_next; \  
105 -}  
106 -  
107 -/*  
108 - * Tail queue definitions.  
109 - */  
110 -#define TAILQ_HEAD(name, type) \  
111 -struct name { \  
112 - struct type *tqh_first; /* first element */ \  
113 - struct type **tqh_last; /* addr of last next element */ \  
114 -}  
115 -  
116 -#define TAILQ_ENTRY(type) \  
117 -struct { \  
118 - struct type *tqe_next; /* next element */ \  
119 - struct type **tqe_prev; /* address of previous next element */ \  
120 -}  
121 -  
122 -/*  
123 - * Tail queue functions.  
124 - */  
125 -#define TAILQ_INIT(head) { \  
126 - (head)->tqh_first = NULL; \  
127 - (head)->tqh_last = &(head)->tqh_first; \  
128 -}  
129 -  
130 -#define TAILQ_INSERT_HEAD(head, elm, field) { \  
131 - if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \  
132 - (elm)->field.tqe_next->field.tqe_prev = \  
133 - &(elm)->field.tqe_next; \  
134 - else \  
135 - (head)->tqh_last = &(elm)->field.tqe_next; \  
136 - (head)->tqh_first = (elm); \  
137 - (elm)->field.tqe_prev = &(head)->tqh_first; \  
138 -}  
139 -  
140 -#define TAILQ_INSERT_TAIL(head, elm, field) { \  
141 - (elm)->field.tqe_next = NULL; \  
142 - (elm)->field.tqe_prev = (head)->tqh_last; \  
143 - *(head)->tqh_last = (elm); \  
144 - (head)->tqh_last = &(elm)->field.tqe_next; \  
145 -}  
146 -  
147 -#define TAILQ_INSERT_AFTER(head, listelm, elm, field) { \  
148 - if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\  
149 - (elm)->field.tqe_next->field.tqe_prev = \  
150 - &(elm)->field.tqe_next; \  
151 - else \  
152 - (head)->tqh_last = &(elm)->field.tqe_next; \  
153 - (listelm)->field.tqe_next = (elm); \  
154 - (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \  
155 -}  
156 -  
157 -#define TAILQ_REMOVE(head, elm, field) { \  
158 - if (((elm)->field.tqe_next) != NULL) \  
159 - (elm)->field.tqe_next->field.tqe_prev = \  
160 - (elm)->field.tqe_prev; \  
161 - else \  
162 - (head)->tqh_last = (elm)->field.tqe_prev; \  
163 - *(elm)->field.tqe_prev = (elm)->field.tqe_next; \  
164 -}  
165 -  
166 -/*  
167 - * Circular queue definitions.  
168 - */  
169 -#define CIRCLEQ_HEAD(name, type) \  
170 -struct name { \  
171 - struct type *cqh_first; /* first element */ \  
172 - struct type *cqh_last; /* last element */ \  
173 -}  
174 -  
175 -#define CIRCLEQ_ENTRY(type) \  
176 -struct { \  
177 - struct type *cqe_next; /* next element */ \  
178 - struct type *cqe_prev; /* previous element */ \  
179 -}  
180 -  
181 -/*  
182 - * Circular queue functions.  
183 - */  
184 -#define CIRCLEQ_INIT(head) { \  
185 - (head)->cqh_first = (void *)(head); \  
186 - (head)->cqh_last = (void *)(head); \  
187 -}  
188 -  
189 -#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) { \  
190 - (elm)->field.cqe_next = (listelm)->field.cqe_next; \  
191 - (elm)->field.cqe_prev = (listelm); \  
192 - if ((listelm)->field.cqe_next == (void *)(head)) \  
193 - (head)->cqh_last = (elm); \  
194 - else \  
195 - (listelm)->field.cqe_next->field.cqe_prev = (elm); \  
196 - (listelm)->field.cqe_next = (elm); \  
197 -}  
198 -  
199 -#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) { \  
200 - (elm)->field.cqe_next = (listelm); \  
201 - (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \  
202 - if ((listelm)->field.cqe_prev == (void *)(head)) \  
203 - (head)->cqh_first = (elm); \  
204 - else \  
205 - (listelm)->field.cqe_prev->field.cqe_next = (elm); \  
206 - (listelm)->field.cqe_prev = (elm); \  
207 -}  
208 -  
209 -#define CIRCLEQ_INSERT_HEAD(head, elm, field) { \  
210 - (elm)->field.cqe_next = (head)->cqh_first; \  
211 - (elm)->field.cqe_prev = (void *)(head); \  
212 - if ((head)->cqh_last == (void *)(head)) \  
213 - (head)->cqh_last = (elm); \  
214 - else \  
215 - (head)->cqh_first->field.cqe_prev = (elm); \  
216 - (head)->cqh_first = (elm); \  
217 -}  
218 -  
219 -#define CIRCLEQ_INSERT_TAIL(head, elm, field) { \  
220 - (elm)->field.cqe_next = (void *)(head); \  
221 - (elm)->field.cqe_prev = (head)->cqh_last; \  
222 - if ((head)->cqh_first == (void *)(head)) \  
223 - (head)->cqh_first = (elm); \  
224 - else \  
225 - (head)->cqh_last->field.cqe_next = (elm); \  
226 - (head)->cqh_last = (elm); \  
227 -}  
228 -  
229 -#define CIRCLEQ_REMOVE(head, elm, field) { \  
230 - if ((elm)->field.cqe_next == (void *)(head)) \  
231 - (head)->cqh_last = (elm)->field.cqe_prev; \  
232 - else \  
233 - (elm)->field.cqe_next->field.cqe_prev = \  
234 - (elm)->field.cqe_prev; \  
235 - if ((elm)->field.cqe_prev == (void *)(head)) \  
236 - (head)->cqh_first = (elm)->field.cqe_next; \  
237 - else \  
238 - (elm)->field.cqe_prev->field.cqe_next = \  
239 - (elm)->field.cqe_next; \  
240 -}  
241 -#endif /* sys/queue.h */ 1 +/* $NetBSD: queue.h,v 1.45.14.1 2007/07/18 20:13:24 liamjfoy Exp $ */
  2 +
  3 +/*
  4 + * Qemu version: Copy from netbsd, removed debug code, removed some of
  5 + * the implementations. Left in lists, tail queues and circular queues.
  6 + */
  7 +
  8 +/*
  9 + * Copyright (c) 1991, 1993
  10 + * The Regents of the University of California. All rights reserved.
  11 + *
  12 + * Redistribution and use in source and binary forms, with or without
  13 + * modification, are permitted provided that the following conditions
  14 + * are met:
  15 + * 1. Redistributions of source code must retain the above copyright
  16 + * notice, this list of conditions and the following disclaimer.
  17 + * 2. Redistributions in binary form must reproduce the above copyright
  18 + * notice, this list of conditions and the following disclaimer in the
  19 + * documentation and/or other materials provided with the distribution.
  20 + * 3. Neither the name of the University nor the names of its contributors
  21 + * may be used to endorse or promote products derived from this software
  22 + * without specific prior written permission.
  23 + *
  24 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27 + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34 + * SUCH DAMAGE.
  35 + *
  36 + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  37 + */
  38 +
  39 +#ifndef _SYS_QUEUE_H_
  40 +#define _SYS_QUEUE_H_
  41 +
  42 +/*
  43 + * This file defines three types of data structures:
  44 + * lists, tail queues, and circular queues.
  45 + *
  46 + * A list is headed by a single forward pointer (or an array of forward
  47 + * pointers for a hash table header). The elements are doubly linked
  48 + * so that an arbitrary element can be removed without a need to
  49 + * traverse the list. New elements can be added to the list before
  50 + * or after an existing element or at the head of the list. A list
  51 + * may only be traversed in the forward direction.
  52 + *
  53 + * A tail queue is headed by a pair of pointers, one to the head of the
  54 + * list and the other to the tail of the list. The elements are doubly
  55 + * linked so that an arbitrary element can be removed without a need to
  56 + * traverse the list. New elements can be added to the list before or
  57 + * after an existing element, at the head of the list, or at the end of
  58 + * the list. A tail queue may be traversed in either direction.
  59 + *
  60 + * A circle queue is headed by a pair of pointers, one to the head of the
  61 + * list and the other to the tail of the list. The elements are doubly
  62 + * linked so that an arbitrary element can be removed without a need to
  63 + * traverse the list. New elements can be added to the list before or after
  64 + * an existing element, at the head of the list, or at the end of the list.
  65 + * A circle queue may be traversed in either direction, but has a more
  66 + * complex end of list detection.
  67 + *
  68 + * For details on the use of these macros, see the queue(3) manual page.
  69 + */
  70 +
  71 +/*
  72 + * List definitions.
  73 + */
  74 +#define LIST_HEAD(name, type) \
  75 +struct name { \
  76 + struct type *lh_first; /* first element */ \
  77 +}
  78 +
  79 +#define LIST_HEAD_INITIALIZER(head) \
  80 + { NULL }
  81 +
  82 +#define LIST_ENTRY(type) \
  83 +struct { \
  84 + struct type *le_next; /* next element */ \
  85 + struct type **le_prev; /* address of previous next element */ \
  86 +}
  87 +
  88 +/*
  89 + * List functions.
  90 + */
  91 +#define LIST_INIT(head) do { \
  92 + (head)->lh_first = NULL; \
  93 +} while (/*CONSTCOND*/0)
  94 +
  95 +#define LIST_INSERT_AFTER(listelm, elm, field) do { \
  96 + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
  97 + (listelm)->field.le_next->field.le_prev = \
  98 + &(elm)->field.le_next; \
  99 + (listelm)->field.le_next = (elm); \
  100 + (elm)->field.le_prev = &(listelm)->field.le_next; \
  101 +} while (/*CONSTCOND*/0)
  102 +
  103 +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
  104 + (elm)->field.le_prev = (listelm)->field.le_prev; \
  105 + (elm)->field.le_next = (listelm); \
  106 + *(listelm)->field.le_prev = (elm); \
  107 + (listelm)->field.le_prev = &(elm)->field.le_next; \
  108 +} while (/*CONSTCOND*/0)
  109 +
  110 +#define LIST_INSERT_HEAD(head, elm, field) do { \
  111 + if (((elm)->field.le_next = (head)->lh_first) != NULL) \
  112 + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
  113 + (head)->lh_first = (elm); \
  114 + (elm)->field.le_prev = &(head)->lh_first; \
  115 +} while (/*CONSTCOND*/0)
  116 +
  117 +#define LIST_REMOVE(elm, field) do { \
  118 + if ((elm)->field.le_next != NULL) \
  119 + (elm)->field.le_next->field.le_prev = \
  120 + (elm)->field.le_prev; \
  121 + *(elm)->field.le_prev = (elm)->field.le_next; \
  122 +} while (/*CONSTCOND*/0)
  123 +
  124 +#define LIST_FOREACH(var, head, field) \
  125 + for ((var) = ((head)->lh_first); \
  126 + (var); \
  127 + (var) = ((var)->field.le_next))
  128 +
  129 +/*
  130 + * List access methods.
  131 + */
  132 +#define LIST_EMPTY(head) ((head)->lh_first == NULL)
  133 +#define LIST_FIRST(head) ((head)->lh_first)
  134 +#define LIST_NEXT(elm, field) ((elm)->field.le_next)
  135 +
  136 +
  137 +/*
  138 + * Tail queue definitions.
  139 + */
  140 +#define _TAILQ_HEAD(name, type, qual) \
  141 +struct name { \
  142 + qual type *tqh_first; /* first element */ \
  143 + qual type *qual *tqh_last; /* addr of last next element */ \
  144 +}
  145 +#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type,)
  146 +
  147 +#define TAILQ_HEAD_INITIALIZER(head) \
  148 + { NULL, &(head).tqh_first }
  149 +
  150 +#define _TAILQ_ENTRY(type, qual) \
  151 +struct { \
  152 + qual type *tqe_next; /* next element */ \
  153 + qual type *qual *tqe_prev; /* address of previous next element */\
  154 +}
  155 +#define TAILQ_ENTRY(type) _TAILQ_ENTRY(struct type,)
  156 +
  157 +/*
  158 + * Tail queue functions.
  159 + */
  160 +#define TAILQ_INIT(head) do { \
  161 + (head)->tqh_first = NULL; \
  162 + (head)->tqh_last = &(head)->tqh_first; \
  163 +} while (/*CONSTCOND*/0)
  164 +
  165 +#define TAILQ_INSERT_HEAD(head, elm, field) do { \
  166 + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  167 + (head)->tqh_first->field.tqe_prev = \
  168 + &(elm)->field.tqe_next; \
  169 + else \
  170 + (head)->tqh_last = &(elm)->field.tqe_next; \
  171 + (head)->tqh_first = (elm); \
  172 + (elm)->field.tqe_prev = &(head)->tqh_first; \
  173 +} while (/*CONSTCOND*/0)
  174 +
  175 +#define TAILQ_INSERT_TAIL(head, elm, field) do { \
  176 + (elm)->field.tqe_next = NULL; \
  177 + (elm)->field.tqe_prev = (head)->tqh_last; \
  178 + *(head)->tqh_last = (elm); \
  179 + (head)->tqh_last = &(elm)->field.tqe_next; \
  180 +} while (/*CONSTCOND*/0)
  181 +
  182 +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  183 + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  184 + (elm)->field.tqe_next->field.tqe_prev = \
  185 + &(elm)->field.tqe_next; \
  186 + else \
  187 + (head)->tqh_last = &(elm)->field.tqe_next; \
  188 + (listelm)->field.tqe_next = (elm); \
  189 + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  190 +} while (/*CONSTCOND*/0)
  191 +
  192 +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  193 + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  194 + (elm)->field.tqe_next = (listelm); \
  195 + *(listelm)->field.tqe_prev = (elm); \
  196 + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  197 +} while (/*CONSTCOND*/0)
  198 +
  199 +#define TAILQ_REMOVE(head, elm, field) do { \
  200 + if (((elm)->field.tqe_next) != NULL) \
  201 + (elm)->field.tqe_next->field.tqe_prev = \
  202 + (elm)->field.tqe_prev; \
  203 + else \
  204 + (head)->tqh_last = (elm)->field.tqe_prev; \
  205 + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  206 +} while (/*CONSTCOND*/0)
  207 +
  208 +#define TAILQ_FOREACH(var, head, field) \
  209 + for ((var) = ((head)->tqh_first); \
  210 + (var); \
  211 + (var) = ((var)->field.tqe_next))
  212 +
  213 +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  214 + for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \
  215 + (var); \
  216 + (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
  217 +
  218 +/*
  219 + * Tail queue access methods.
  220 + */
  221 +#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
  222 +#define TAILQ_FIRST(head) ((head)->tqh_first)
  223 +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  224 +
  225 +#define TAILQ_LAST(head, headname) \
  226 + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  227 +#define TAILQ_PREV(elm, headname, field) \
  228 + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  229 +
  230 +
  231 +/*
  232 + * Circular queue definitions.
  233 + */
  234 +#define CIRCLEQ_HEAD(name, type) \
  235 +struct name { \
  236 + struct type *cqh_first; /* first element */ \
  237 + struct type *cqh_last; /* last element */ \
  238 +}
  239 +
  240 +#define CIRCLEQ_HEAD_INITIALIZER(head) \
  241 + { (void *)&head, (void *)&head }
  242 +
  243 +#define CIRCLEQ_ENTRY(type) \
  244 +struct { \
  245 + struct type *cqe_next; /* next element */ \
  246 + struct type *cqe_prev; /* previous element */ \
  247 +}
  248 +
  249 +/*
  250 + * Circular queue functions.
  251 + */
  252 +#define CIRCLEQ_INIT(head) do { \
  253 + (head)->cqh_first = (void *)(head); \
  254 + (head)->cqh_last = (void *)(head); \
  255 +} while (/*CONSTCOND*/0)
  256 +
  257 +#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  258 + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  259 + (elm)->field.cqe_prev = (listelm); \
  260 + if ((listelm)->field.cqe_next == (void *)(head)) \
  261 + (head)->cqh_last = (elm); \
  262 + else \
  263 + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  264 + (listelm)->field.cqe_next = (elm); \
  265 +} while (/*CONSTCOND*/0)
  266 +
  267 +#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  268 + (elm)->field.cqe_next = (listelm); \
  269 + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  270 + if ((listelm)->field.cqe_prev == (void *)(head)) \
  271 + (head)->cqh_first = (elm); \
  272 + else \
  273 + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  274 + (listelm)->field.cqe_prev = (elm); \
  275 +} while (/*CONSTCOND*/0)
  276 +
  277 +#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  278 + (elm)->field.cqe_next = (head)->cqh_first; \
  279 + (elm)->field.cqe_prev = (void *)(head); \
  280 + if ((head)->cqh_last == (void *)(head)) \
  281 + (head)->cqh_last = (elm); \
  282 + else \
  283 + (head)->cqh_first->field.cqe_prev = (elm); \
  284 + (head)->cqh_first = (elm); \
  285 +} while (/*CONSTCOND*/0)
  286 +
  287 +#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  288 + (elm)->field.cqe_next = (void *)(head); \
  289 + (elm)->field.cqe_prev = (head)->cqh_last; \
  290 + if ((head)->cqh_first == (void *)(head)) \
  291 + (head)->cqh_first = (elm); \
  292 + else \
  293 + (head)->cqh_last->field.cqe_next = (elm); \
  294 + (head)->cqh_last = (elm); \
  295 +} while (/*CONSTCOND*/0)
  296 +
  297 +#define CIRCLEQ_REMOVE(head, elm, field) do { \
  298 + if ((elm)->field.cqe_next == (void *)(head)) \
  299 + (head)->cqh_last = (elm)->field.cqe_prev; \
  300 + else \
  301 + (elm)->field.cqe_next->field.cqe_prev = \
  302 + (elm)->field.cqe_prev; \
  303 + if ((elm)->field.cqe_prev == (void *)(head)) \
  304 + (head)->cqh_first = (elm)->field.cqe_next; \
  305 + else \
  306 + (elm)->field.cqe_prev->field.cqe_next = \
  307 + (elm)->field.cqe_next; \
  308 +} while (/*CONSTCOND*/0)
  309 +
  310 +#define CIRCLEQ_FOREACH(var, head, field) \
  311 + for ((var) = ((head)->cqh_first); \
  312 + (var) != (const void *)(head); \
  313 + (var) = ((var)->field.cqe_next))
  314 +
  315 +#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  316 + for ((var) = ((head)->cqh_last); \
  317 + (var) != (const void *)(head); \
  318 + (var) = ((var)->field.cqe_prev))
  319 +
  320 +/*
  321 + * Circular queue access methods.
  322 + */
  323 +#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
  324 +#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
  325 +#define CIRCLEQ_LAST(head) ((head)->cqh_last)
  326 +#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  327 +#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  328 +
  329 +#define CIRCLEQ_LOOP_NEXT(head, elm, field) \
  330 + (((elm)->field.cqe_next == (void *)(head)) \
  331 + ? ((head)->cqh_first) \
  332 + : (elm->field.cqe_next))
  333 +#define CIRCLEQ_LOOP_PREV(head, elm, field) \
  334 + (((elm)->field.cqe_prev == (void *)(head)) \
  335 + ? ((head)->cqh_last) \
  336 + : (elm->field.cqe_prev))
  337 +
  338 +#endif /* !_SYS_QUEUE_H_ */