linprocfs - Introduce /proc/mounts
[dragonfly.git] / sys / sys / queue.h
blobc7171fe479b74513647749c112b7c94b7921f2d6
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: src/sys/sys/queue.h,v 1.69 2008/05/22 14:40:03 ed Exp $
31 * $DragonFly: src/sys/sys/queue.h,v 1.11 2008/08/28 08:42:29 hasso Exp $
34 #ifndef _SYS_QUEUE_H_
35 #define _SYS_QUEUE_H_
37 #include <sys/cdefs.h>
40 * This file defines four types of data structures: singly-linked lists,
41 * singly-linked tail queues, lists and tail queues.
43 * A singly-linked list is headed by a single forward pointer. The elements
44 * are singly linked for minimum space and pointer manipulation overhead at
45 * the expense of O(n) removal for arbitrary elements. New elements can be
46 * added to the list after an existing element or at the head of the list.
47 * Elements being removed from the head of the list should use the explicit
48 * macro for this purpose for optimum efficiency. A singly-linked list may
49 * only be traversed in the forward direction. Singly-linked lists are ideal
50 * for applications with large datasets and few or no removals or for
51 * implementing a LIFO queue.
53 * A singly-linked tail queue is headed by a pair of pointers, one to the
54 * head of the list and the other to the tail of the list. The elements are
55 * singly linked for minimum space and pointer manipulation overhead at the
56 * expense of O(n) removal for arbitrary elements. New elements can be added
57 * to the list after an existing element, at the head of the list, or at the
58 * end of the list. Elements being removed from the head of the tail queue
59 * should use the explicit macro for this purpose for optimum efficiency.
60 * A singly-linked tail queue may only be traversed in the forward direction.
61 * Singly-linked tail queues are ideal for applications with large datasets
62 * and few or no removals or for implementing a FIFO queue.
64 * A list is headed by a single forward pointer (or an array of forward
65 * pointers for a hash table header). The elements are doubly linked
66 * so that an arbitrary element can be removed without a need to
67 * traverse the list. New elements can be added to the list before
68 * or after an existing element or at the head of the list. A list
69 * may only be traversed in the forward direction.
71 * A tail queue is headed by a pair of pointers, one to the head of the
72 * list and the other to the tail of the list. The elements are doubly
73 * linked so that an arbitrary element can be removed without a need to
74 * traverse the list. New elements can be added to the list before or
75 * after an existing element, at the head of the list, or at the end of
76 * the list. A tail queue may be traversed in either direction.
78 * For details on the use of these macros, see the queue(3) manual page.
81 * SLIST LIST STAILQ TAILQ
82 * _HEAD + + + +
83 * _HEAD_INITIALIZER + + + +
84 * _ENTRY + + + +
85 * _INIT + + + +
86 * _EMPTY + + + +
87 * _FIRST + + + +
88 * _NEXT + + + +
89 * _PREV - - - +
90 * _LAST - - + +
91 * _FOREACH + + + +
92 * _FOREACH_MUTABLE + + + +
93 * _FOREACH_REVERSE - - - +
94 * _FOREACH_REVERSE_MUTABLE - - - +
95 * _INSERT_HEAD + + + +
96 * _INSERT_BEFORE - + - +
97 * _INSERT_AFTER + + + +
98 * _INSERT_TAIL - - + +
99 * _CONCAT - - + +
100 * _REMOVE_HEAD + - + -
101 * _REMOVE_NEXT + - + -
102 * _REMOVE + + + +
105 #ifdef QUEUE_MACRO_DEBUG
106 /* Store the last 2 places the queue element or head was altered */
107 struct qm_trace {
108 char *lastfile;
109 int lastline;
110 char *prevfile;
111 int prevline;
114 #define TRACEBUF struct qm_trace trace;
115 #define TRASHIT(x) do {(x) = (void *)-1;} while (0)
117 #define QMD_TRACE_HEAD(head) do { \
118 (head)->trace.prevline = (head)->trace.lastline; \
119 (head)->trace.prevfile = (head)->trace.lastfile; \
120 (head)->trace.lastline = __LINE__; \
121 (head)->trace.lastfile = __FILE__; \
122 } while (0)
124 #define QMD_TRACE_ELEM(elem) do { \
125 (elem)->trace.prevline = (elem)->trace.lastline; \
126 (elem)->trace.prevfile = (elem)->trace.lastfile; \
127 (elem)->trace.lastline = __LINE__; \
128 (elem)->trace.lastfile = __FILE__; \
129 } while (0)
131 #else
132 #define QMD_TRACE_ELEM(elem)
133 #define QMD_TRACE_HEAD(head)
134 #define TRACEBUF
135 #define TRASHIT(x)
136 #endif /* QUEUE_MACRO_DEBUG */
139 * Singly-linked List declarations.
141 #define SLIST_HEAD(name, type) \
142 struct name { \
143 struct type *slh_first; /* first element */ \
146 #define SLIST_HEAD_INITIALIZER(head) \
147 { NULL }
149 #define SLIST_ENTRY(type) \
150 struct { \
151 struct type *sle_next; /* next element */ \
154 #define SLIST_ENTRY_INITIALIZER { NULL }
157 * Singly-linked List functions.
159 #define SLIST_EMPTY(head) ((head)->slh_first == NULL)
161 #define SLIST_FIRST(head) ((head)->slh_first)
163 #define SLIST_FOREACH(var, head, field) \
164 for ((var) = SLIST_FIRST((head)); \
165 (var); \
166 (var) = SLIST_NEXT((var), field))
168 #define SLIST_FOREACH_MUTABLE(var, head, field, tvar) \
169 for ((var) = SLIST_FIRST((head)); \
170 (var) && ((tvar) = SLIST_NEXT((var), field), 1); \
171 (var) = (tvar))
173 #define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
174 for ((varp) = &SLIST_FIRST((head)); \
175 ((var) = *(varp)) != NULL; \
176 (varp) = &SLIST_NEXT((var), field))
178 #define SLIST_INIT(head) do { \
179 SLIST_FIRST((head)) = NULL; \
180 } while (0)
182 #define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
183 SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \
184 SLIST_NEXT((slistelm), field) = (elm); \
185 } while (0)
187 #define SLIST_INSERT_HEAD(head, elm, field) do { \
188 SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \
189 SLIST_FIRST((head)) = (elm); \
190 } while (0)
192 #define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
194 #define SLIST_REMOVE(head, elm, type, field) do { \
195 if (SLIST_FIRST((head)) == (elm)) { \
196 SLIST_REMOVE_HEAD((head), field); \
198 else { \
199 struct type *curelm = SLIST_FIRST((head)); \
200 while (SLIST_NEXT(curelm, field) != (elm)) \
201 curelm = SLIST_NEXT(curelm, field); \
202 SLIST_REMOVE_NEXT(head, curelm, field); \
204 TRASHIT((elm)->field.sle_next); \
205 } while (0)
207 #define SLIST_REMOVE_NEXT(head, elm, field) do { \
208 SLIST_NEXT(elm, field) = \
209 SLIST_NEXT(SLIST_NEXT(elm, field), field); \
210 } while (0)
212 #define SLIST_REMOVE_HEAD(head, field) do { \
213 SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
214 } while (0)
217 * Singly-linked Tail queue declarations.
219 #define STAILQ_HEAD(name, type) \
220 struct name { \
221 struct type *stqh_first;/* first element */ \
222 struct type **stqh_last;/* addr of last next element */ \
225 #define STAILQ_HEAD_INITIALIZER(head) \
226 { NULL, &(head).stqh_first }
228 #define STAILQ_ENTRY(type) \
229 struct { \
230 struct type *stqe_next; /* next element */ \
234 * Singly-linked Tail queue functions.
236 #define STAILQ_CONCAT(head1, head2) do { \
237 if (!STAILQ_EMPTY((head2))) { \
238 *(head1)->stqh_last = (head2)->stqh_first; \
239 (head1)->stqh_last = (head2)->stqh_last; \
240 STAILQ_INIT((head2)); \
242 } while (0)
244 #define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
246 #define STAILQ_FIRST(head) ((head)->stqh_first)
248 #define STAILQ_FOREACH(var, head, field) \
249 for((var) = STAILQ_FIRST((head)); \
250 (var); \
251 (var) = STAILQ_NEXT((var), field))
254 #define STAILQ_FOREACH_MUTABLE(var, head, field, tvar) \
255 for ((var) = STAILQ_FIRST((head)); \
256 (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
257 (var) = (tvar))
259 #define STAILQ_INIT(head) do { \
260 STAILQ_FIRST((head)) = NULL; \
261 (head)->stqh_last = &STAILQ_FIRST((head)); \
262 } while (0)
264 #define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \
265 if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
266 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
267 STAILQ_NEXT((tqelm), field) = (elm); \
268 } while (0)
270 #define STAILQ_INSERT_HEAD(head, elm, field) do { \
271 if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
272 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
273 STAILQ_FIRST((head)) = (elm); \
274 } while (0)
276 #define STAILQ_INSERT_TAIL(head, elm, field) do { \
277 STAILQ_NEXT((elm), field) = NULL; \
278 *(head)->stqh_last = (elm); \
279 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
280 } while (0)
282 #define STAILQ_LAST(head, type, field) \
283 (STAILQ_EMPTY((head)) ? \
284 NULL : \
285 ((struct type *)(void *) \
286 ((char *)((head)->stqh_last) - __offsetof(struct type, field))))
288 #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
290 #define STAILQ_REMOVE(head, elm, type, field) do { \
291 if (STAILQ_FIRST((head)) == (elm)) { \
292 STAILQ_REMOVE_HEAD((head), field); \
294 else { \
295 struct type *curelm = STAILQ_FIRST((head)); \
296 while (STAILQ_NEXT(curelm, field) != (elm)) \
297 curelm = STAILQ_NEXT(curelm, field); \
298 STAILQ_REMOVE_NEXT(head, curelm, field); \
300 TRASHIT((elm)->field.stqe_next); \
301 } while (0)
303 #define STAILQ_REMOVE_HEAD(head, field) do { \
304 if ((STAILQ_FIRST((head)) = \
305 STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \
306 (head)->stqh_last = &STAILQ_FIRST((head)); \
307 } while (0)
309 #define STAILQ_REMOVE_NEXT(head, elm, field) do { \
310 if ((STAILQ_NEXT(elm, field) = \
311 STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \
312 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
313 } while (0)
316 * List declarations.
318 #define LIST_HEAD(name, type) \
319 struct name { \
320 struct type *lh_first; /* first element */ \
323 #define LIST_HEAD_INITIALIZER(head) \
324 { NULL }
326 #define LIST_ENTRY(type) \
327 struct { \
328 struct type *le_next; /* next element */ \
329 struct type **le_prev; /* address of previous next element */ \
333 * List functions.
336 #if (defined(_KERNEL) && defined(INVARIANTS))
337 #define QMD_LIST_CHECK_HEAD(head, field) do { \
338 if (LIST_FIRST((head)) != NULL && \
339 LIST_FIRST((head))->field.le_prev != \
340 &LIST_FIRST((head))) \
341 panic("Bad list head %p first->prev != head", (head)); \
342 } while (0)
344 #define QMD_LIST_CHECK_NEXT(elm, field) do { \
345 if (LIST_NEXT((elm), field) != NULL && \
346 LIST_NEXT((elm), field)->field.le_prev != \
347 &((elm)->field.le_next)) \
348 panic("Bad link elm %p next->prev != elm", (elm)); \
349 } while (0)
351 #define QMD_LIST_CHECK_PREV(elm, field) do { \
352 if (*(elm)->field.le_prev != (elm)) \
353 panic("Bad link elm %p prev->next != elm", (elm)); \
354 } while (0)
355 #else
356 #define QMD_LIST_CHECK_HEAD(head, field)
357 #define QMD_LIST_CHECK_NEXT(elm, field)
358 #define QMD_LIST_CHECK_PREV(elm, field)
359 #endif /* (_KERNEL && INVARIANTS) */
361 #define LIST_EMPTY(head) ((head)->lh_first == NULL)
363 #define LIST_FIRST(head) ((head)->lh_first)
365 #define LIST_FOREACH(var, head, field) \
366 for ((var) = LIST_FIRST((head)); \
367 (var); \
368 (var) = LIST_NEXT((var), field))
370 #define LIST_FOREACH_MUTABLE(var, head, field, tvar) \
371 for ((var) = LIST_FIRST((head)); \
372 (var) && ((tvar) = LIST_NEXT((var), field), 1); \
373 (var) = (tvar))
375 #define LIST_INIT(head) do { \
376 LIST_FIRST((head)) = NULL; \
377 } while (0)
379 #define LIST_INSERT_AFTER(listelm, elm, field) do { \
380 QMD_LIST_CHECK_NEXT(listelm, field); \
381 if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
382 LIST_NEXT((listelm), field)->field.le_prev = \
383 &LIST_NEXT((elm), field); \
384 LIST_NEXT((listelm), field) = (elm); \
385 (elm)->field.le_prev = &LIST_NEXT((listelm), field); \
386 } while (0)
388 #define LIST_INSERT_BEFORE(listelm, elm, field) do { \
389 QMD_LIST_CHECK_PREV(listelm, field); \
390 (elm)->field.le_prev = (listelm)->field.le_prev; \
391 LIST_NEXT((elm), field) = (listelm); \
392 *(listelm)->field.le_prev = (elm); \
393 (listelm)->field.le_prev = &LIST_NEXT((elm), field); \
394 } while (0)
396 #define LIST_INSERT_HEAD(head, elm, field) do { \
397 QMD_LIST_CHECK_HEAD((head), field); \
398 if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
399 LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
400 LIST_FIRST((head)) = (elm); \
401 (elm)->field.le_prev = &LIST_FIRST((head)); \
402 } while (0)
404 #define LIST_NEXT(elm, field) ((elm)->field.le_next)
406 #define LIST_REMOVE(elm, field) do { \
407 QMD_LIST_CHECK_NEXT(elm, field); \
408 QMD_LIST_CHECK_PREV(elm, field); \
409 if (LIST_NEXT((elm), field) != NULL) \
410 LIST_NEXT((elm), field)->field.le_prev = \
411 (elm)->field.le_prev; \
412 *(elm)->field.le_prev = LIST_NEXT((elm), field); \
413 TRASHIT((elm)->field.le_next); \
414 TRASHIT((elm)->field.le_prev); \
415 } while (0)
418 * Tail queue declarations.
420 #define TAILQ_HEAD(name, type) \
421 struct name { \
422 struct type *tqh_first; /* first element */ \
423 struct type **tqh_last; /* addr of last next element */ \
424 TRACEBUF \
427 #define TAILQ_HEAD_INITIALIZER(head) \
428 { NULL, &(head).tqh_first }
430 #define TAILQ_ENTRY(type) \
431 struct { \
432 struct type *tqe_next; /* next element */ \
433 struct type **tqe_prev; /* address of previous next element */ \
434 TRACEBUF \
438 * Tail queue functions.
440 #if (defined(_KERNEL) && defined(INVARIANTS))
441 #define QMD_TAILQ_CHECK_HEAD(head, field) do { \
442 if (!TAILQ_EMPTY(head) && \
443 TAILQ_FIRST((head))->field.tqe_prev != \
444 &TAILQ_FIRST((head))) \
445 panic("Bad tailq head %p first->prev != head", (head)); \
446 } while (0)
448 #define QMD_TAILQ_CHECK_TAIL(head, field) do { \
449 if (*(head)->tqh_last != NULL) \
450 panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \
451 } while (0)
453 #define QMD_TAILQ_CHECK_NEXT(elm, field) do { \
454 if (TAILQ_NEXT((elm), field) != NULL && \
455 TAILQ_NEXT((elm), field)->field.tqe_prev != \
456 &((elm)->field.tqe_next)) \
457 panic("Bad link elm %p next->prev != elm", (elm)); \
458 } while (0)
460 #define QMD_TAILQ_CHECK_PREV(elm, field) do { \
461 if (*(elm)->field.tqe_prev != (elm)) \
462 panic("Bad link elm %p prev->next != elm", (elm)); \
463 } while (0)
464 #else
465 #define QMD_TAILQ_CHECK_HEAD(head, field)
466 #define QMD_TAILQ_CHECK_TAIL(head, headname)
467 #define QMD_TAILQ_CHECK_NEXT(elm, field)
468 #define QMD_TAILQ_CHECK_PREV(elm, field)
469 #endif /* (_KERNEL && INVARIANTS) */
471 #define TAILQ_CONCAT(head1, head2, field) do { \
472 if (!TAILQ_EMPTY(head2)) { \
473 *(head1)->tqh_last = (head2)->tqh_first; \
474 (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
475 (head1)->tqh_last = (head2)->tqh_last; \
476 TAILQ_INIT((head2)); \
477 QMD_TRACE_HEAD(head1); \
478 QMD_TRACE_HEAD(head2); \
480 } while (0)
482 #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
484 #define TAILQ_FIRST(head) ((head)->tqh_first)
486 #define TAILQ_FOREACH(var, head, field) \
487 for ((var) = TAILQ_FIRST((head)); \
488 (var); \
489 (var) = TAILQ_NEXT((var), field))
491 #define TAILQ_FOREACH_MUTABLE(var, head, field, tvar) \
492 for ((var) = TAILQ_FIRST((head)); \
493 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
494 (var) = (tvar))
496 #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
497 for ((var) = TAILQ_LAST((head), headname); \
498 (var); \
499 (var) = TAILQ_PREV((var), headname, field))
501 #define TAILQ_FOREACH_REVERSE_MUTABLE(var, head, headname, field, tvar) \
502 for ((var) = TAILQ_LAST((head), headname); \
503 (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
504 (var) = (tvar))
506 #define TAILQ_INIT(head) do { \
507 TAILQ_FIRST((head)) = NULL; \
508 (head)->tqh_last = &TAILQ_FIRST((head)); \
509 QMD_TRACE_HEAD(head); \
510 } while (0)
512 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
513 QMD_TAILQ_CHECK_NEXT(listelm, field); \
514 if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
515 TAILQ_NEXT((elm), field)->field.tqe_prev = \
516 &TAILQ_NEXT((elm), field); \
517 else { \
518 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
519 QMD_TRACE_HEAD(head); \
521 TAILQ_NEXT((listelm), field) = (elm); \
522 (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
523 QMD_TRACE_ELEM(&(elm)->field); \
524 QMD_TRACE_ELEM(&listelm->field); \
525 } while (0)
527 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
528 QMD_TAILQ_CHECK_PREV(listelm, field); \
529 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
530 TAILQ_NEXT((elm), field) = (listelm); \
531 *(listelm)->field.tqe_prev = (elm); \
532 (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
533 QMD_TRACE_ELEM(&(elm)->field); \
534 QMD_TRACE_ELEM(&listelm->field); \
535 } while (0)
537 #define TAILQ_INSERT_HEAD(head, elm, field) do { \
538 QMD_TAILQ_CHECK_HEAD(head, field); \
539 if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
540 TAILQ_FIRST((head))->field.tqe_prev = \
541 &TAILQ_NEXT((elm), field); \
542 else \
543 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
544 TAILQ_FIRST((head)) = (elm); \
545 (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
546 QMD_TRACE_HEAD(head); \
547 QMD_TRACE_ELEM(&(elm)->field); \
548 } while (0)
550 #define TAILQ_INSERT_TAIL(head, elm, field) do { \
551 QMD_TAILQ_CHECK_TAIL(head, field); \
552 TAILQ_NEXT((elm), field) = NULL; \
553 (elm)->field.tqe_prev = (head)->tqh_last; \
554 *(head)->tqh_last = (elm); \
555 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
556 QMD_TRACE_HEAD(head); \
557 QMD_TRACE_ELEM(&(elm)->field); \
558 } while (0)
560 #define TAILQ_LAST(head, headname) \
561 (*(((struct headname *)((head)->tqh_last))->tqh_last))
563 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
565 #define TAILQ_PREV(elm, headname, field) \
566 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
568 #define TAILQ_REMOVE(head, elm, field) do { \
569 QMD_TAILQ_CHECK_NEXT(elm, field); \
570 QMD_TAILQ_CHECK_PREV(elm, field); \
571 if ((TAILQ_NEXT((elm), field)) != NULL) \
572 TAILQ_NEXT((elm), field)->field.tqe_prev = \
573 (elm)->field.tqe_prev; \
574 else { \
575 (head)->tqh_last = (elm)->field.tqe_prev; \
576 QMD_TRACE_HEAD(head); \
578 *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
579 TRASHIT((elm)->field.tqe_next); \
580 TRASHIT((elm)->field.tqe_prev); \
581 QMD_TRACE_ELEM(&(elm)->field); \
582 } while (0)
585 #ifdef _KERNEL
588 * XXX insque() and remque() are an old way of handling certain queues.
589 * They bogusly assumes that all queue heads look alike.
592 struct quehead {
593 struct quehead *qh_link;
594 struct quehead *qh_rlink;
597 #ifdef __GNUC__
599 static __inline void
600 insque(void *a, void *b)
602 struct quehead *element = (struct quehead *)a,
603 *head = (struct quehead *)b;
605 element->qh_link = head->qh_link;
606 element->qh_rlink = head;
607 head->qh_link = element;
608 element->qh_link->qh_rlink = element;
611 static __inline void
612 remque(void *a)
614 struct quehead *element = (struct quehead *)a;
616 element->qh_link->qh_rlink = element->qh_rlink;
617 element->qh_rlink->qh_link = element->qh_link;
618 element->qh_rlink = 0;
621 #else /* !__GNUC__ */
623 void insque(void *a, void *b);
624 void remque(void *a);
626 #endif /* __GNUC__ */
628 #endif /* _KERNEL */
630 #endif /* !_SYS_QUEUE_H_ */