1 /* $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $ */
2 /* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
5 * Copyright (c) 1991, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)queue.h 8.5 (Berkeley) 8/20/94
41 * This file defines linked list operations. It is derived from BSD with
42 * only the MACRO names being prefixed with DWC_. This is because a few of
43 * these names conflict with those on Linux. For documentation on use, see the
44 * inline comments in the source code. The original license for this source
45 * code applies and is preserved in the dwc_list.h source file.
49 * This file defines five types of data structures: singly-linked lists,
50 * lists, simple queues, tail queues, and circular queues.
53 * A singly-linked list is headed by a single forward pointer. The elements
54 * are singly linked for minimum space and pointer manipulation overhead at
55 * the expense of O(n) removal for arbitrary elements. New elements can be
56 * added to the list after an existing element or at the head of the list.
57 * Elements being removed from the head of the list should use the explicit
58 * macro for this purpose for optimum efficiency. A singly-linked list may
59 * only be traversed in the forward direction. Singly-linked lists are ideal
60 * for applications with large datasets and few or no removals or for
61 * implementing a LIFO 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 simple queue is headed by a pair of pointers, one the head of the
71 * list and the other to the tail of the list. The elements are singly
72 * linked to save space, so elements can only be removed from the
73 * head of the list. New elements can be added to the list before or after
74 * an existing element, at the head of the list, or at the end of the
75 * list. A simple queue may only be traversed in the forward direction.
77 * A tail queue is headed by a pair of pointers, one to the head of the
78 * list and the other to the tail of the list. The elements are doubly
79 * linked so that an arbitrary element can be removed without a need to
80 * traverse the list. New elements can be added to the list before or
81 * after an existing element, at the head of the list, or at the end of
82 * the list. A tail queue may be traversed in either direction.
84 * A circle queue is headed by a pair of pointers, one to the head of the
85 * list and the other to the tail of the list. The elements are doubly
86 * linked so that an arbitrary element can be removed without a need to
87 * traverse the list. New elements can be added to the list before or after
88 * an existing element, at the head of the list, or at the end of the list.
89 * A circle queue may be traversed in either direction, but has a more
90 * complex end of list detection.
92 * For details on the use of these macros, see the queue(3) manual page.
99 typedef struct dwc_list_link {
100 struct dwc_list_link *next;
101 struct dwc_list_link *prev;
104 #define DWC_LIST_INIT(link) do{ \
105 (link)->next = (link); \
106 (link)->prev = (link); \
109 #define DWC_LIST_FIRST(link) ((link)->next)
110 #define DWC_LIST_LAST(link) ((link)->prev)
111 #define DWC_LIST_END(link) (link)
112 #define DWC_LIST_NEXT(link) ((link)->next)
113 #define DWC_LIST_PREV(link) ((link)->prev)
114 #define DWC_LIST_EMPTY(link) \
115 (DWC_LIST_FIRST(link) == DWC_LIST_END(link))
116 #define DWC_LIST_ENTRY(link, type, field) (type *) \
117 ((uint8_t *)(link) - (size_t)(&((type *)0)->field))
119 #define DWC_LIST_INSERT_HEAD(list, link) do { \
120 (link)->next = (list)->next; \
121 (link)->prev = (list); \
122 (list)->next->prev = link; \
123 (list)->next = link; \
126 #define DWC_LIST_INSERT_TAIL(list, link) do { \
127 (link)->next = list; \
128 (link)->prev = (list)->prev; \
129 (list)->prev->next = link; \
130 (list)->prev = link; \
133 #define DWC_LIST_REMOVE(link) do { \
134 (link)->next->prev = (link)->prev; \
135 (link)->prev->next = (link)->next; \
138 #define DWC_LIST_REMOVE_INIT(link) do { \
139 DWC_LIST_REMOVE(link); \
140 DWC_LIST_INIT(link); \
143 #define DWC_LIST_MOVE_HEAD(list, link) do { \
144 DWC_LIST_REMOVE(link); \
145 DWC_LIST_INSERT_HEAD(list, link); \
148 #define DWC_LIST_MOVE_TAIL(list, link) do { \
149 DWC_LIST_REMOVE(link); \
150 DWC_LIST_INSERT_TAIL(list, link); \
153 #define DWC_LIST_FOREACH(var, list) \
154 for((var) = DWC_LIST_FIRST(list); \
155 (var) != DWC_LIST_END(list); \
156 (var) = DWC_LIST_NEXT(var))
158 #define DWC_LIST_FOREACH_SAFE(var, var2, list) \
159 for((var) = DWC_LIST_FIRST(list), var2 = DWC_LIST_NEXT(var); \
160 (var) != DWC_LIST_END(list); \
161 (var) = (var2), var2 = DWC_LIST_NEXT(var2))
163 #define DWC_LIST_FOREACH_REVERSE(var, list) \
164 for((var) = DWC_LIST_LAST(list); \
165 (var) != DWC_LIST_END(list); \
166 (var) = DWC_LIST_PREV(var))
169 * Singly-linked List definitions.
171 #define DWC_SLIST_HEAD(name, type) \
173 struct type *slh_first; /* first element */ \
176 #define DWC_SLIST_HEAD_INITIALIZER(head) \
179 #define DWC_SLIST_ENTRY(type) \
181 struct type *sle_next; /* next element */ \
185 * Singly-linked List access methods.
187 #define DWC_SLIST_FIRST(head) ((head)->slh_first)
188 #define DWC_SLIST_END(head) NULL
189 #define DWC_SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
190 #define DWC_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
192 #define DWC_SLIST_FOREACH(var, head, field) \
193 for((var) = SLIST_FIRST(head); \
194 (var) != SLIST_END(head); \
195 (var) = SLIST_NEXT(var, field))
197 #define DWC_SLIST_FOREACH_PREVPTR(var, varp, head, field) \
198 for ((varp) = &SLIST_FIRST((head)); \
199 ((var) = *(varp)) != SLIST_END(head); \
200 (varp) = &SLIST_NEXT((var), field))
203 * Singly-linked List functions.
205 #define DWC_SLIST_INIT(head) { \
206 SLIST_FIRST(head) = SLIST_END(head); \
209 #define DWC_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
210 (elm)->field.sle_next = (slistelm)->field.sle_next; \
211 (slistelm)->field.sle_next = (elm); \
214 #define DWC_SLIST_INSERT_HEAD(head, elm, field) do { \
215 (elm)->field.sle_next = (head)->slh_first; \
216 (head)->slh_first = (elm); \
219 #define DWC_SLIST_REMOVE_NEXT(head, elm, field) do { \
220 (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
223 #define DWC_SLIST_REMOVE_HEAD(head, field) do { \
224 (head)->slh_first = (head)->slh_first->field.sle_next; \
227 #define DWC_SLIST_REMOVE(head, elm, type, field) do { \
228 if ((head)->slh_first == (elm)) { \
229 SLIST_REMOVE_HEAD((head), field); \
232 struct type *curelm = (head)->slh_first; \
233 while( curelm->field.sle_next != (elm) ) \
234 curelm = curelm->field.sle_next; \
235 curelm->field.sle_next = \
236 curelm->field.sle_next->field.sle_next; \
245 #define DWC_LIST_HEAD(name, type) \
247 struct type *lh_first; /* first element */ \
250 #define DWC_LIST_HEAD_INITIALIZER(head) \
253 #define DWC_LIST_ENTRY(type) \
255 struct type *le_next; /* next element */ \
256 struct type **le_prev; /* address of previous next element */ \
260 * List access methods
262 #define DWC_LIST_FIRST(head) ((head)->lh_first)
263 #define DWC_LIST_END(head) NULL
264 #define DWC_LIST_EMPTY(head) (DWC_LIST_FIRST(head) == DWC_LIST_END(head))
265 #define DWC_LIST_NEXT(elm, field) ((elm)->field.le_next)
267 #define DWC_LIST_FOREACH(var, head, field) \
268 for((var) = DWC_LIST_FIRST(head); \
269 (var)!= DWC_LIST_END(head); \
270 (var) = DWC_LIST_NEXT(var, field))
271 #define DWC_LIST_FOREACH_SAFE(var, var2, head, field) \
272 for((var) = DWC_LIST_FIRST(head), var2 = DWC_LIST_NEXT(var, field); \
273 (var) != DWC_LIST_END(head); \
274 (var) = var2, var2 = DWC_LIST_NEXT(var, field))
279 #define DWC_LIST_INIT(head) do { \
280 DWC_LIST_FIRST(head) = DWC_LIST_END(head); \
283 #define DWC_LIST_INSERT_AFTER(listelm, elm, field) do { \
284 if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
285 (listelm)->field.le_next->field.le_prev = \
286 &(elm)->field.le_next; \
287 (listelm)->field.le_next = (elm); \
288 (elm)->field.le_prev = &(listelm)->field.le_next; \
291 #define DWC_LIST_INSERT_BEFORE(listelm, elm, field) do { \
292 (elm)->field.le_prev = (listelm)->field.le_prev; \
293 (elm)->field.le_next = (listelm); \
294 *(listelm)->field.le_prev = (elm); \
295 (listelm)->field.le_prev = &(elm)->field.le_next; \
298 #define DWC_LIST_INSERT_HEAD(head, elm, field) do { \
299 if (((elm)->field.le_next = (head)->lh_first) != NULL) \
300 (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
301 (head)->lh_first = (elm); \
302 (elm)->field.le_prev = &(head)->lh_first; \
305 #define DWC_LIST_REMOVE(elm, field) do { \
306 if ((elm)->field.le_next != NULL) \
307 (elm)->field.le_next->field.le_prev = \
308 (elm)->field.le_prev; \
309 *(elm)->field.le_prev = (elm)->field.le_next; \
312 #define DWC_LIST_REPLACE(elm, elm2, field) do { \
313 if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
314 (elm2)->field.le_next->field.le_prev = \
315 &(elm2)->field.le_next; \
316 (elm2)->field.le_prev = (elm)->field.le_prev; \
317 *(elm2)->field.le_prev = (elm2); \
323 * Simple queue definitions.
325 #define DWC_SIMPLEQ_HEAD(name, type) \
327 struct type *sqh_first; /* first element */ \
328 struct type **sqh_last; /* addr of last next element */ \
331 #define DWC_SIMPLEQ_HEAD_INITIALIZER(head) \
332 { NULL, &(head).sqh_first }
334 #define DWC_SIMPLEQ_ENTRY(type) \
336 struct type *sqe_next; /* next element */ \
340 * Simple queue access methods.
342 #define DWC_SIMPLEQ_FIRST(head) ((head)->sqh_first)
343 #define DWC_SIMPLEQ_END(head) NULL
344 #define DWC_SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
345 #define DWC_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
347 #define DWC_SIMPLEQ_FOREACH(var, head, field) \
348 for((var) = SIMPLEQ_FIRST(head); \
349 (var) != SIMPLEQ_END(head); \
350 (var) = SIMPLEQ_NEXT(var, field))
353 * Simple queue functions.
355 #define DWC_SIMPLEQ_INIT(head) do { \
356 (head)->sqh_first = NULL; \
357 (head)->sqh_last = &(head)->sqh_first; \
360 #define DWC_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
361 if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
362 (head)->sqh_last = &(elm)->field.sqe_next; \
363 (head)->sqh_first = (elm); \
366 #define DWC_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
367 (elm)->field.sqe_next = NULL; \
368 *(head)->sqh_last = (elm); \
369 (head)->sqh_last = &(elm)->field.sqe_next; \
372 #define DWC_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
373 if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
374 (head)->sqh_last = &(elm)->field.sqe_next; \
375 (listelm)->field.sqe_next = (elm); \
378 #define DWC_SIMPLEQ_REMOVE_HEAD(head, field) do { \
379 if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
380 (head)->sqh_last = &(head)->sqh_first; \
384 * Tail queue definitions.
386 #define DWC_TAILQ_HEAD(name, type) \
388 struct type *tqh_first; /* first element */ \
389 struct type **tqh_last; /* addr of last next element */ \
392 #define DWC_TAILQ_HEAD_INITIALIZER(head) \
393 { NULL, &(head).tqh_first }
395 #define DWC_TAILQ_ENTRY(type) \
397 struct type *tqe_next; /* next element */ \
398 struct type **tqe_prev; /* address of previous next element */ \
402 * tail queue access methods
404 #define DWC_TAILQ_FIRST(head) ((head)->tqh_first)
405 #define DWC_TAILQ_END(head) NULL
406 #define DWC_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
407 #define DWC_TAILQ_LAST(head, headname) \
408 (*(((struct headname *)((head)->tqh_last))->tqh_last))
410 #define DWC_TAILQ_PREV(elm, headname, field) \
411 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
412 #define DWC_TAILQ_EMPTY(head) \
413 (TAILQ_FIRST(head) == TAILQ_END(head))
415 #define DWC_TAILQ_FOREACH(var, head, field) \
416 for((var) = TAILQ_FIRST(head); \
417 (var) != TAILQ_END(head); \
418 (var) = TAILQ_NEXT(var, field))
420 #define DWC_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
421 for((var) = TAILQ_LAST(head, headname); \
422 (var) != TAILQ_END(head); \
423 (var) = TAILQ_PREV(var, headname, field))
426 * Tail queue functions.
428 #define DWC_TAILQ_INIT(head) do { \
429 (head)->tqh_first = NULL; \
430 (head)->tqh_last = &(head)->tqh_first; \
433 #define DWC_TAILQ_INSERT_HEAD(head, elm, field) do { \
434 if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
435 (head)->tqh_first->field.tqe_prev = \
436 &(elm)->field.tqe_next; \
438 (head)->tqh_last = &(elm)->field.tqe_next; \
439 (head)->tqh_first = (elm); \
440 (elm)->field.tqe_prev = &(head)->tqh_first; \
443 #define DWC_TAILQ_INSERT_TAIL(head, elm, field) do { \
444 (elm)->field.tqe_next = NULL; \
445 (elm)->field.tqe_prev = (head)->tqh_last; \
446 *(head)->tqh_last = (elm); \
447 (head)->tqh_last = &(elm)->field.tqe_next; \
450 #define DWC_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
451 if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
452 (elm)->field.tqe_next->field.tqe_prev = \
453 &(elm)->field.tqe_next; \
455 (head)->tqh_last = &(elm)->field.tqe_next; \
456 (listelm)->field.tqe_next = (elm); \
457 (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
460 #define DWC_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
461 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
462 (elm)->field.tqe_next = (listelm); \
463 *(listelm)->field.tqe_prev = (elm); \
464 (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
467 #define DWC_TAILQ_REMOVE(head, elm, field) do { \
468 if (((elm)->field.tqe_next) != NULL) \
469 (elm)->field.tqe_next->field.tqe_prev = \
470 (elm)->field.tqe_prev; \
472 (head)->tqh_last = (elm)->field.tqe_prev; \
473 *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
476 #define DWC_TAILQ_REPLACE(head, elm, elm2, field) do { \
477 if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
478 (elm2)->field.tqe_next->field.tqe_prev = \
479 &(elm2)->field.tqe_next; \
481 (head)->tqh_last = &(elm2)->field.tqe_next; \
482 (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
483 *(elm2)->field.tqe_prev = (elm2); \
487 * Circular queue definitions.
489 #define DWC_CIRCLEQ_HEAD(name, type) \
491 struct type *cqh_first; /* first element */ \
492 struct type *cqh_last; /* last element */ \
495 #define DWC_CIRCLEQ_HEAD_INITIALIZER(head) \
496 { DWC_CIRCLEQ_END(&head), DWC_CIRCLEQ_END(&head) }
498 #define DWC_CIRCLEQ_ENTRY(type) \
500 struct type *cqe_next; /* next element */ \
501 struct type *cqe_prev; /* previous element */ \
505 * Circular queue access methods
507 #define DWC_CIRCLEQ_FIRST(head) ((head)->cqh_first)
508 #define DWC_CIRCLEQ_LAST(head) ((head)->cqh_last)
509 #define DWC_CIRCLEQ_END(head) ((void *)(head))
510 #define DWC_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
511 #define DWC_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
512 #define DWC_CIRCLEQ_EMPTY(head) \
513 (DWC_CIRCLEQ_FIRST(head) == DWC_CIRCLEQ_END(head))
515 #define DWC_CIRCLEQ_EMPTY_ENTRY(elm, field) (((elm)->field.cqe_next == NULL) && ((elm)->field.cqe_prev == NULL))
517 #define DWC_CIRCLEQ_FOREACH(var, head, field) \
518 for((var) = DWC_CIRCLEQ_FIRST(head); \
519 (var) != DWC_CIRCLEQ_END(head); \
520 (var) = DWC_CIRCLEQ_NEXT(var, field))
522 #define DWC_CIRCLEQ_FOREACH_SAFE(var, var2, head, field) \
523 for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
524 (var) != DWC_CIRCLEQ_END(head); \
525 (var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
527 #define DWC_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
528 for((var) = DWC_CIRCLEQ_LAST(head); \
529 (var) != DWC_CIRCLEQ_END(head); \
530 (var) = DWC_CIRCLEQ_PREV(var, field))
533 * Circular queue functions.
535 #define DWC_CIRCLEQ_INIT(head) do { \
536 (head)->cqh_first = DWC_CIRCLEQ_END(head); \
537 (head)->cqh_last = DWC_CIRCLEQ_END(head); \
540 #define DWC_CIRCLEQ_INIT_ENTRY(elm, field) do { \
541 (elm)->field.cqe_next = NULL; \
542 (elm)->field.cqe_prev = NULL; \
545 #define DWC_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
546 (elm)->field.cqe_next = (listelm)->field.cqe_next; \
547 (elm)->field.cqe_prev = (listelm); \
548 if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
549 (head)->cqh_last = (elm); \
551 (listelm)->field.cqe_next->field.cqe_prev = (elm); \
552 (listelm)->field.cqe_next = (elm); \
555 #define DWC_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
556 (elm)->field.cqe_next = (listelm); \
557 (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
558 if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
559 (head)->cqh_first = (elm); \
561 (listelm)->field.cqe_prev->field.cqe_next = (elm); \
562 (listelm)->field.cqe_prev = (elm); \
565 #define DWC_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
566 (elm)->field.cqe_next = (head)->cqh_first; \
567 (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \
568 if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \
569 (head)->cqh_last = (elm); \
571 (head)->cqh_first->field.cqe_prev = (elm); \
572 (head)->cqh_first = (elm); \
575 #define DWC_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
576 (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \
577 (elm)->field.cqe_prev = (head)->cqh_last; \
578 if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \
579 (head)->cqh_first = (elm); \
581 (head)->cqh_last->field.cqe_next = (elm); \
582 (head)->cqh_last = (elm); \
585 #define DWC_CIRCLEQ_REMOVE(head, elm, field) do { \
586 if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
587 (head)->cqh_last = (elm)->field.cqe_prev; \
589 (elm)->field.cqe_next->field.cqe_prev = \
590 (elm)->field.cqe_prev; \
591 if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
592 (head)->cqh_first = (elm)->field.cqe_next; \
594 (elm)->field.cqe_prev->field.cqe_next = \
595 (elm)->field.cqe_next; \
598 #define DWC_CIRCLEQ_REMOVE_INIT(head, elm, field) do { \
599 DWC_CIRCLEQ_REMOVE(head, elm, field); \
600 DWC_CIRCLEQ_INIT_ENTRY(elm, field); \
603 #define DWC_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
604 if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
605 DWC_CIRCLEQ_END(head)) \
606 (head).cqh_last = (elm2); \
608 (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
609 if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
610 DWC_CIRCLEQ_END(head)) \
611 (head).cqh_first = (elm2); \
613 (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
616 #endif /* !_SYS_QUEUE_H_ */