blob: 1d077458ce1ba5cba8d07f66c7684a170d316181 [file] [log] [blame]
Pierre Riteauc616bbe2009-11-30 18:21:20 +01001/* $NetBSD: queue.h,v 1.52 2009/04/20 09:56:08 mschuett Exp $ */
blueswir1fc56ef02008-12-14 08:53:17 +00002
3/*
4 * Qemu version: Copy from netbsd, removed debug code, removed some of
Pierre Riteauc616bbe2009-11-30 18:21:20 +01005 * the implementations. Left in lists, simple queues, tail queues and
6 * circular queues.
blueswir1fc56ef02008-12-14 08:53:17 +00007 */
8
9/*
10 * Copyright (c) 1991, 1993
11 * The Regents of the University of California. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * @(#)queue.h 8.5 (Berkeley) 8/20/94
38 */
39
Blue Swirl72cf2d42009-09-12 07:36:22 +000040#ifndef QEMU_SYS_QUEUE_H_
41#define QEMU_SYS_QUEUE_H_
blueswir1fc56ef02008-12-14 08:53:17 +000042
43/*
Pierre Riteauc616bbe2009-11-30 18:21:20 +010044 * This file defines four types of data structures:
45 * lists, simple queues, tail queues, and circular queues.
blueswir1fc56ef02008-12-14 08:53:17 +000046 *
47 * A list is headed by a single forward pointer (or an array of forward
48 * pointers for a hash table header). The elements are doubly linked
49 * so that an arbitrary element can be removed without a need to
50 * traverse the list. New elements can be added to the list before
51 * or after an existing element or at the head of the list. A list
52 * may only be traversed in the forward direction.
53 *
Pierre Riteauc616bbe2009-11-30 18:21:20 +010054 * A simple queue is headed by a pair of pointers, one the head of the
55 * list and the other to the tail of the list. The elements are singly
56 * linked to save space, so elements can only be removed from the
57 * head of the list. New elements can be added to the list after
58 * an existing element, at the head of the list, or at the end of the
59 * list. A simple queue may only be traversed in the forward direction.
60 *
blueswir1fc56ef02008-12-14 08:53:17 +000061 * A tail queue is headed by a pair of pointers, one to the head of the
62 * list and the other to the tail of the list. The elements are doubly
63 * linked so that an arbitrary element can be removed without a need to
64 * traverse the list. New elements can be added to the list before or
65 * after an existing element, at the head of the list, or at the end of
66 * the list. A tail queue may be traversed in either direction.
67 *
68 * A circle queue is headed by a pair of pointers, one to the head of the
69 * list and the other to the tail of the list. The elements are doubly
70 * linked so that an arbitrary element can be removed without a need to
71 * traverse the list. New elements can be added to the list before or after
72 * an existing element, at the head of the list, or at the end of the list.
73 * A circle queue may be traversed in either direction, but has a more
74 * complex end of list detection.
75 *
76 * For details on the use of these macros, see the queue(3) manual page.
77 */
78
79/*
80 * List definitions.
81 */
Blue Swirl72cf2d42009-09-12 07:36:22 +000082#define QLIST_HEAD(name, type) \
blueswir1fc56ef02008-12-14 08:53:17 +000083struct name { \
84 struct type *lh_first; /* first element */ \
85}
86
Blue Swirl72cf2d42009-09-12 07:36:22 +000087#define QLIST_HEAD_INITIALIZER(head) \
blueswir1fc56ef02008-12-14 08:53:17 +000088 { NULL }
89
Blue Swirl72cf2d42009-09-12 07:36:22 +000090#define QLIST_ENTRY(type) \
blueswir1fc56ef02008-12-14 08:53:17 +000091struct { \
92 struct type *le_next; /* next element */ \
93 struct type **le_prev; /* address of previous next element */ \
94}
95
96/*
97 * List functions.
98 */
Blue Swirl72cf2d42009-09-12 07:36:22 +000099#define QLIST_INIT(head) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000100 (head)->lh_first = NULL; \
101} while (/*CONSTCOND*/0)
102
Blue Swirl72cf2d42009-09-12 07:36:22 +0000103#define QLIST_INSERT_AFTER(listelm, elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000104 if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
105 (listelm)->field.le_next->field.le_prev = \
106 &(elm)->field.le_next; \
107 (listelm)->field.le_next = (elm); \
108 (elm)->field.le_prev = &(listelm)->field.le_next; \
109} while (/*CONSTCOND*/0)
110
Blue Swirl72cf2d42009-09-12 07:36:22 +0000111#define QLIST_INSERT_BEFORE(listelm, elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000112 (elm)->field.le_prev = (listelm)->field.le_prev; \
113 (elm)->field.le_next = (listelm); \
114 *(listelm)->field.le_prev = (elm); \
115 (listelm)->field.le_prev = &(elm)->field.le_next; \
116} while (/*CONSTCOND*/0)
117
Blue Swirl72cf2d42009-09-12 07:36:22 +0000118#define QLIST_INSERT_HEAD(head, elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000119 if (((elm)->field.le_next = (head)->lh_first) != NULL) \
120 (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
121 (head)->lh_first = (elm); \
122 (elm)->field.le_prev = &(head)->lh_first; \
123} while (/*CONSTCOND*/0)
124
Blue Swirl72cf2d42009-09-12 07:36:22 +0000125#define QLIST_REMOVE(elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000126 if ((elm)->field.le_next != NULL) \
127 (elm)->field.le_next->field.le_prev = \
128 (elm)->field.le_prev; \
129 *(elm)->field.le_prev = (elm)->field.le_next; \
130} while (/*CONSTCOND*/0)
131
Blue Swirl72cf2d42009-09-12 07:36:22 +0000132#define QLIST_FOREACH(var, head, field) \
blueswir1fc56ef02008-12-14 08:53:17 +0000133 for ((var) = ((head)->lh_first); \
134 (var); \
135 (var) = ((var)->field.le_next))
136
Blue Swirl72cf2d42009-09-12 07:36:22 +0000137#define QLIST_FOREACH_SAFE(var, head, field, next_var) \
Juan Quintelabb150dc2009-09-01 02:12:32 +0200138 for ((var) = ((head)->lh_first); \
139 (var) && ((next_var) = ((var)->field.le_next), 1); \
140 (var) = (next_var))
141
blueswir1fc56ef02008-12-14 08:53:17 +0000142/*
143 * List access methods.
144 */
Blue Swirl72cf2d42009-09-12 07:36:22 +0000145#define QLIST_EMPTY(head) ((head)->lh_first == NULL)
146#define QLIST_FIRST(head) ((head)->lh_first)
147#define QLIST_NEXT(elm, field) ((elm)->field.le_next)
blueswir1fc56ef02008-12-14 08:53:17 +0000148
149
150/*
Pierre Riteauc616bbe2009-11-30 18:21:20 +0100151 * Simple queue definitions.
152 */
153#define QSIMPLEQ_HEAD(name, type) \
154struct name { \
155 struct type *sqh_first; /* first element */ \
156 struct type **sqh_last; /* addr of last next element */ \
157}
158
159#define QSIMPLEQ_HEAD_INITIALIZER(head) \
160 { NULL, &(head).sqh_first }
161
162#define QSIMPLEQ_ENTRY(type) \
163struct { \
164 struct type *sqe_next; /* next element */ \
165}
166
167/*
168 * Simple queue functions.
169 */
170#define QSIMPLEQ_INIT(head) do { \
171 (head)->sqh_first = NULL; \
172 (head)->sqh_last = &(head)->sqh_first; \
173} while (/*CONSTCOND*/0)
174
175#define QSIMPLEQ_INSERT_HEAD(head, elm, field) do { \
176 if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
177 (head)->sqh_last = &(elm)->field.sqe_next; \
178 (head)->sqh_first = (elm); \
179} while (/*CONSTCOND*/0)
180
181#define QSIMPLEQ_INSERT_TAIL(head, elm, field) do { \
182 (elm)->field.sqe_next = NULL; \
183 *(head)->sqh_last = (elm); \
184 (head)->sqh_last = &(elm)->field.sqe_next; \
185} while (/*CONSTCOND*/0)
186
187#define QSIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
188 if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL) \
189 (head)->sqh_last = &(elm)->field.sqe_next; \
190 (listelm)->field.sqe_next = (elm); \
191} while (/*CONSTCOND*/0)
192
193#define QSIMPLEQ_REMOVE_HEAD(head, field) do { \
194 if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL)\
195 (head)->sqh_last = &(head)->sqh_first; \
196} while (/*CONSTCOND*/0)
197
198#define QSIMPLEQ_REMOVE(head, elm, type, field) do { \
199 if ((head)->sqh_first == (elm)) { \
200 QSIMPLEQ_REMOVE_HEAD((head), field); \
201 } else { \
202 struct type *curelm = (head)->sqh_first; \
203 while (curelm->field.sqe_next != (elm)) \
204 curelm = curelm->field.sqe_next; \
205 if ((curelm->field.sqe_next = \
206 curelm->field.sqe_next->field.sqe_next) == NULL) \
207 (head)->sqh_last = &(curelm)->field.sqe_next; \
208 } \
209} while (/*CONSTCOND*/0)
210
211#define QSIMPLEQ_FOREACH(var, head, field) \
212 for ((var) = ((head)->sqh_first); \
213 (var); \
214 (var) = ((var)->field.sqe_next))
215
216#define QSIMPLEQ_FOREACH_SAFE(var, head, field, next) \
217 for ((var) = ((head)->sqh_first); \
218 (var) && ((next = ((var)->field.sqe_next)), 1); \
219 (var) = (next))
220
221#define QSIMPLEQ_CONCAT(head1, head2) do { \
222 if (!QSIMPLEQ_EMPTY((head2))) { \
223 *(head1)->sqh_last = (head2)->sqh_first; \
224 (head1)->sqh_last = (head2)->sqh_last; \
225 QSIMPLEQ_INIT((head2)); \
226 } \
227} while (/*CONSTCOND*/0)
228
229#define QSIMPLEQ_LAST(head, type, field) \
230 (QSIMPLEQ_EMPTY((head)) ? \
231 NULL : \
232 ((struct type *)(void *) \
233 ((char *)((head)->sqh_last) - offsetof(struct type, field))))
234
235/*
236 * Simple queue access methods.
237 */
238#define QSIMPLEQ_EMPTY(head) ((head)->sqh_first == NULL)
239#define QSIMPLEQ_FIRST(head) ((head)->sqh_first)
240#define QSIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
241
242
243/*
blueswir1fc56ef02008-12-14 08:53:17 +0000244 * Tail queue definitions.
245 */
Blue Swirl72cf2d42009-09-12 07:36:22 +0000246#define Q_TAILQ_HEAD(name, type, qual) \
blueswir1fc56ef02008-12-14 08:53:17 +0000247struct name { \
248 qual type *tqh_first; /* first element */ \
249 qual type *qual *tqh_last; /* addr of last next element */ \
250}
Blue Swirl72cf2d42009-09-12 07:36:22 +0000251#define QTAILQ_HEAD(name, type) Q_TAILQ_HEAD(name, struct type,)
blueswir1fc56ef02008-12-14 08:53:17 +0000252
Blue Swirl72cf2d42009-09-12 07:36:22 +0000253#define QTAILQ_HEAD_INITIALIZER(head) \
blueswir1fc56ef02008-12-14 08:53:17 +0000254 { NULL, &(head).tqh_first }
255
Blue Swirl72cf2d42009-09-12 07:36:22 +0000256#define Q_TAILQ_ENTRY(type, qual) \
blueswir1fc56ef02008-12-14 08:53:17 +0000257struct { \
258 qual type *tqe_next; /* next element */ \
259 qual type *qual *tqe_prev; /* address of previous next element */\
260}
Blue Swirl72cf2d42009-09-12 07:36:22 +0000261#define QTAILQ_ENTRY(type) Q_TAILQ_ENTRY(struct type,)
blueswir1fc56ef02008-12-14 08:53:17 +0000262
263/*
264 * Tail queue functions.
265 */
Blue Swirl72cf2d42009-09-12 07:36:22 +0000266#define QTAILQ_INIT(head) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000267 (head)->tqh_first = NULL; \
268 (head)->tqh_last = &(head)->tqh_first; \
269} while (/*CONSTCOND*/0)
270
Blue Swirl72cf2d42009-09-12 07:36:22 +0000271#define QTAILQ_INSERT_HEAD(head, elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000272 if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
273 (head)->tqh_first->field.tqe_prev = \
274 &(elm)->field.tqe_next; \
275 else \
276 (head)->tqh_last = &(elm)->field.tqe_next; \
277 (head)->tqh_first = (elm); \
278 (elm)->field.tqe_prev = &(head)->tqh_first; \
279} while (/*CONSTCOND*/0)
280
Blue Swirl72cf2d42009-09-12 07:36:22 +0000281#define QTAILQ_INSERT_TAIL(head, elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000282 (elm)->field.tqe_next = NULL; \
283 (elm)->field.tqe_prev = (head)->tqh_last; \
284 *(head)->tqh_last = (elm); \
285 (head)->tqh_last = &(elm)->field.tqe_next; \
286} while (/*CONSTCOND*/0)
287
Blue Swirl72cf2d42009-09-12 07:36:22 +0000288#define QTAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000289 if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
290 (elm)->field.tqe_next->field.tqe_prev = \
291 &(elm)->field.tqe_next; \
292 else \
293 (head)->tqh_last = &(elm)->field.tqe_next; \
294 (listelm)->field.tqe_next = (elm); \
295 (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
296} while (/*CONSTCOND*/0)
297
Blue Swirl72cf2d42009-09-12 07:36:22 +0000298#define QTAILQ_INSERT_BEFORE(listelm, elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000299 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
300 (elm)->field.tqe_next = (listelm); \
301 *(listelm)->field.tqe_prev = (elm); \
302 (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
303} while (/*CONSTCOND*/0)
304
Blue Swirl72cf2d42009-09-12 07:36:22 +0000305#define QTAILQ_REMOVE(head, elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000306 if (((elm)->field.tqe_next) != NULL) \
307 (elm)->field.tqe_next->field.tqe_prev = \
308 (elm)->field.tqe_prev; \
309 else \
310 (head)->tqh_last = (elm)->field.tqe_prev; \
311 *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
312} while (/*CONSTCOND*/0)
313
Blue Swirl72cf2d42009-09-12 07:36:22 +0000314#define QTAILQ_FOREACH(var, head, field) \
blueswir1fc56ef02008-12-14 08:53:17 +0000315 for ((var) = ((head)->tqh_first); \
316 (var); \
317 (var) = ((var)->field.tqe_next))
318
Blue Swirl72cf2d42009-09-12 07:36:22 +0000319#define QTAILQ_FOREACH_SAFE(var, head, field, next_var) \
blueswir1fc56ef02008-12-14 08:53:17 +0000320 for ((var) = ((head)->tqh_first); \
321 (var) && ((next_var) = ((var)->field.tqe_next), 1); \
322 (var) = (next_var))
323
Blue Swirl72cf2d42009-09-12 07:36:22 +0000324#define QTAILQ_FOREACH_REVERSE(var, head, headname, field) \
blueswir1fc56ef02008-12-14 08:53:17 +0000325 for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \
326 (var); \
327 (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
328
329/*
330 * Tail queue access methods.
331 */
Blue Swirl72cf2d42009-09-12 07:36:22 +0000332#define QTAILQ_EMPTY(head) ((head)->tqh_first == NULL)
333#define QTAILQ_FIRST(head) ((head)->tqh_first)
334#define QTAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
blueswir1fc56ef02008-12-14 08:53:17 +0000335
Blue Swirl72cf2d42009-09-12 07:36:22 +0000336#define QTAILQ_LAST(head, headname) \
blueswir1fc56ef02008-12-14 08:53:17 +0000337 (*(((struct headname *)((head)->tqh_last))->tqh_last))
Blue Swirl72cf2d42009-09-12 07:36:22 +0000338#define QTAILQ_PREV(elm, headname, field) \
blueswir1fc56ef02008-12-14 08:53:17 +0000339 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
340
341
342/*
343 * Circular queue definitions.
344 */
Blue Swirl72cf2d42009-09-12 07:36:22 +0000345#define QCIRCLEQ_HEAD(name, type) \
blueswir1fc56ef02008-12-14 08:53:17 +0000346struct name { \
347 struct type *cqh_first; /* first element */ \
348 struct type *cqh_last; /* last element */ \
349}
350
Blue Swirl72cf2d42009-09-12 07:36:22 +0000351#define QCIRCLEQ_HEAD_INITIALIZER(head) \
blueswir1fc56ef02008-12-14 08:53:17 +0000352 { (void *)&head, (void *)&head }
353
Blue Swirl72cf2d42009-09-12 07:36:22 +0000354#define QCIRCLEQ_ENTRY(type) \
blueswir1fc56ef02008-12-14 08:53:17 +0000355struct { \
356 struct type *cqe_next; /* next element */ \
357 struct type *cqe_prev; /* previous element */ \
358}
359
360/*
361 * Circular queue functions.
362 */
Blue Swirl72cf2d42009-09-12 07:36:22 +0000363#define QCIRCLEQ_INIT(head) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000364 (head)->cqh_first = (void *)(head); \
365 (head)->cqh_last = (void *)(head); \
366} while (/*CONSTCOND*/0)
367
Blue Swirl72cf2d42009-09-12 07:36:22 +0000368#define QCIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000369 (elm)->field.cqe_next = (listelm)->field.cqe_next; \
370 (elm)->field.cqe_prev = (listelm); \
371 if ((listelm)->field.cqe_next == (void *)(head)) \
372 (head)->cqh_last = (elm); \
373 else \
374 (listelm)->field.cqe_next->field.cqe_prev = (elm); \
375 (listelm)->field.cqe_next = (elm); \
376} while (/*CONSTCOND*/0)
377
Blue Swirl72cf2d42009-09-12 07:36:22 +0000378#define QCIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000379 (elm)->field.cqe_next = (listelm); \
380 (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
381 if ((listelm)->field.cqe_prev == (void *)(head)) \
382 (head)->cqh_first = (elm); \
383 else \
384 (listelm)->field.cqe_prev->field.cqe_next = (elm); \
385 (listelm)->field.cqe_prev = (elm); \
386} while (/*CONSTCOND*/0)
387
Blue Swirl72cf2d42009-09-12 07:36:22 +0000388#define QCIRCLEQ_INSERT_HEAD(head, elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000389 (elm)->field.cqe_next = (head)->cqh_first; \
390 (elm)->field.cqe_prev = (void *)(head); \
391 if ((head)->cqh_last == (void *)(head)) \
392 (head)->cqh_last = (elm); \
393 else \
394 (head)->cqh_first->field.cqe_prev = (elm); \
395 (head)->cqh_first = (elm); \
396} while (/*CONSTCOND*/0)
397
Blue Swirl72cf2d42009-09-12 07:36:22 +0000398#define QCIRCLEQ_INSERT_TAIL(head, elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000399 (elm)->field.cqe_next = (void *)(head); \
400 (elm)->field.cqe_prev = (head)->cqh_last; \
401 if ((head)->cqh_first == (void *)(head)) \
402 (head)->cqh_first = (elm); \
403 else \
404 (head)->cqh_last->field.cqe_next = (elm); \
405 (head)->cqh_last = (elm); \
406} while (/*CONSTCOND*/0)
407
Blue Swirl72cf2d42009-09-12 07:36:22 +0000408#define QCIRCLEQ_REMOVE(head, elm, field) do { \
blueswir1fc56ef02008-12-14 08:53:17 +0000409 if ((elm)->field.cqe_next == (void *)(head)) \
410 (head)->cqh_last = (elm)->field.cqe_prev; \
411 else \
412 (elm)->field.cqe_next->field.cqe_prev = \
413 (elm)->field.cqe_prev; \
414 if ((elm)->field.cqe_prev == (void *)(head)) \
415 (head)->cqh_first = (elm)->field.cqe_next; \
416 else \
417 (elm)->field.cqe_prev->field.cqe_next = \
418 (elm)->field.cqe_next; \
419} while (/*CONSTCOND*/0)
420
Blue Swirl72cf2d42009-09-12 07:36:22 +0000421#define QCIRCLEQ_FOREACH(var, head, field) \
blueswir1fc56ef02008-12-14 08:53:17 +0000422 for ((var) = ((head)->cqh_first); \
423 (var) != (const void *)(head); \
424 (var) = ((var)->field.cqe_next))
425
Blue Swirl72cf2d42009-09-12 07:36:22 +0000426#define QCIRCLEQ_FOREACH_REVERSE(var, head, field) \
blueswir1fc56ef02008-12-14 08:53:17 +0000427 for ((var) = ((head)->cqh_last); \
428 (var) != (const void *)(head); \
429 (var) = ((var)->field.cqe_prev))
430
431/*
432 * Circular queue access methods.
433 */
Blue Swirl72cf2d42009-09-12 07:36:22 +0000434#define QCIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
435#define QCIRCLEQ_FIRST(head) ((head)->cqh_first)
436#define QCIRCLEQ_LAST(head) ((head)->cqh_last)
437#define QCIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
438#define QCIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
blueswir1fc56ef02008-12-14 08:53:17 +0000439
Blue Swirl72cf2d42009-09-12 07:36:22 +0000440#define QCIRCLEQ_LOOP_NEXT(head, elm, field) \
blueswir1fc56ef02008-12-14 08:53:17 +0000441 (((elm)->field.cqe_next == (void *)(head)) \
442 ? ((head)->cqh_first) \
443 : (elm->field.cqe_next))
Blue Swirl72cf2d42009-09-12 07:36:22 +0000444#define QCIRCLEQ_LOOP_PREV(head, elm, field) \
blueswir1fc56ef02008-12-14 08:53:17 +0000445 (((elm)->field.cqe_prev == (void *)(head)) \
446 ? ((head)->cqh_last) \
447 : (elm->field.cqe_prev))
448
Blue Swirl72cf2d42009-09-12 07:36:22 +0000449#endif /* !QEMU_SYS_QUEUE_H_ */