make includes fix from trunk
[minix.git] / include / sys / queue.h
blob6757e2eb7cc1ddfd892bae63e67e9e560431dbfc
1 /*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
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.
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.
29 * @(#)queue.h 8.5 (Berkeley) 8/20/94
30 * $FreeBSD$
33 #ifndef _SYS_QUEUE_H_
34 #define _SYS_QUEUE_H_
36 /* Minix doesn't have this file.
37 #include <sys/cdefs.h>
40 /* Minix does needs this declaration from sys/cdefs.h though. */
41 #define __offsetof(type, field) ((size_t)(&((type *)0)->field))
44 * This file defines four types of data structures: singly-linked lists,
45 * singly-linked tail queues, lists and tail queues.
47 * A singly-linked list is headed by a single forward pointer. The elements
48 * are singly linked for minimum space and pointer manipulation overhead at
49 * the expense of O(n) removal for arbitrary elements. New elements can be
50 * added to the list after an existing element or at the head of the list.
51 * Elements being removed from the head of the list should use the explicit
52 * macro for this purpose for optimum efficiency. A singly-linked list may
53 * only be traversed in the forward direction. Singly-linked lists are ideal
54 * for applications with large datasets and few or no removals or for
55 * implementing a LIFO queue.
57 * A singly-linked tail queue is headed by a pair of pointers, one to the
58 * head of the list and the other to the tail of the list. The elements are
59 * singly linked for minimum space and pointer manipulation overhead at the
60 * expense of O(n) removal for arbitrary elements. New elements can be added
61 * to the list after an existing element, at the head of the list, or at the
62 * end of the list. Elements being removed from the head of the tail queue
63 * should use the explicit macro for this purpose for optimum efficiency.
64 * A singly-linked tail queue may only be traversed in the forward direction.
65 * Singly-linked tail queues are ideal for applications with large datasets
66 * and few or no removals or for implementing a FIFO queue.
68 * A list is headed by a single forward pointer (or an array of forward
69 * pointers for a hash table header). The elements are doubly linked
70 * 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
72 * or after an existing element or at the head of the list. A list
73 * may only be traversed in the forward direction.
75 * A tail queue is headed by a pair of pointers, one to the head of the
76 * list and the other to the tail of the list. The elements are doubly
77 * linked so that an arbitrary element can be removed without a need to
78 * traverse the list. New elements can be added to the list before or
79 * after an existing element, at the head of the list, or at the end of
80 * the list. A tail queue may be traversed in either direction.
82 * For details on the use of these macros, see the queue(3) manual page.
85 * SLIST LIST STAILQ TAILQ
86 * _HEAD + + + +
87 * _HEAD_INITIALIZER + + + +
88 * _ENTRY + + + +
89 * _INIT + + + +
90 * _EMPTY + + + +
91 * _FIRST + + + +
92 * _NEXT + + + +
93 * _PREV - - - +
94 * _LAST - - + +
95 * _FOREACH + + + +
96 * _FOREACH_SAFE + + + +
97 * _FOREACH_REVERSE - - - +
98 * _FOREACH_REVERSE_SAFE - - - +
99 * _INSERT_HEAD + + + +
100 * _INSERT_BEFORE - + - +
101 * _INSERT_AFTER + + + +
102 * _INSERT_TAIL - - + +
103 * _CONCAT - - + +
104 * _REMOVE_HEAD + - + -
105 * _REMOVE_NEXT + - + -
106 * _REMOVE + + + +
109 #ifdef QUEUE_MACRO_DEBUG
110 /* Store the last 2 places the queue element or head was altered */
111 struct qm_trace {
112 char * lastfile;
113 int lastline;
114 char * prevfile;
115 int prevline;
118 #define TRACEBUF struct qm_trace trace;
119 #define TRASHIT(x) do {(x) = (void *)-1;} while (0)
121 #define QMD_TRACE_HEAD(head) do { \
122 (head)->trace.prevline = (head)->trace.lastline; \
123 (head)->trace.prevfile = (head)->trace.lastfile; \
124 (head)->trace.lastline = __LINE__; \
125 (head)->trace.lastfile = __FILE__; \
126 } while (0)
128 #define QMD_TRACE_ELEM(elem) do { \
129 (elem)->trace.prevline = (elem)->trace.lastline; \
130 (elem)->trace.prevfile = (elem)->trace.lastfile; \
131 (elem)->trace.lastline = __LINE__; \
132 (elem)->trace.lastfile = __FILE__; \
133 } while (0)
135 #else
136 #define QMD_TRACE_ELEM(elem)
137 #define QMD_TRACE_HEAD(head)
138 #define TRACEBUF
139 #define TRASHIT(x)
140 #endif /* QUEUE_MACRO_DEBUG */
143 * Singly-linked List declarations.
145 #define SLIST_HEAD(name, type) \
146 struct name { \
147 struct type *slh_first; /* first element */ \
150 #define SLIST_HEAD_INITIALIZER(head) \
151 { NULL }
153 #define SLIST_ENTRY(type) \
154 struct { \
155 struct type *sle_next; /* next element */ \
159 * Singly-linked List functions.
161 #define SLIST_EMPTY(head) ((head)->slh_first == NULL)
163 #define SLIST_FIRST(head) ((head)->slh_first)
165 #define SLIST_FOREACH(var, head, field) \
166 for ((var) = SLIST_FIRST((head)); \
167 (var); \
168 (var) = SLIST_NEXT((var), field))
170 #define SLIST_FOREACH_SAFE(var, head, field, tvar) \
171 for ((var) = SLIST_FIRST((head)); \
172 (var) && ((tvar) = SLIST_NEXT((var), field), 1); \
173 (var) = (tvar))
175 #define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
176 for ((varp) = &SLIST_FIRST((head)); \
177 ((var) = *(varp)) != NULL; \
178 (varp) = &SLIST_NEXT((var), field))
180 #define SLIST_INIT(head) do { \
181 SLIST_FIRST((head)) = NULL; \
182 } while (0)
184 #define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
185 SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \
186 SLIST_NEXT((slistelm), field) = (elm); \
187 } while (0)
189 #define SLIST_INSERT_HEAD(head, elm, field) do { \
190 SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \
191 SLIST_FIRST((head)) = (elm); \
192 } while (0)
194 #define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
196 #define SLIST_REMOVE(head, elm, type, field) do { \
197 if (SLIST_FIRST((head)) == (elm)) { \
198 SLIST_REMOVE_HEAD((head), field); \
200 else { \
201 struct type *curelm = SLIST_FIRST((head)); \
202 while (SLIST_NEXT(curelm, field) != (elm)) \
203 curelm = SLIST_NEXT(curelm, field); \
204 SLIST_REMOVE_NEXT(head, curelm, field); \
206 TRASHIT((elm)->field.sle_next); \
207 } while (0)
209 #define SLIST_REMOVE_NEXT(head, elm, field) do { \
210 SLIST_NEXT(elm, field) = \
211 SLIST_NEXT(SLIST_NEXT(elm, field), field); \
212 } while (0)
214 #define SLIST_REMOVE_HEAD(head, field) do { \
215 SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
216 } while (0)
219 * Singly-linked Tail queue declarations.
221 #define STAILQ_HEAD(name, type) \
222 struct name { \
223 struct type *stqh_first;/* first element */ \
224 struct type **stqh_last;/* addr of last next element */ \
227 #define STAILQ_HEAD_INITIALIZER(head) \
228 { NULL, &(head).stqh_first }
230 #define STAILQ_ENTRY(type) \
231 struct { \
232 struct type *stqe_next; /* next element */ \
236 * Singly-linked Tail queue functions.
238 #define STAILQ_CONCAT(head1, head2) do { \
239 if (!STAILQ_EMPTY((head2))) { \
240 *(head1)->stqh_last = (head2)->stqh_first; \
241 (head1)->stqh_last = (head2)->stqh_last; \
242 STAILQ_INIT((head2)); \
244 } while (0)
246 #define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
248 #define STAILQ_FIRST(head) ((head)->stqh_first)
250 #define STAILQ_FOREACH(var, head, field) \
251 for((var) = STAILQ_FIRST((head)); \
252 (var); \
253 (var) = STAILQ_NEXT((var), field))
256 #define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
257 for ((var) = STAILQ_FIRST((head)); \
258 (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
259 (var) = (tvar))
261 #define STAILQ_INIT(head) do { \
262 STAILQ_FIRST((head)) = NULL; \
263 (head)->stqh_last = &STAILQ_FIRST((head)); \
264 } while (0)
266 #define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \
267 if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
268 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
269 STAILQ_NEXT((tqelm), field) = (elm); \
270 } while (0)
272 #define STAILQ_INSERT_HEAD(head, elm, field) do { \
273 if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
274 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
275 STAILQ_FIRST((head)) = (elm); \
276 } while (0)
278 #define STAILQ_INSERT_TAIL(head, elm, field) do { \
279 STAILQ_NEXT((elm), field) = NULL; \
280 *(head)->stqh_last = (elm); \
281 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
282 } while (0)
284 #define STAILQ_LAST(head, type, field) \
285 (STAILQ_EMPTY((head)) ? \
286 NULL : \
287 ((struct type *)(void *) \
288 ((char *)((head)->stqh_last) - __offsetof(struct type, field))))
290 #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
292 #define STAILQ_REMOVE(head, elm, type, field) do { \
293 if (STAILQ_FIRST((head)) == (elm)) { \
294 STAILQ_REMOVE_HEAD((head), field); \
296 else { \
297 struct type *curelm = STAILQ_FIRST((head)); \
298 while (STAILQ_NEXT(curelm, field) != (elm)) \
299 curelm = STAILQ_NEXT(curelm, field); \
300 STAILQ_REMOVE_NEXT(head, curelm, field); \
302 TRASHIT((elm)->field.stqe_next); \
303 } while (0)
305 #define STAILQ_REMOVE_HEAD(head, field) do { \
306 if ((STAILQ_FIRST((head)) = \
307 STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \
308 (head)->stqh_last = &STAILQ_FIRST((head)); \
309 } while (0)
311 #define STAILQ_REMOVE_NEXT(head, elm, field) do { \
312 if ((STAILQ_NEXT(elm, field) = \
313 STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \
314 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
315 } while (0)
318 * List declarations.
320 #define LIST_HEAD(name, type) \
321 struct name { \
322 struct type *lh_first; /* first element */ \
325 #define LIST_HEAD_INITIALIZER(head) \
326 { NULL }
328 #define LIST_ENTRY(type) \
329 struct { \
330 struct type *le_next; /* next element */ \
331 struct type **le_prev; /* address of previous next element */ \
335 * List functions.
338 #if (defined(_KERNEL) && defined(INVARIANTS))
339 #define QMD_LIST_CHECK_HEAD(head, field) do { \
340 if (LIST_FIRST((head)) != NULL && \
341 LIST_FIRST((head))->field.le_prev != \
342 &LIST_FIRST((head))) \
343 panic("Bad list head %p first->prev != head", (head)); \
344 } while (0)
346 #define QMD_LIST_CHECK_NEXT(elm, field) do { \
347 if (LIST_NEXT((elm), field) != NULL && \
348 LIST_NEXT((elm), field)->field.le_prev != \
349 &((elm)->field.le_next)) \
350 panic("Bad link elm %p next->prev != elm", (elm)); \
351 } while (0)
353 #define QMD_LIST_CHECK_PREV(elm, field) do { \
354 if (*(elm)->field.le_prev != (elm)) \
355 panic("Bad link elm %p prev->next != elm", (elm)); \
356 } while (0)
357 #else
358 #define QMD_LIST_CHECK_HEAD(head, field)
359 #define QMD_LIST_CHECK_NEXT(elm, field)
360 #define QMD_LIST_CHECK_PREV(elm, field)
361 #endif /* (_KERNEL && INVARIANTS) */
363 #define LIST_EMPTY(head) ((head)->lh_first == NULL)
365 #define LIST_FIRST(head) ((head)->lh_first)
367 #define LIST_FOREACH(var, head, field) \
368 for ((var) = LIST_FIRST((head)); \
369 (var); \
370 (var) = LIST_NEXT((var), field))
372 #define LIST_FOREACH_SAFE(var, head, field, tvar) \
373 for ((var) = LIST_FIRST((head)); \
374 (var) && ((tvar) = LIST_NEXT((var), field), 1); \
375 (var) = (tvar))
377 #define LIST_INIT(head) do { \
378 LIST_FIRST((head)) = NULL; \
379 } while (0)
381 #define LIST_INSERT_AFTER(listelm, elm, field) do { \
382 QMD_LIST_CHECK_NEXT(listelm, field); \
383 if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
384 LIST_NEXT((listelm), field)->field.le_prev = \
385 &LIST_NEXT((elm), field); \
386 LIST_NEXT((listelm), field) = (elm); \
387 (elm)->field.le_prev = &LIST_NEXT((listelm), field); \
388 } while (0)
390 #define LIST_INSERT_BEFORE(listelm, elm, field) do { \
391 QMD_LIST_CHECK_PREV(listelm, field); \
392 (elm)->field.le_prev = (listelm)->field.le_prev; \
393 LIST_NEXT((elm), field) = (listelm); \
394 *(listelm)->field.le_prev = (elm); \
395 (listelm)->field.le_prev = &LIST_NEXT((elm), field); \
396 } while (0)
398 #define LIST_INSERT_HEAD(head, elm, field) do { \
399 QMD_LIST_CHECK_HEAD((head), field); \
400 if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
401 LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
402 LIST_FIRST((head)) = (elm); \
403 (elm)->field.le_prev = &LIST_FIRST((head)); \
404 } while (0)
406 #define LIST_NEXT(elm, field) ((elm)->field.le_next)
408 #define LIST_REMOVE(elm, field) do { \
409 QMD_LIST_CHECK_NEXT(elm, field); \
410 QMD_LIST_CHECK_PREV(elm, field); \
411 if (LIST_NEXT((elm), field) != NULL) \
412 LIST_NEXT((elm), field)->field.le_prev = \
413 (elm)->field.le_prev; \
414 *(elm)->field.le_prev = LIST_NEXT((elm), field); \
415 TRASHIT((elm)->field.le_next); \
416 TRASHIT((elm)->field.le_prev); \
417 } while (0)
420 * Tail queue declarations.
422 #define TAILQ_HEAD(name, type) \
423 struct name { \
424 struct type *tqh_first; /* first element */ \
425 struct type **tqh_last; /* addr of last next element */ \
426 TRACEBUF \
429 #define TAILQ_HEAD_INITIALIZER(head) \
430 { NULL, &(head).tqh_first }
432 #define TAILQ_ENTRY(type) \
433 struct { \
434 struct type *tqe_next; /* next element */ \
435 struct type **tqe_prev; /* address of previous next element */ \
436 TRACEBUF \
440 * Tail queue functions.
442 #if (defined(_KERNEL) && defined(INVARIANTS))
443 #define QMD_TAILQ_CHECK_HEAD(head, field) do { \
444 if (!TAILQ_EMPTY(head) && \
445 TAILQ_FIRST((head))->field.tqe_prev != \
446 &TAILQ_FIRST((head))) \
447 panic("Bad tailq head %p first->prev != head", (head)); \
448 } while (0)
450 #define QMD_TAILQ_CHECK_TAIL(head, field) do { \
451 if (*(head)->tqh_last != NULL) \
452 panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \
453 } while (0)
455 #define QMD_TAILQ_CHECK_NEXT(elm, field) do { \
456 if (TAILQ_NEXT((elm), field) != NULL && \
457 TAILQ_NEXT((elm), field)->field.tqe_prev != \
458 &((elm)->field.tqe_next)) \
459 panic("Bad link elm %p next->prev != elm", (elm)); \
460 } while (0)
462 #define QMD_TAILQ_CHECK_PREV(elm, field) do { \
463 if (*(elm)->field.tqe_prev != (elm)) \
464 panic("Bad link elm %p prev->next != elm", (elm)); \
465 } while (0)
466 #else
467 #define QMD_TAILQ_CHECK_HEAD(head, field)
468 #define QMD_TAILQ_CHECK_TAIL(head, headname)
469 #define QMD_TAILQ_CHECK_NEXT(elm, field)
470 #define QMD_TAILQ_CHECK_PREV(elm, field)
471 #endif /* (_KERNEL && INVARIANTS) */
473 #define TAILQ_CONCAT(head1, head2, field) do { \
474 if (!TAILQ_EMPTY(head2)) { \
475 *(head1)->tqh_last = (head2)->tqh_first; \
476 (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
477 (head1)->tqh_last = (head2)->tqh_last; \
478 TAILQ_INIT((head2)); \
479 QMD_TRACE_HEAD(head1); \
480 QMD_TRACE_HEAD(head2); \
482 } while (0)
484 #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
486 #define TAILQ_FIRST(head) ((head)->tqh_first)
488 #define TAILQ_FOREACH(var, head, field) \
489 for ((var) = TAILQ_FIRST((head)); \
490 (var); \
491 (var) = TAILQ_NEXT((var), field))
493 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
494 for ((var) = TAILQ_FIRST((head)); \
495 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
496 (var) = (tvar))
498 #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
499 for ((var) = TAILQ_LAST((head), headname); \
500 (var); \
501 (var) = TAILQ_PREV((var), headname, field))
503 #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
504 for ((var) = TAILQ_LAST((head), headname); \
505 (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
506 (var) = (tvar))
508 #define TAILQ_INIT(head) do { \
509 TAILQ_FIRST((head)) = NULL; \
510 (head)->tqh_last = &TAILQ_FIRST((head)); \
511 QMD_TRACE_HEAD(head); \
512 } while (0)
514 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
515 QMD_TAILQ_CHECK_NEXT(listelm, field); \
516 if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
517 TAILQ_NEXT((elm), field)->field.tqe_prev = \
518 &TAILQ_NEXT((elm), field); \
519 else { \
520 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
521 QMD_TRACE_HEAD(head); \
523 TAILQ_NEXT((listelm), field) = (elm); \
524 (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
525 QMD_TRACE_ELEM(&(elm)->field); \
526 QMD_TRACE_ELEM(&listelm->field); \
527 } while (0)
529 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
530 QMD_TAILQ_CHECK_PREV(listelm, field); \
531 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
532 TAILQ_NEXT((elm), field) = (listelm); \
533 *(listelm)->field.tqe_prev = (elm); \
534 (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
535 QMD_TRACE_ELEM(&(elm)->field); \
536 QMD_TRACE_ELEM(&listelm->field); \
537 } while (0)
539 #define TAILQ_INSERT_HEAD(head, elm, field) do { \
540 QMD_TAILQ_CHECK_HEAD(head, field); \
541 if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
542 TAILQ_FIRST((head))->field.tqe_prev = \
543 &TAILQ_NEXT((elm), field); \
544 else \
545 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
546 TAILQ_FIRST((head)) = (elm); \
547 (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
548 QMD_TRACE_HEAD(head); \
549 QMD_TRACE_ELEM(&(elm)->field); \
550 } while (0)
552 #define TAILQ_INSERT_TAIL(head, elm, field) do { \
553 QMD_TAILQ_CHECK_TAIL(head, field); \
554 TAILQ_NEXT((elm), field) = NULL; \
555 (elm)->field.tqe_prev = (head)->tqh_last; \
556 *(head)->tqh_last = (elm); \
557 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
558 QMD_TRACE_HEAD(head); \
559 QMD_TRACE_ELEM(&(elm)->field); \
560 } while (0)
562 #define TAILQ_LAST(head, headname) \
563 (*(((struct headname *)((head)->tqh_last))->tqh_last))
565 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
567 #define TAILQ_PREV(elm, headname, field) \
568 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
570 #define TAILQ_REMOVE(head, elm, field) do { \
571 QMD_TAILQ_CHECK_NEXT(elm, field); \
572 QMD_TAILQ_CHECK_PREV(elm, field); \
573 if ((TAILQ_NEXT((elm), field)) != NULL) \
574 TAILQ_NEXT((elm), field)->field.tqe_prev = \
575 (elm)->field.tqe_prev; \
576 else { \
577 (head)->tqh_last = (elm)->field.tqe_prev; \
578 QMD_TRACE_HEAD(head); \
580 *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
581 TRASHIT((elm)->field.tqe_next); \
582 TRASHIT((elm)->field.tqe_prev); \
583 QMD_TRACE_ELEM(&(elm)->field); \
584 } while (0)
587 #ifdef _KERNEL
590 * XXX insque() and remque() are an old way of handling certain queues.
591 * They bogusly assumes that all queue heads look alike.
594 struct quehead {
595 struct quehead *qh_link;
596 struct quehead *qh_rlink;
599 #ifdef __CC_SUPPORTS___INLINE
601 static __inline void
602 insque(void *a, void *b)
604 struct quehead *element = (struct quehead *)a,
605 *head = (struct quehead *)b;
607 element->qh_link = head->qh_link;
608 element->qh_rlink = head;
609 head->qh_link = element;
610 element->qh_link->qh_rlink = element;
613 static __inline void
614 remque(void *a)
616 struct quehead *element = (struct quehead *)a;
618 element->qh_link->qh_rlink = element->qh_rlink;
619 element->qh_rlink->qh_link = element->qh_link;
620 element->qh_rlink = 0;
623 #else /* !__CC_SUPPORTS___INLINE */
625 void insque(void *a, void *b);
626 void remque(void *a);
628 #endif /* __CC_SUPPORTS___INLINE */
630 #endif /* _KERNEL */
632 #endif /* !_SYS_QUEUE_H_ */