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
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
29 * @(#)queue.h 8.5 (Berkeley) 8/20/94
36 #include <sys/cdefs.h>
39 * This file defines four types of data structures: singly-linked lists,
40 * singly-linked tail queues, lists and tail queues.
42 * A singly-linked list is headed by a single forward pointer. The elements
43 * are singly linked for minimum space and pointer manipulation overhead at
44 * the expense of O(n) removal for arbitrary elements. New elements can be
45 * added to the list after an existing element or at the head of the list.
46 * Elements being removed from the head of the list should use the explicit
47 * macro for this purpose for optimum efficiency. A singly-linked list may
48 * only be traversed in the forward direction. Singly-linked lists are ideal
49 * for applications with large datasets and few or no removals or for
50 * implementing a LIFO queue.
52 * A singly-linked tail queue is headed by a pair of pointers, one to the
53 * head of the list and the other to the tail of the list. The elements are
54 * singly linked for minimum space and pointer manipulation overhead at the
55 * expense of O(n) removal for arbitrary elements. New elements can be added
56 * to the list after an existing element, at the head of the list, or at the
57 * end of the list. Elements being removed from the head of the tail queue
58 * should use the explicit macro for this purpose for optimum efficiency.
59 * A singly-linked tail queue may only be traversed in the forward direction.
60 * Singly-linked tail queues are ideal for applications with large datasets
61 * and few or no removals or for implementing a FIFO queue.
63 * A list is headed by a single forward pointer (or an array of forward
64 * pointers for a hash table header). The elements are doubly linked
65 * so that an arbitrary element can be removed without a need to
66 * traverse the list. New elements can be added to the list before
67 * or after an existing element or at the head of the list. A list
68 * may only be traversed in the forward direction.
70 * A tail queue is headed by a pair of pointers, one to the head of the
71 * list and the other to the tail of the list. The elements are doubly
72 * linked so that an arbitrary element can be removed without a need to
73 * traverse the list. New elements can be added to the list before or
74 * after an existing element, at the head of the list, or at the end of
75 * the list. A tail queue may be traversed in either direction.
77 * For details on the use of these macros, see the queue(3) manual page.
80 * SLIST LIST STAILQ TAILQ
82 * _HEAD_INITIALIZER + + + +
91 * _FOREACH_SAFE + + + +
92 * _FOREACH_REVERSE - - - +
93 * _FOREACH_REVERSE_SAFE - - - +
94 * _INSERT_HEAD + + + +
95 * _INSERT_BEFORE - + - +
96 * _INSERT_AFTER + + + +
97 * _INSERT_TAIL - - + +
99 * _REMOVE_AFTER + - + -
100 * _REMOVE_HEAD + - + -
104 #ifdef QUEUE_MACRO_DEBUG
105 /* Store the last 2 places the queue element or head was altered */
113 #define TRACEBUF struct qm_trace trace;
114 #define TRASHIT(x) do {(x) = (void *)-1;} while (0)
116 #define QMD_TRACE_HEAD(head) do { \
117 (head)->trace.prevline = (head)->trace.lastline; \
118 (head)->trace.prevfile = (head)->trace.lastfile; \
119 (head)->trace.lastline = __LINE__; \
120 (head)->trace.lastfile = __FILE__; \
123 #define QMD_TRACE_ELEM(elem) do { \
124 (elem)->trace.prevline = (elem)->trace.lastline; \
125 (elem)->trace.prevfile = (elem)->trace.lastfile; \
126 (elem)->trace.lastline = __LINE__; \
127 (elem)->trace.lastfile = __FILE__; \
131 #define QMD_TRACE_ELEM(elem)
132 #define QMD_TRACE_HEAD(head)
135 #endif /* QUEUE_MACRO_DEBUG */
138 * Singly-linked List declarations.
140 #define SLIST_HEAD(name, type) \
142 struct type *slh_first; /* first element */ \
145 #define SLIST_HEAD_INITIALIZER(head) \
148 #define SLIST_ENTRY(type) \
150 struct type *sle_next; /* next element */ \
154 * Singly-linked List functions.
156 #define SLIST_EMPTY(head) ((head)->slh_first == NULL)
158 #define SLIST_FIRST(head) ((head)->slh_first)
160 #define SLIST_FOREACH(var, head, field) \
161 for ((var) = SLIST_FIRST((head)); \
163 (var) = SLIST_NEXT((var), field))
165 #define SLIST_FOREACH_SAFE(var, head, field, tvar) \
166 for ((var) = SLIST_FIRST((head)); \
167 (var) && ((tvar) = SLIST_NEXT((var), field), 1); \
170 #define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
171 for ((varp) = &SLIST_FIRST((head)); \
172 ((var) = *(varp)) != NULL; \
173 (varp) = &SLIST_NEXT((var), field))
175 #define SLIST_INIT(head) do { \
176 SLIST_FIRST((head)) = NULL; \
179 #define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
180 SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \
181 SLIST_NEXT((slistelm), field) = (elm); \
184 #define SLIST_INSERT_HEAD(head, elm, field) do { \
185 SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \
186 SLIST_FIRST((head)) = (elm); \
189 #define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
191 #define SLIST_REMOVE(head, elm, type, field) do { \
192 if (SLIST_FIRST((head)) == (elm)) { \
193 SLIST_REMOVE_HEAD((head), field); \
196 struct type *curelm = SLIST_FIRST((head)); \
197 while (SLIST_NEXT(curelm, field) != (elm)) \
198 curelm = SLIST_NEXT(curelm, field); \
199 SLIST_REMOVE_AFTER(curelm, field); \
201 TRASHIT((elm)->field.sle_next); \
204 #define SLIST_REMOVE_AFTER(elm, field) do { \
205 SLIST_NEXT(elm, field) = \
206 SLIST_NEXT(SLIST_NEXT(elm, field), field); \
209 #define SLIST_REMOVE_HEAD(head, field) do { \
210 SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
214 * Singly-linked Tail queue declarations.
216 #define STAILQ_HEAD(name, type) \
218 struct type *stqh_first;/* first element */ \
219 struct type **stqh_last;/* addr of last next element */ \
222 #define STAILQ_HEAD_INITIALIZER(head) \
223 { NULL, &(head).stqh_first }
225 #define STAILQ_ENTRY(type) \
227 struct type *stqe_next; /* next element */ \
231 * Singly-linked Tail queue functions.
233 #define STAILQ_CONCAT(head1, head2) do { \
234 if (!STAILQ_EMPTY((head2))) { \
235 *(head1)->stqh_last = (head2)->stqh_first; \
236 (head1)->stqh_last = (head2)->stqh_last; \
237 STAILQ_INIT((head2)); \
241 #define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
243 #define STAILQ_FIRST(head) ((head)->stqh_first)
245 #define STAILQ_FOREACH(var, head, field) \
246 for((var) = STAILQ_FIRST((head)); \
248 (var) = STAILQ_NEXT((var), field))
251 #define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
252 for ((var) = STAILQ_FIRST((head)); \
253 (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
256 #define STAILQ_INIT(head) do { \
257 STAILQ_FIRST((head)) = NULL; \
258 (head)->stqh_last = &STAILQ_FIRST((head)); \
261 #define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \
262 if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
263 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
264 STAILQ_NEXT((tqelm), field) = (elm); \
267 #define STAILQ_INSERT_HEAD(head, elm, field) do { \
268 if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
269 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
270 STAILQ_FIRST((head)) = (elm); \
273 #define STAILQ_INSERT_TAIL(head, elm, field) do { \
274 STAILQ_NEXT((elm), field) = NULL; \
275 *(head)->stqh_last = (elm); \
276 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
279 #define STAILQ_LAST(head, type, field) \
280 (STAILQ_EMPTY((head)) ? \
282 ((struct type *)(void *) \
283 ((char *)((head)->stqh_last) - __offsetof(struct type, field))))
285 #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
287 #define STAILQ_REMOVE(head, elm, type, field) do { \
288 if (STAILQ_FIRST((head)) == (elm)) { \
289 STAILQ_REMOVE_HEAD((head), field); \
292 struct type *curelm = STAILQ_FIRST((head)); \
293 while (STAILQ_NEXT(curelm, field) != (elm)) \
294 curelm = STAILQ_NEXT(curelm, field); \
295 STAILQ_REMOVE_AFTER(head, curelm, field); \
297 TRASHIT((elm)->field.stqe_next); \
300 #define STAILQ_REMOVE_HEAD(head, field) do { \
301 if ((STAILQ_FIRST((head)) = \
302 STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \
303 (head)->stqh_last = &STAILQ_FIRST((head)); \
306 #define STAILQ_REMOVE_AFTER(head, elm, field) do { \
307 if ((STAILQ_NEXT(elm, field) = \
308 STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \
309 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
312 #define STAILQ_SWAP(head1, head2, type) do { \
313 struct type *swap_first = STAILQ_FIRST(head1); \
314 struct type **swap_last = (head1)->stqh_last; \
315 STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \
316 (head1)->stqh_last = (head2)->stqh_last; \
317 STAILQ_FIRST(head2) = swap_first; \
318 (head2)->stqh_last = swap_last; \
319 if (STAILQ_EMPTY(head1)) \
320 (head1)->stqh_last = &STAILQ_FIRST(head1); \
321 if (STAILQ_EMPTY(head2)) \
322 (head2)->stqh_last = &STAILQ_FIRST(head2); \
329 #define LIST_HEAD(name, type) \
331 struct type *lh_first; /* first element */ \
334 #define LIST_HEAD_INITIALIZER(head) \
337 #define LIST_ENTRY(type) \
339 struct type *le_next; /* next element */ \
340 struct type **le_prev; /* address of previous next element */ \
347 #if (defined(_KERNEL) && defined(INVARIANTS))
348 #define QMD_LIST_CHECK_HEAD(head, field) do { \
349 if (LIST_FIRST((head)) != NULL && \
350 LIST_FIRST((head))->field.le_prev != \
351 &LIST_FIRST((head))) \
352 panic("Bad list head %p first->prev != head", (head)); \
355 #define QMD_LIST_CHECK_NEXT(elm, field) do { \
356 if (LIST_NEXT((elm), field) != NULL && \
357 LIST_NEXT((elm), field)->field.le_prev != \
358 &((elm)->field.le_next)) \
359 panic("Bad link elm %p next->prev != elm", (elm)); \
362 #define QMD_LIST_CHECK_PREV(elm, field) do { \
363 if (*(elm)->field.le_prev != (elm)) \
364 panic("Bad link elm %p prev->next != elm", (elm)); \
367 #define QMD_LIST_CHECK_HEAD(head, field)
368 #define QMD_LIST_CHECK_NEXT(elm, field)
369 #define QMD_LIST_CHECK_PREV(elm, field)
370 #endif /* (_KERNEL && INVARIANTS) */
372 #define LIST_EMPTY(head) ((head)->lh_first == NULL)
374 #define LIST_FIRST(head) ((head)->lh_first)
376 #define LIST_FOREACH(var, head, field) \
377 for ((var) = LIST_FIRST((head)); \
379 (var) = LIST_NEXT((var), field))
381 #define LIST_FOREACH_SAFE(var, head, field, tvar) \
382 for ((var) = LIST_FIRST((head)); \
383 (var) && ((tvar) = LIST_NEXT((var), field), 1); \
386 #define LIST_INIT(head) do { \
387 LIST_FIRST((head)) = NULL; \
390 #define LIST_INSERT_AFTER(listelm, elm, field) do { \
391 QMD_LIST_CHECK_NEXT(listelm, field); \
392 if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
393 LIST_NEXT((listelm), field)->field.le_prev = \
394 &LIST_NEXT((elm), field); \
395 LIST_NEXT((listelm), field) = (elm); \
396 (elm)->field.le_prev = &LIST_NEXT((listelm), field); \
399 #define LIST_INSERT_BEFORE(listelm, elm, field) do { \
400 QMD_LIST_CHECK_PREV(listelm, field); \
401 (elm)->field.le_prev = (listelm)->field.le_prev; \
402 LIST_NEXT((elm), field) = (listelm); \
403 *(listelm)->field.le_prev = (elm); \
404 (listelm)->field.le_prev = &LIST_NEXT((elm), field); \
407 #define LIST_INSERT_HEAD(head, elm, field) do { \
408 QMD_LIST_CHECK_HEAD((head), field); \
409 if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
410 LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
411 LIST_FIRST((head)) = (elm); \
412 (elm)->field.le_prev = &LIST_FIRST((head)); \
415 #define LIST_NEXT(elm, field) ((elm)->field.le_next)
417 #define LIST_REMOVE(elm, field) do { \
418 QMD_LIST_CHECK_NEXT(elm, field); \
419 QMD_LIST_CHECK_PREV(elm, field); \
420 if (LIST_NEXT((elm), field) != NULL) \
421 LIST_NEXT((elm), field)->field.le_prev = \
422 (elm)->field.le_prev; \
423 *(elm)->field.le_prev = LIST_NEXT((elm), field); \
424 TRASHIT((elm)->field.le_next); \
425 TRASHIT((elm)->field.le_prev); \
428 #define LIST_SWAP(head1, head2, type, field) do { \
429 struct type *swap_tmp = LIST_FIRST((head1)); \
430 LIST_FIRST((head1)) = LIST_FIRST((head2)); \
431 LIST_FIRST((head2)) = swap_tmp; \
432 if ((swap_tmp = LIST_FIRST((head1))) != NULL) \
433 swap_tmp->field.le_prev = &LIST_FIRST((head1)); \
434 if ((swap_tmp = LIST_FIRST((head2))) != NULL) \
435 swap_tmp->field.le_prev = &LIST_FIRST((head2)); \
439 * Tail queue declarations.
441 #define TAILQ_HEAD(name, type) \
443 struct type *tqh_first; /* first element */ \
444 struct type **tqh_last; /* addr of last next element */ \
448 #define TAILQ_HEAD_INITIALIZER(head) \
449 { NULL, &(head).tqh_first }
451 #define TAILQ_ENTRY(type) \
453 struct type *tqe_next; /* next element */ \
454 struct type **tqe_prev; /* address of previous next element */ \
459 * Tail queue functions.
461 #if (defined(_KERNEL) && defined(INVARIANTS))
462 #define QMD_TAILQ_CHECK_HEAD(head, field) do { \
463 if (!TAILQ_EMPTY(head) && \
464 TAILQ_FIRST((head))->field.tqe_prev != \
465 &TAILQ_FIRST((head))) \
466 panic("Bad tailq head %p first->prev != head", (head)); \
469 #define QMD_TAILQ_CHECK_TAIL(head, field) do { \
470 if (*(head)->tqh_last != NULL) \
471 panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \
474 #define QMD_TAILQ_CHECK_NEXT(elm, field) do { \
475 if (TAILQ_NEXT((elm), field) != NULL && \
476 TAILQ_NEXT((elm), field)->field.tqe_prev != \
477 &((elm)->field.tqe_next)) \
478 panic("Bad link elm %p next->prev != elm", (elm)); \
481 #define QMD_TAILQ_CHECK_PREV(elm, field) do { \
482 if (*(elm)->field.tqe_prev != (elm)) \
483 panic("Bad link elm %p prev->next != elm", (elm)); \
486 #define QMD_TAILQ_CHECK_HEAD(head, field)
487 #define QMD_TAILQ_CHECK_TAIL(head, headname)
488 #define QMD_TAILQ_CHECK_NEXT(elm, field)
489 #define QMD_TAILQ_CHECK_PREV(elm, field)
490 #endif /* (_KERNEL && INVARIANTS) */
492 #define TAILQ_CONCAT(head1, head2, field) do { \
493 if (!TAILQ_EMPTY(head2)) { \
494 *(head1)->tqh_last = (head2)->tqh_first; \
495 (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
496 (head1)->tqh_last = (head2)->tqh_last; \
497 TAILQ_INIT((head2)); \
498 QMD_TRACE_HEAD(head1); \
499 QMD_TRACE_HEAD(head2); \
503 #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
505 #define TAILQ_FIRST(head) ((head)->tqh_first)
507 #define TAILQ_FOREACH(var, head, field) \
508 for ((var) = TAILQ_FIRST((head)); \
510 (var) = TAILQ_NEXT((var), field))
512 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
513 for ((var) = TAILQ_FIRST((head)); \
514 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
517 #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
518 for ((var) = TAILQ_LAST((head), headname); \
520 (var) = TAILQ_PREV((var), headname, field))
522 #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
523 for ((var) = TAILQ_LAST((head), headname); \
524 (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
527 #define TAILQ_INIT(head) do { \
528 TAILQ_FIRST((head)) = NULL; \
529 (head)->tqh_last = &TAILQ_FIRST((head)); \
530 QMD_TRACE_HEAD(head); \
533 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
534 QMD_TAILQ_CHECK_NEXT(listelm, field); \
535 if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
536 TAILQ_NEXT((elm), field)->field.tqe_prev = \
537 &TAILQ_NEXT((elm), field); \
539 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
540 QMD_TRACE_HEAD(head); \
542 TAILQ_NEXT((listelm), field) = (elm); \
543 (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
544 QMD_TRACE_ELEM(&(elm)->field); \
545 QMD_TRACE_ELEM(&listelm->field); \
548 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
549 QMD_TAILQ_CHECK_PREV(listelm, field); \
550 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
551 TAILQ_NEXT((elm), field) = (listelm); \
552 *(listelm)->field.tqe_prev = (elm); \
553 (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
554 QMD_TRACE_ELEM(&(elm)->field); \
555 QMD_TRACE_ELEM(&listelm->field); \
558 #define TAILQ_INSERT_HEAD(head, elm, field) do { \
559 QMD_TAILQ_CHECK_HEAD(head, field); \
560 if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
561 TAILQ_FIRST((head))->field.tqe_prev = \
562 &TAILQ_NEXT((elm), field); \
564 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
565 TAILQ_FIRST((head)) = (elm); \
566 (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
567 QMD_TRACE_HEAD(head); \
568 QMD_TRACE_ELEM(&(elm)->field); \
571 #define TAILQ_INSERT_TAIL(head, elm, field) do { \
572 QMD_TAILQ_CHECK_TAIL(head, field); \
573 TAILQ_NEXT((elm), field) = NULL; \
574 (elm)->field.tqe_prev = (head)->tqh_last; \
575 *(head)->tqh_last = (elm); \
576 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
577 QMD_TRACE_HEAD(head); \
578 QMD_TRACE_ELEM(&(elm)->field); \
581 #define TAILQ_LAST(head, headname) \
582 (*(((struct headname *)((head)->tqh_last))->tqh_last))
584 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
586 #define TAILQ_PREV(elm, headname, field) \
587 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
589 #define TAILQ_REMOVE(head, elm, field) do { \
590 QMD_TAILQ_CHECK_NEXT(elm, field); \
591 QMD_TAILQ_CHECK_PREV(elm, field); \
592 if ((TAILQ_NEXT((elm), field)) != NULL) \
593 TAILQ_NEXT((elm), field)->field.tqe_prev = \
594 (elm)->field.tqe_prev; \
596 (head)->tqh_last = (elm)->field.tqe_prev; \
597 QMD_TRACE_HEAD(head); \
599 *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
600 TRASHIT((elm)->field.tqe_next); \
601 TRASHIT((elm)->field.tqe_prev); \
602 QMD_TRACE_ELEM(&(elm)->field); \
605 #define TAILQ_SWAP(head1, head2, type, field) do { \
606 struct type *swap_first = (head1)->tqh_first; \
607 struct type **swap_last = (head1)->tqh_last; \
608 (head1)->tqh_first = (head2)->tqh_first; \
609 (head1)->tqh_last = (head2)->tqh_last; \
610 (head2)->tqh_first = swap_first; \
611 (head2)->tqh_last = swap_last; \
612 if ((swap_first = (head1)->tqh_first) != NULL) \
613 swap_first->field.tqe_prev = &(head1)->tqh_first; \
615 (head1)->tqh_last = &(head1)->tqh_first; \
616 if ((swap_first = (head2)->tqh_first) != NULL) \
617 swap_first->field.tqe_prev = &(head2)->tqh_first; \
619 (head2)->tqh_last = &(head2)->tqh_first; \
622 #endif /* !_SYS_QUEUE_H_ */