Statistics
| Branch: | Revision:

root / sys-queue.h @ 41db4607

History | View | Annotate | Download (16.8 kB)

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