xref: /utopia/UTPA2-700.0.x/projects/tools/lint/mips-linux-gnu_include/sys/queue.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1*53ee8cc1Swenshuai.xi /*
2*53ee8cc1Swenshuai.xi  * Copyright (c) 1991, 1993
3*53ee8cc1Swenshuai.xi  *	The Regents of the University of California.  All rights reserved.
4*53ee8cc1Swenshuai.xi  *
5*53ee8cc1Swenshuai.xi  * Redistribution and use in source and binary forms, with or without
6*53ee8cc1Swenshuai.xi  * modification, are permitted provided that the following conditions
7*53ee8cc1Swenshuai.xi  * are met:
8*53ee8cc1Swenshuai.xi  * 1. Redistributions of source code must retain the above copyright
9*53ee8cc1Swenshuai.xi  *    notice, this list of conditions and the following disclaimer.
10*53ee8cc1Swenshuai.xi  * 2. Redistributions in binary form must reproduce the above copyright
11*53ee8cc1Swenshuai.xi  *    notice, this list of conditions and the following disclaimer in the
12*53ee8cc1Swenshuai.xi  *    documentation and/or other materials provided with the distribution.
13*53ee8cc1Swenshuai.xi  * 3. Neither the name of the University nor the names of its contributors
14*53ee8cc1Swenshuai.xi  *    may be used to endorse or promote products derived from this software
15*53ee8cc1Swenshuai.xi  *    without specific prior written permission.
16*53ee8cc1Swenshuai.xi  *
17*53ee8cc1Swenshuai.xi  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18*53ee8cc1Swenshuai.xi  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*53ee8cc1Swenshuai.xi  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*53ee8cc1Swenshuai.xi  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21*53ee8cc1Swenshuai.xi  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*53ee8cc1Swenshuai.xi  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*53ee8cc1Swenshuai.xi  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*53ee8cc1Swenshuai.xi  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*53ee8cc1Swenshuai.xi  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*53ee8cc1Swenshuai.xi  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*53ee8cc1Swenshuai.xi  * SUCH DAMAGE.
28*53ee8cc1Swenshuai.xi  *
29*53ee8cc1Swenshuai.xi  *	@(#)queue.h	8.5 (Berkeley) 8/20/94
30*53ee8cc1Swenshuai.xi  */
31*53ee8cc1Swenshuai.xi 
32*53ee8cc1Swenshuai.xi #ifndef	_SYS_QUEUE_H_
33*53ee8cc1Swenshuai.xi #define	_SYS_QUEUE_H_
34*53ee8cc1Swenshuai.xi 
35*53ee8cc1Swenshuai.xi /*
36*53ee8cc1Swenshuai.xi  * This file defines five types of data structures: singly-linked lists,
37*53ee8cc1Swenshuai.xi  * lists, simple queues, tail queues, and circular queues.
38*53ee8cc1Swenshuai.xi  *
39*53ee8cc1Swenshuai.xi  * A singly-linked list is headed by a single forward pointer. The
40*53ee8cc1Swenshuai.xi  * elements are singly linked for minimum space and pointer manipulation
41*53ee8cc1Swenshuai.xi  * overhead at the expense of O(n) removal for arbitrary elements. New
42*53ee8cc1Swenshuai.xi  * elements can be added to the list after an existing element or at the
43*53ee8cc1Swenshuai.xi  * head of the list.  Elements being removed from the head of the list
44*53ee8cc1Swenshuai.xi  * should use the explicit macro for this purpose for optimum
45*53ee8cc1Swenshuai.xi  * efficiency. A singly-linked list may only be traversed in the forward
46*53ee8cc1Swenshuai.xi  * direction.  Singly-linked lists are ideal for applications with large
47*53ee8cc1Swenshuai.xi  * datasets and few or no removals or for implementing a LIFO queue.
48*53ee8cc1Swenshuai.xi  *
49*53ee8cc1Swenshuai.xi  * A list is headed by a single forward pointer (or an array of forward
50*53ee8cc1Swenshuai.xi  * pointers for a hash table header). The elements are doubly linked
51*53ee8cc1Swenshuai.xi  * so that an arbitrary element can be removed without a need to
52*53ee8cc1Swenshuai.xi  * traverse the list. New elements can be added to the list before
53*53ee8cc1Swenshuai.xi  * or after an existing element or at the head of the list. A list
54*53ee8cc1Swenshuai.xi  * may only be traversed in the forward direction.
55*53ee8cc1Swenshuai.xi  *
56*53ee8cc1Swenshuai.xi  * A simple queue is headed by a pair of pointers, one the head of the
57*53ee8cc1Swenshuai.xi  * list and the other to the tail of the list. The elements are singly
58*53ee8cc1Swenshuai.xi  * linked to save space, so elements can only be removed from the
59*53ee8cc1Swenshuai.xi  * head of the list. New elements can be added to the list after
60*53ee8cc1Swenshuai.xi  * an existing element, at the head of the list, or at the end of the
61*53ee8cc1Swenshuai.xi  * list. A simple queue may only be traversed in the forward direction.
62*53ee8cc1Swenshuai.xi  *
63*53ee8cc1Swenshuai.xi  * A tail queue is headed by a pair of pointers, one to the head of the
64*53ee8cc1Swenshuai.xi  * list and the other to the tail of the list. The elements are doubly
65*53ee8cc1Swenshuai.xi  * linked so that an arbitrary element can be removed without a need to
66*53ee8cc1Swenshuai.xi  * traverse the list. New elements can be added to the list before or
67*53ee8cc1Swenshuai.xi  * after an existing element, at the head of the list, or at the end of
68*53ee8cc1Swenshuai.xi  * the list. A tail queue may be traversed in either direction.
69*53ee8cc1Swenshuai.xi  *
70*53ee8cc1Swenshuai.xi  * A circle queue is headed by a pair of pointers, one to the head of the
71*53ee8cc1Swenshuai.xi  * list and the other to the tail of the list. The elements are doubly
72*53ee8cc1Swenshuai.xi  * linked so that an arbitrary element can be removed without a need to
73*53ee8cc1Swenshuai.xi  * traverse the list. New elements can be added to the list before or after
74*53ee8cc1Swenshuai.xi  * an existing element, at the head of the list, or at the end of the list.
75*53ee8cc1Swenshuai.xi  * A circle queue may be traversed in either direction, but has a more
76*53ee8cc1Swenshuai.xi  * complex end of list detection.
77*53ee8cc1Swenshuai.xi  *
78*53ee8cc1Swenshuai.xi  * For details on the use of these macros, see the queue(3) manual page.
79*53ee8cc1Swenshuai.xi  */
80*53ee8cc1Swenshuai.xi 
81*53ee8cc1Swenshuai.xi /*
82*53ee8cc1Swenshuai.xi  * List definitions.
83*53ee8cc1Swenshuai.xi  */
84*53ee8cc1Swenshuai.xi #define	LIST_HEAD(name, type)						\
85*53ee8cc1Swenshuai.xi struct name {								\
86*53ee8cc1Swenshuai.xi 	struct type *lh_first;	/* first element */			\
87*53ee8cc1Swenshuai.xi }
88*53ee8cc1Swenshuai.xi 
89*53ee8cc1Swenshuai.xi #define	LIST_HEAD_INITIALIZER(head)					\
90*53ee8cc1Swenshuai.xi 	{ NULL }
91*53ee8cc1Swenshuai.xi 
92*53ee8cc1Swenshuai.xi #define	LIST_ENTRY(type)						\
93*53ee8cc1Swenshuai.xi struct {								\
94*53ee8cc1Swenshuai.xi 	struct type *le_next;	/* next element */			\
95*53ee8cc1Swenshuai.xi 	struct type **le_prev;	/* address of previous next element */	\
96*53ee8cc1Swenshuai.xi }
97*53ee8cc1Swenshuai.xi 
98*53ee8cc1Swenshuai.xi /*
99*53ee8cc1Swenshuai.xi  * List functions.
100*53ee8cc1Swenshuai.xi  */
101*53ee8cc1Swenshuai.xi #define	LIST_INIT(head) do {						\
102*53ee8cc1Swenshuai.xi 	(head)->lh_first = NULL;					\
103*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
104*53ee8cc1Swenshuai.xi 
105*53ee8cc1Swenshuai.xi #define	LIST_INSERT_AFTER(listelm, elm, field) do {			\
106*53ee8cc1Swenshuai.xi 	if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)	\
107*53ee8cc1Swenshuai.xi 		(listelm)->field.le_next->field.le_prev =		\
108*53ee8cc1Swenshuai.xi 		    &(elm)->field.le_next;				\
109*53ee8cc1Swenshuai.xi 	(listelm)->field.le_next = (elm);				\
110*53ee8cc1Swenshuai.xi 	(elm)->field.le_prev = &(listelm)->field.le_next;		\
111*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
112*53ee8cc1Swenshuai.xi 
113*53ee8cc1Swenshuai.xi #define	LIST_INSERT_BEFORE(listelm, elm, field) do {			\
114*53ee8cc1Swenshuai.xi 	(elm)->field.le_prev = (listelm)->field.le_prev;		\
115*53ee8cc1Swenshuai.xi 	(elm)->field.le_next = (listelm);				\
116*53ee8cc1Swenshuai.xi 	*(listelm)->field.le_prev = (elm);				\
117*53ee8cc1Swenshuai.xi 	(listelm)->field.le_prev = &(elm)->field.le_next;		\
118*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
119*53ee8cc1Swenshuai.xi 
120*53ee8cc1Swenshuai.xi #define	LIST_INSERT_HEAD(head, elm, field) do {				\
121*53ee8cc1Swenshuai.xi 	if (((elm)->field.le_next = (head)->lh_first) != NULL)		\
122*53ee8cc1Swenshuai.xi 		(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
123*53ee8cc1Swenshuai.xi 	(head)->lh_first = (elm);					\
124*53ee8cc1Swenshuai.xi 	(elm)->field.le_prev = &(head)->lh_first;			\
125*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
126*53ee8cc1Swenshuai.xi 
127*53ee8cc1Swenshuai.xi #define	LIST_REMOVE(elm, field) do {					\
128*53ee8cc1Swenshuai.xi 	if ((elm)->field.le_next != NULL)				\
129*53ee8cc1Swenshuai.xi 		(elm)->field.le_next->field.le_prev = 			\
130*53ee8cc1Swenshuai.xi 		    (elm)->field.le_prev;				\
131*53ee8cc1Swenshuai.xi 	*(elm)->field.le_prev = (elm)->field.le_next;			\
132*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
133*53ee8cc1Swenshuai.xi 
134*53ee8cc1Swenshuai.xi #define	LIST_FOREACH(var, head, field)					\
135*53ee8cc1Swenshuai.xi 	for ((var) = ((head)->lh_first);				\
136*53ee8cc1Swenshuai.xi 		(var);							\
137*53ee8cc1Swenshuai.xi 		(var) = ((var)->field.le_next))
138*53ee8cc1Swenshuai.xi 
139*53ee8cc1Swenshuai.xi /*
140*53ee8cc1Swenshuai.xi  * List access methods.
141*53ee8cc1Swenshuai.xi  */
142*53ee8cc1Swenshuai.xi #define	LIST_EMPTY(head)		((head)->lh_first == NULL)
143*53ee8cc1Swenshuai.xi #define	LIST_FIRST(head)		((head)->lh_first)
144*53ee8cc1Swenshuai.xi #define	LIST_NEXT(elm, field)		((elm)->field.le_next)
145*53ee8cc1Swenshuai.xi 
146*53ee8cc1Swenshuai.xi 
147*53ee8cc1Swenshuai.xi /*
148*53ee8cc1Swenshuai.xi  * Singly-linked List definitions.
149*53ee8cc1Swenshuai.xi  */
150*53ee8cc1Swenshuai.xi #define	SLIST_HEAD(name, type)						\
151*53ee8cc1Swenshuai.xi struct name {								\
152*53ee8cc1Swenshuai.xi 	struct type *slh_first;	/* first element */			\
153*53ee8cc1Swenshuai.xi }
154*53ee8cc1Swenshuai.xi 
155*53ee8cc1Swenshuai.xi #define	SLIST_HEAD_INITIALIZER(head)					\
156*53ee8cc1Swenshuai.xi 	{ NULL }
157*53ee8cc1Swenshuai.xi 
158*53ee8cc1Swenshuai.xi #define	SLIST_ENTRY(type)						\
159*53ee8cc1Swenshuai.xi struct {								\
160*53ee8cc1Swenshuai.xi 	struct type *sle_next;	/* next element */			\
161*53ee8cc1Swenshuai.xi }
162*53ee8cc1Swenshuai.xi 
163*53ee8cc1Swenshuai.xi /*
164*53ee8cc1Swenshuai.xi  * Singly-linked List functions.
165*53ee8cc1Swenshuai.xi  */
166*53ee8cc1Swenshuai.xi #define	SLIST_INIT(head) do {						\
167*53ee8cc1Swenshuai.xi 	(head)->slh_first = NULL;					\
168*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
169*53ee8cc1Swenshuai.xi 
170*53ee8cc1Swenshuai.xi #define	SLIST_INSERT_AFTER(slistelm, elm, field) do {			\
171*53ee8cc1Swenshuai.xi 	(elm)->field.sle_next = (slistelm)->field.sle_next;		\
172*53ee8cc1Swenshuai.xi 	(slistelm)->field.sle_next = (elm);				\
173*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
174*53ee8cc1Swenshuai.xi 
175*53ee8cc1Swenshuai.xi #define	SLIST_INSERT_HEAD(head, elm, field) do {			\
176*53ee8cc1Swenshuai.xi 	(elm)->field.sle_next = (head)->slh_first;			\
177*53ee8cc1Swenshuai.xi 	(head)->slh_first = (elm);					\
178*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
179*53ee8cc1Swenshuai.xi 
180*53ee8cc1Swenshuai.xi #define	SLIST_REMOVE_HEAD(head, field) do {				\
181*53ee8cc1Swenshuai.xi 	(head)->slh_first = (head)->slh_first->field.sle_next;		\
182*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
183*53ee8cc1Swenshuai.xi 
184*53ee8cc1Swenshuai.xi #define	SLIST_REMOVE(head, elm, type, field) do {			\
185*53ee8cc1Swenshuai.xi 	if ((head)->slh_first == (elm)) {				\
186*53ee8cc1Swenshuai.xi 		SLIST_REMOVE_HEAD((head), field);			\
187*53ee8cc1Swenshuai.xi 	}								\
188*53ee8cc1Swenshuai.xi 	else {								\
189*53ee8cc1Swenshuai.xi 		struct type *curelm = (head)->slh_first;		\
190*53ee8cc1Swenshuai.xi 		while(curelm->field.sle_next != (elm))			\
191*53ee8cc1Swenshuai.xi 			curelm = curelm->field.sle_next;		\
192*53ee8cc1Swenshuai.xi 		curelm->field.sle_next =				\
193*53ee8cc1Swenshuai.xi 		    curelm->field.sle_next->field.sle_next;		\
194*53ee8cc1Swenshuai.xi 	}								\
195*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
196*53ee8cc1Swenshuai.xi 
197*53ee8cc1Swenshuai.xi #define	SLIST_FOREACH(var, head, field)					\
198*53ee8cc1Swenshuai.xi 	for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
199*53ee8cc1Swenshuai.xi 
200*53ee8cc1Swenshuai.xi /*
201*53ee8cc1Swenshuai.xi  * Singly-linked List access methods.
202*53ee8cc1Swenshuai.xi  */
203*53ee8cc1Swenshuai.xi #define	SLIST_EMPTY(head)	((head)->slh_first == NULL)
204*53ee8cc1Swenshuai.xi #define	SLIST_FIRST(head)	((head)->slh_first)
205*53ee8cc1Swenshuai.xi #define	SLIST_NEXT(elm, field)	((elm)->field.sle_next)
206*53ee8cc1Swenshuai.xi 
207*53ee8cc1Swenshuai.xi 
208*53ee8cc1Swenshuai.xi /*
209*53ee8cc1Swenshuai.xi  * Singly-linked Tail queue declarations.
210*53ee8cc1Swenshuai.xi  */
211*53ee8cc1Swenshuai.xi #define	STAILQ_HEAD(name, type)					\
212*53ee8cc1Swenshuai.xi struct name {								\
213*53ee8cc1Swenshuai.xi 	struct type *stqh_first;	/* first element */			\
214*53ee8cc1Swenshuai.xi 	struct type **stqh_last;	/* addr of last next element */		\
215*53ee8cc1Swenshuai.xi }
216*53ee8cc1Swenshuai.xi 
217*53ee8cc1Swenshuai.xi #define	STAILQ_HEAD_INITIALIZER(head)					\
218*53ee8cc1Swenshuai.xi 	{ NULL, &(head).stqh_first }
219*53ee8cc1Swenshuai.xi 
220*53ee8cc1Swenshuai.xi #define	STAILQ_ENTRY(type)						\
221*53ee8cc1Swenshuai.xi struct {								\
222*53ee8cc1Swenshuai.xi 	struct type *stqe_next;	/* next element */			\
223*53ee8cc1Swenshuai.xi }
224*53ee8cc1Swenshuai.xi 
225*53ee8cc1Swenshuai.xi /*
226*53ee8cc1Swenshuai.xi  * Singly-linked Tail queue functions.
227*53ee8cc1Swenshuai.xi  */
228*53ee8cc1Swenshuai.xi #define	STAILQ_INIT(head) do {						\
229*53ee8cc1Swenshuai.xi 	(head)->stqh_first = NULL;					\
230*53ee8cc1Swenshuai.xi 	(head)->stqh_last = &(head)->stqh_first;				\
231*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
232*53ee8cc1Swenshuai.xi 
233*53ee8cc1Swenshuai.xi #define	STAILQ_INSERT_HEAD(head, elm, field) do {			\
234*53ee8cc1Swenshuai.xi 	if (((elm)->field.stqe_next = (head)->stqh_first) == NULL)	\
235*53ee8cc1Swenshuai.xi 		(head)->stqh_last = &(elm)->field.stqe_next;		\
236*53ee8cc1Swenshuai.xi 	(head)->stqh_first = (elm);					\
237*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
238*53ee8cc1Swenshuai.xi 
239*53ee8cc1Swenshuai.xi #define	STAILQ_INSERT_TAIL(head, elm, field) do {			\
240*53ee8cc1Swenshuai.xi 	(elm)->field.stqe_next = NULL;					\
241*53ee8cc1Swenshuai.xi 	*(head)->stqh_last = (elm);					\
242*53ee8cc1Swenshuai.xi 	(head)->stqh_last = &(elm)->field.stqe_next;			\
243*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
244*53ee8cc1Swenshuai.xi 
245*53ee8cc1Swenshuai.xi #define	STAILQ_INSERT_AFTER(head, listelm, elm, field) do {		\
246*53ee8cc1Swenshuai.xi 	if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\
247*53ee8cc1Swenshuai.xi 		(head)->stqh_last = &(elm)->field.stqe_next;		\
248*53ee8cc1Swenshuai.xi 	(listelm)->field.stqe_next = (elm);				\
249*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
250*53ee8cc1Swenshuai.xi 
251*53ee8cc1Swenshuai.xi #define	STAILQ_REMOVE_HEAD(head, field) do {				\
252*53ee8cc1Swenshuai.xi 	if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == NULL) \
253*53ee8cc1Swenshuai.xi 		(head)->stqh_last = &(head)->stqh_first;			\
254*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
255*53ee8cc1Swenshuai.xi 
256*53ee8cc1Swenshuai.xi #define	STAILQ_REMOVE(head, elm, type, field) do {			\
257*53ee8cc1Swenshuai.xi 	if ((head)->stqh_first == (elm)) {				\
258*53ee8cc1Swenshuai.xi 		STAILQ_REMOVE_HEAD((head), field);			\
259*53ee8cc1Swenshuai.xi 	} else {							\
260*53ee8cc1Swenshuai.xi 		struct type *curelm = (head)->stqh_first;		\
261*53ee8cc1Swenshuai.xi 		while (curelm->field.stqe_next != (elm))			\
262*53ee8cc1Swenshuai.xi 			curelm = curelm->field.stqe_next;		\
263*53ee8cc1Swenshuai.xi 		if ((curelm->field.stqe_next =				\
264*53ee8cc1Swenshuai.xi 			curelm->field.stqe_next->field.stqe_next) == NULL) \
265*53ee8cc1Swenshuai.xi 			    (head)->stqh_last = &(curelm)->field.stqe_next; \
266*53ee8cc1Swenshuai.xi 	}								\
267*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
268*53ee8cc1Swenshuai.xi 
269*53ee8cc1Swenshuai.xi #define	STAILQ_FOREACH(var, head, field)				\
270*53ee8cc1Swenshuai.xi 	for ((var) = ((head)->stqh_first);				\
271*53ee8cc1Swenshuai.xi 		(var);							\
272*53ee8cc1Swenshuai.xi 		(var) = ((var)->field.stqe_next))
273*53ee8cc1Swenshuai.xi 
274*53ee8cc1Swenshuai.xi #define	STAILQ_CONCAT(head1, head2) do {				\
275*53ee8cc1Swenshuai.xi 	if (!STAILQ_EMPTY((head2))) {					\
276*53ee8cc1Swenshuai.xi 		*(head1)->stqh_last = (head2)->stqh_first;		\
277*53ee8cc1Swenshuai.xi 		(head1)->stqh_last = (head2)->stqh_last;		\
278*53ee8cc1Swenshuai.xi 		STAILQ_INIT((head2));					\
279*53ee8cc1Swenshuai.xi 	}								\
280*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
281*53ee8cc1Swenshuai.xi 
282*53ee8cc1Swenshuai.xi /*
283*53ee8cc1Swenshuai.xi  * Singly-linked Tail queue access methods.
284*53ee8cc1Swenshuai.xi  */
285*53ee8cc1Swenshuai.xi #define	STAILQ_EMPTY(head)	((head)->stqh_first == NULL)
286*53ee8cc1Swenshuai.xi #define	STAILQ_FIRST(head)	((head)->stqh_first)
287*53ee8cc1Swenshuai.xi #define	STAILQ_NEXT(elm, field)	((elm)->field.stqe_next)
288*53ee8cc1Swenshuai.xi 
289*53ee8cc1Swenshuai.xi 
290*53ee8cc1Swenshuai.xi /*
291*53ee8cc1Swenshuai.xi  * Simple queue definitions.
292*53ee8cc1Swenshuai.xi  */
293*53ee8cc1Swenshuai.xi #define	SIMPLEQ_HEAD(name, type)					\
294*53ee8cc1Swenshuai.xi struct name {								\
295*53ee8cc1Swenshuai.xi 	struct type *sqh_first;	/* first element */			\
296*53ee8cc1Swenshuai.xi 	struct type **sqh_last;	/* addr of last next element */		\
297*53ee8cc1Swenshuai.xi }
298*53ee8cc1Swenshuai.xi 
299*53ee8cc1Swenshuai.xi #define	SIMPLEQ_HEAD_INITIALIZER(head)					\
300*53ee8cc1Swenshuai.xi 	{ NULL, &(head).sqh_first }
301*53ee8cc1Swenshuai.xi 
302*53ee8cc1Swenshuai.xi #define	SIMPLEQ_ENTRY(type)						\
303*53ee8cc1Swenshuai.xi struct {								\
304*53ee8cc1Swenshuai.xi 	struct type *sqe_next;	/* next element */			\
305*53ee8cc1Swenshuai.xi }
306*53ee8cc1Swenshuai.xi 
307*53ee8cc1Swenshuai.xi /*
308*53ee8cc1Swenshuai.xi  * Simple queue functions.
309*53ee8cc1Swenshuai.xi  */
310*53ee8cc1Swenshuai.xi #define	SIMPLEQ_INIT(head) do {						\
311*53ee8cc1Swenshuai.xi 	(head)->sqh_first = NULL;					\
312*53ee8cc1Swenshuai.xi 	(head)->sqh_last = &(head)->sqh_first;				\
313*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
314*53ee8cc1Swenshuai.xi 
315*53ee8cc1Swenshuai.xi #define	SIMPLEQ_INSERT_HEAD(head, elm, field) do {			\
316*53ee8cc1Swenshuai.xi 	if (((elm)->field.sqe_next = (head)->sqh_first) == NULL)	\
317*53ee8cc1Swenshuai.xi 		(head)->sqh_last = &(elm)->field.sqe_next;		\
318*53ee8cc1Swenshuai.xi 	(head)->sqh_first = (elm);					\
319*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
320*53ee8cc1Swenshuai.xi 
321*53ee8cc1Swenshuai.xi #define	SIMPLEQ_INSERT_TAIL(head, elm, field) do {			\
322*53ee8cc1Swenshuai.xi 	(elm)->field.sqe_next = NULL;					\
323*53ee8cc1Swenshuai.xi 	*(head)->sqh_last = (elm);					\
324*53ee8cc1Swenshuai.xi 	(head)->sqh_last = &(elm)->field.sqe_next;			\
325*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
326*53ee8cc1Swenshuai.xi 
327*53ee8cc1Swenshuai.xi #define	SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do {		\
328*53ee8cc1Swenshuai.xi 	if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
329*53ee8cc1Swenshuai.xi 		(head)->sqh_last = &(elm)->field.sqe_next;		\
330*53ee8cc1Swenshuai.xi 	(listelm)->field.sqe_next = (elm);				\
331*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
332*53ee8cc1Swenshuai.xi 
333*53ee8cc1Swenshuai.xi #define	SIMPLEQ_REMOVE_HEAD(head, field) do {				\
334*53ee8cc1Swenshuai.xi 	if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
335*53ee8cc1Swenshuai.xi 		(head)->sqh_last = &(head)->sqh_first;			\
336*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
337*53ee8cc1Swenshuai.xi 
338*53ee8cc1Swenshuai.xi #define	SIMPLEQ_REMOVE(head, elm, type, field) do {			\
339*53ee8cc1Swenshuai.xi 	if ((head)->sqh_first == (elm)) {				\
340*53ee8cc1Swenshuai.xi 		SIMPLEQ_REMOVE_HEAD((head), field);			\
341*53ee8cc1Swenshuai.xi 	} else {							\
342*53ee8cc1Swenshuai.xi 		struct type *curelm = (head)->sqh_first;		\
343*53ee8cc1Swenshuai.xi 		while (curelm->field.sqe_next != (elm))			\
344*53ee8cc1Swenshuai.xi 			curelm = curelm->field.sqe_next;		\
345*53ee8cc1Swenshuai.xi 		if ((curelm->field.sqe_next =				\
346*53ee8cc1Swenshuai.xi 			curelm->field.sqe_next->field.sqe_next) == NULL) \
347*53ee8cc1Swenshuai.xi 			    (head)->sqh_last = &(curelm)->field.sqe_next; \
348*53ee8cc1Swenshuai.xi 	}								\
349*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
350*53ee8cc1Swenshuai.xi 
351*53ee8cc1Swenshuai.xi #define	SIMPLEQ_FOREACH(var, head, field)				\
352*53ee8cc1Swenshuai.xi 	for ((var) = ((head)->sqh_first);				\
353*53ee8cc1Swenshuai.xi 		(var);							\
354*53ee8cc1Swenshuai.xi 		(var) = ((var)->field.sqe_next))
355*53ee8cc1Swenshuai.xi 
356*53ee8cc1Swenshuai.xi /*
357*53ee8cc1Swenshuai.xi  * Simple queue access methods.
358*53ee8cc1Swenshuai.xi  */
359*53ee8cc1Swenshuai.xi #define	SIMPLEQ_EMPTY(head)		((head)->sqh_first == NULL)
360*53ee8cc1Swenshuai.xi #define	SIMPLEQ_FIRST(head)		((head)->sqh_first)
361*53ee8cc1Swenshuai.xi #define	SIMPLEQ_NEXT(elm, field)	((elm)->field.sqe_next)
362*53ee8cc1Swenshuai.xi 
363*53ee8cc1Swenshuai.xi 
364*53ee8cc1Swenshuai.xi /*
365*53ee8cc1Swenshuai.xi  * Tail queue definitions.
366*53ee8cc1Swenshuai.xi  */
367*53ee8cc1Swenshuai.xi #define	_TAILQ_HEAD(name, type, qual)					\
368*53ee8cc1Swenshuai.xi struct name {								\
369*53ee8cc1Swenshuai.xi 	qual type *tqh_first;		/* first element */		\
370*53ee8cc1Swenshuai.xi 	qual type *qual *tqh_last;	/* addr of last next element */	\
371*53ee8cc1Swenshuai.xi }
372*53ee8cc1Swenshuai.xi #define TAILQ_HEAD(name, type)	_TAILQ_HEAD(name, struct type,)
373*53ee8cc1Swenshuai.xi 
374*53ee8cc1Swenshuai.xi #define	TAILQ_HEAD_INITIALIZER(head)					\
375*53ee8cc1Swenshuai.xi 	{ NULL, &(head).tqh_first }
376*53ee8cc1Swenshuai.xi 
377*53ee8cc1Swenshuai.xi #define	_TAILQ_ENTRY(type, qual)					\
378*53ee8cc1Swenshuai.xi struct {								\
379*53ee8cc1Swenshuai.xi 	qual type *tqe_next;		/* next element */		\
380*53ee8cc1Swenshuai.xi 	qual type *qual *tqe_prev;	/* address of previous next element */\
381*53ee8cc1Swenshuai.xi }
382*53ee8cc1Swenshuai.xi #define TAILQ_ENTRY(type)	_TAILQ_ENTRY(struct type,)
383*53ee8cc1Swenshuai.xi 
384*53ee8cc1Swenshuai.xi /*
385*53ee8cc1Swenshuai.xi  * Tail queue functions.
386*53ee8cc1Swenshuai.xi  */
387*53ee8cc1Swenshuai.xi #define	TAILQ_INIT(head) do {						\
388*53ee8cc1Swenshuai.xi 	(head)->tqh_first = NULL;					\
389*53ee8cc1Swenshuai.xi 	(head)->tqh_last = &(head)->tqh_first;				\
390*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
391*53ee8cc1Swenshuai.xi 
392*53ee8cc1Swenshuai.xi #define	TAILQ_INSERT_HEAD(head, elm, field) do {			\
393*53ee8cc1Swenshuai.xi 	if (((elm)->field.tqe_next = (head)->tqh_first) != NULL)	\
394*53ee8cc1Swenshuai.xi 		(head)->tqh_first->field.tqe_prev =			\
395*53ee8cc1Swenshuai.xi 		    &(elm)->field.tqe_next;				\
396*53ee8cc1Swenshuai.xi 	else								\
397*53ee8cc1Swenshuai.xi 		(head)->tqh_last = &(elm)->field.tqe_next;		\
398*53ee8cc1Swenshuai.xi 	(head)->tqh_first = (elm);					\
399*53ee8cc1Swenshuai.xi 	(elm)->field.tqe_prev = &(head)->tqh_first;			\
400*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
401*53ee8cc1Swenshuai.xi 
402*53ee8cc1Swenshuai.xi #define	TAILQ_INSERT_TAIL(head, elm, field) do {			\
403*53ee8cc1Swenshuai.xi 	(elm)->field.tqe_next = NULL;					\
404*53ee8cc1Swenshuai.xi 	(elm)->field.tqe_prev = (head)->tqh_last;			\
405*53ee8cc1Swenshuai.xi 	*(head)->tqh_last = (elm);					\
406*53ee8cc1Swenshuai.xi 	(head)->tqh_last = &(elm)->field.tqe_next;			\
407*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
408*53ee8cc1Swenshuai.xi 
409*53ee8cc1Swenshuai.xi #define	TAILQ_INSERT_AFTER(head, listelm, elm, field) do {		\
410*53ee8cc1Swenshuai.xi 	if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
411*53ee8cc1Swenshuai.xi 		(elm)->field.tqe_next->field.tqe_prev = 		\
412*53ee8cc1Swenshuai.xi 		    &(elm)->field.tqe_next;				\
413*53ee8cc1Swenshuai.xi 	else								\
414*53ee8cc1Swenshuai.xi 		(head)->tqh_last = &(elm)->field.tqe_next;		\
415*53ee8cc1Swenshuai.xi 	(listelm)->field.tqe_next = (elm);				\
416*53ee8cc1Swenshuai.xi 	(elm)->field.tqe_prev = &(listelm)->field.tqe_next;		\
417*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
418*53ee8cc1Swenshuai.xi 
419*53ee8cc1Swenshuai.xi #define	TAILQ_INSERT_BEFORE(listelm, elm, field) do {			\
420*53ee8cc1Swenshuai.xi 	(elm)->field.tqe_prev = (listelm)->field.tqe_prev;		\
421*53ee8cc1Swenshuai.xi 	(elm)->field.tqe_next = (listelm);				\
422*53ee8cc1Swenshuai.xi 	*(listelm)->field.tqe_prev = (elm);				\
423*53ee8cc1Swenshuai.xi 	(listelm)->field.tqe_prev = &(elm)->field.tqe_next;		\
424*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
425*53ee8cc1Swenshuai.xi 
426*53ee8cc1Swenshuai.xi #define	TAILQ_REMOVE(head, elm, field) do {				\
427*53ee8cc1Swenshuai.xi 	if (((elm)->field.tqe_next) != NULL)				\
428*53ee8cc1Swenshuai.xi 		(elm)->field.tqe_next->field.tqe_prev = 		\
429*53ee8cc1Swenshuai.xi 		    (elm)->field.tqe_prev;				\
430*53ee8cc1Swenshuai.xi 	else								\
431*53ee8cc1Swenshuai.xi 		(head)->tqh_last = (elm)->field.tqe_prev;		\
432*53ee8cc1Swenshuai.xi 	*(elm)->field.tqe_prev = (elm)->field.tqe_next;			\
433*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
434*53ee8cc1Swenshuai.xi 
435*53ee8cc1Swenshuai.xi #define	TAILQ_FOREACH(var, head, field)					\
436*53ee8cc1Swenshuai.xi 	for ((var) = ((head)->tqh_first);				\
437*53ee8cc1Swenshuai.xi 		(var);							\
438*53ee8cc1Swenshuai.xi 		(var) = ((var)->field.tqe_next))
439*53ee8cc1Swenshuai.xi 
440*53ee8cc1Swenshuai.xi #define	TAILQ_FOREACH_REVERSE(var, head, headname, field)		\
441*53ee8cc1Swenshuai.xi 	for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last));	\
442*53ee8cc1Swenshuai.xi 		(var);							\
443*53ee8cc1Swenshuai.xi 		(var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
444*53ee8cc1Swenshuai.xi 
445*53ee8cc1Swenshuai.xi #define	TAILQ_CONCAT(head1, head2, field) do {				\
446*53ee8cc1Swenshuai.xi 	if (!TAILQ_EMPTY(head2)) {					\
447*53ee8cc1Swenshuai.xi 		*(head1)->tqh_last = (head2)->tqh_first;		\
448*53ee8cc1Swenshuai.xi 		(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last;	\
449*53ee8cc1Swenshuai.xi 		(head1)->tqh_last = (head2)->tqh_last;			\
450*53ee8cc1Swenshuai.xi 		TAILQ_INIT((head2));					\
451*53ee8cc1Swenshuai.xi 	}								\
452*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
453*53ee8cc1Swenshuai.xi 
454*53ee8cc1Swenshuai.xi /*
455*53ee8cc1Swenshuai.xi  * Tail queue access methods.
456*53ee8cc1Swenshuai.xi  */
457*53ee8cc1Swenshuai.xi #define	TAILQ_EMPTY(head)		((head)->tqh_first == NULL)
458*53ee8cc1Swenshuai.xi #define	TAILQ_FIRST(head)		((head)->tqh_first)
459*53ee8cc1Swenshuai.xi #define	TAILQ_NEXT(elm, field)		((elm)->field.tqe_next)
460*53ee8cc1Swenshuai.xi 
461*53ee8cc1Swenshuai.xi #define	TAILQ_LAST(head, headname) \
462*53ee8cc1Swenshuai.xi 	(*(((struct headname *)((head)->tqh_last))->tqh_last))
463*53ee8cc1Swenshuai.xi #define	TAILQ_PREV(elm, headname, field) \
464*53ee8cc1Swenshuai.xi 	(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
465*53ee8cc1Swenshuai.xi 
466*53ee8cc1Swenshuai.xi 
467*53ee8cc1Swenshuai.xi /*
468*53ee8cc1Swenshuai.xi  * Circular queue definitions.
469*53ee8cc1Swenshuai.xi  */
470*53ee8cc1Swenshuai.xi #define	CIRCLEQ_HEAD(name, type)					\
471*53ee8cc1Swenshuai.xi struct name {								\
472*53ee8cc1Swenshuai.xi 	struct type *cqh_first;		/* first element */		\
473*53ee8cc1Swenshuai.xi 	struct type *cqh_last;		/* last element */		\
474*53ee8cc1Swenshuai.xi }
475*53ee8cc1Swenshuai.xi 
476*53ee8cc1Swenshuai.xi #define	CIRCLEQ_HEAD_INITIALIZER(head)					\
477*53ee8cc1Swenshuai.xi 	{ (void *)&head, (void *)&head }
478*53ee8cc1Swenshuai.xi 
479*53ee8cc1Swenshuai.xi #define	CIRCLEQ_ENTRY(type)						\
480*53ee8cc1Swenshuai.xi struct {								\
481*53ee8cc1Swenshuai.xi 	struct type *cqe_next;		/* next element */		\
482*53ee8cc1Swenshuai.xi 	struct type *cqe_prev;		/* previous element */		\
483*53ee8cc1Swenshuai.xi }
484*53ee8cc1Swenshuai.xi 
485*53ee8cc1Swenshuai.xi /*
486*53ee8cc1Swenshuai.xi  * Circular queue functions.
487*53ee8cc1Swenshuai.xi  */
488*53ee8cc1Swenshuai.xi #define	CIRCLEQ_INIT(head) do {						\
489*53ee8cc1Swenshuai.xi 	(head)->cqh_first = (void *)(head);				\
490*53ee8cc1Swenshuai.xi 	(head)->cqh_last = (void *)(head);				\
491*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
492*53ee8cc1Swenshuai.xi 
493*53ee8cc1Swenshuai.xi #define	CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do {		\
494*53ee8cc1Swenshuai.xi 	(elm)->field.cqe_next = (listelm)->field.cqe_next;		\
495*53ee8cc1Swenshuai.xi 	(elm)->field.cqe_prev = (listelm);				\
496*53ee8cc1Swenshuai.xi 	if ((listelm)->field.cqe_next == (void *)(head))		\
497*53ee8cc1Swenshuai.xi 		(head)->cqh_last = (elm);				\
498*53ee8cc1Swenshuai.xi 	else								\
499*53ee8cc1Swenshuai.xi 		(listelm)->field.cqe_next->field.cqe_prev = (elm);	\
500*53ee8cc1Swenshuai.xi 	(listelm)->field.cqe_next = (elm);				\
501*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
502*53ee8cc1Swenshuai.xi 
503*53ee8cc1Swenshuai.xi #define	CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do {		\
504*53ee8cc1Swenshuai.xi 	(elm)->field.cqe_next = (listelm);				\
505*53ee8cc1Swenshuai.xi 	(elm)->field.cqe_prev = (listelm)->field.cqe_prev;		\
506*53ee8cc1Swenshuai.xi 	if ((listelm)->field.cqe_prev == (void *)(head))		\
507*53ee8cc1Swenshuai.xi 		(head)->cqh_first = (elm);				\
508*53ee8cc1Swenshuai.xi 	else								\
509*53ee8cc1Swenshuai.xi 		(listelm)->field.cqe_prev->field.cqe_next = (elm);	\
510*53ee8cc1Swenshuai.xi 	(listelm)->field.cqe_prev = (elm);				\
511*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
512*53ee8cc1Swenshuai.xi 
513*53ee8cc1Swenshuai.xi #define	CIRCLEQ_INSERT_HEAD(head, elm, field) do {			\
514*53ee8cc1Swenshuai.xi 	(elm)->field.cqe_next = (head)->cqh_first;			\
515*53ee8cc1Swenshuai.xi 	(elm)->field.cqe_prev = (void *)(head);				\
516*53ee8cc1Swenshuai.xi 	if ((head)->cqh_last == (void *)(head))				\
517*53ee8cc1Swenshuai.xi 		(head)->cqh_last = (elm);				\
518*53ee8cc1Swenshuai.xi 	else								\
519*53ee8cc1Swenshuai.xi 		(head)->cqh_first->field.cqe_prev = (elm);		\
520*53ee8cc1Swenshuai.xi 	(head)->cqh_first = (elm);					\
521*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
522*53ee8cc1Swenshuai.xi 
523*53ee8cc1Swenshuai.xi #define	CIRCLEQ_INSERT_TAIL(head, elm, field) do {			\
524*53ee8cc1Swenshuai.xi 	(elm)->field.cqe_next = (void *)(head);				\
525*53ee8cc1Swenshuai.xi 	(elm)->field.cqe_prev = (head)->cqh_last;			\
526*53ee8cc1Swenshuai.xi 	if ((head)->cqh_first == (void *)(head))			\
527*53ee8cc1Swenshuai.xi 		(head)->cqh_first = (elm);				\
528*53ee8cc1Swenshuai.xi 	else								\
529*53ee8cc1Swenshuai.xi 		(head)->cqh_last->field.cqe_next = (elm);		\
530*53ee8cc1Swenshuai.xi 	(head)->cqh_last = (elm);					\
531*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
532*53ee8cc1Swenshuai.xi 
533*53ee8cc1Swenshuai.xi #define	CIRCLEQ_REMOVE(head, elm, field) do {				\
534*53ee8cc1Swenshuai.xi 	if ((elm)->field.cqe_next == (void *)(head))			\
535*53ee8cc1Swenshuai.xi 		(head)->cqh_last = (elm)->field.cqe_prev;		\
536*53ee8cc1Swenshuai.xi 	else								\
537*53ee8cc1Swenshuai.xi 		(elm)->field.cqe_next->field.cqe_prev =			\
538*53ee8cc1Swenshuai.xi 		    (elm)->field.cqe_prev;				\
539*53ee8cc1Swenshuai.xi 	if ((elm)->field.cqe_prev == (void *)(head))			\
540*53ee8cc1Swenshuai.xi 		(head)->cqh_first = (elm)->field.cqe_next;		\
541*53ee8cc1Swenshuai.xi 	else								\
542*53ee8cc1Swenshuai.xi 		(elm)->field.cqe_prev->field.cqe_next =			\
543*53ee8cc1Swenshuai.xi 		    (elm)->field.cqe_next;				\
544*53ee8cc1Swenshuai.xi } while (/*CONSTCOND*/0)
545*53ee8cc1Swenshuai.xi 
546*53ee8cc1Swenshuai.xi #define	CIRCLEQ_FOREACH(var, head, field)				\
547*53ee8cc1Swenshuai.xi 	for ((var) = ((head)->cqh_first);				\
548*53ee8cc1Swenshuai.xi 		(var) != (const void *)(head);				\
549*53ee8cc1Swenshuai.xi 		(var) = ((var)->field.cqe_next))
550*53ee8cc1Swenshuai.xi 
551*53ee8cc1Swenshuai.xi #define	CIRCLEQ_FOREACH_REVERSE(var, head, field)			\
552*53ee8cc1Swenshuai.xi 	for ((var) = ((head)->cqh_last);				\
553*53ee8cc1Swenshuai.xi 		(var) != (const void *)(head);				\
554*53ee8cc1Swenshuai.xi 		(var) = ((var)->field.cqe_prev))
555*53ee8cc1Swenshuai.xi 
556*53ee8cc1Swenshuai.xi /*
557*53ee8cc1Swenshuai.xi  * Circular queue access methods.
558*53ee8cc1Swenshuai.xi  */
559*53ee8cc1Swenshuai.xi #define	CIRCLEQ_EMPTY(head)		((head)->cqh_first == (void *)(head))
560*53ee8cc1Swenshuai.xi #define	CIRCLEQ_FIRST(head)		((head)->cqh_first)
561*53ee8cc1Swenshuai.xi #define	CIRCLEQ_LAST(head)		((head)->cqh_last)
562*53ee8cc1Swenshuai.xi #define	CIRCLEQ_NEXT(elm, field)	((elm)->field.cqe_next)
563*53ee8cc1Swenshuai.xi #define	CIRCLEQ_PREV(elm, field)	((elm)->field.cqe_prev)
564*53ee8cc1Swenshuai.xi 
565*53ee8cc1Swenshuai.xi #define CIRCLEQ_LOOP_NEXT(head, elm, field)				\
566*53ee8cc1Swenshuai.xi 	(((elm)->field.cqe_next == (void *)(head))			\
567*53ee8cc1Swenshuai.xi 	    ? ((head)->cqh_first)					\
568*53ee8cc1Swenshuai.xi 	    : (elm->field.cqe_next))
569*53ee8cc1Swenshuai.xi #define CIRCLEQ_LOOP_PREV(head, elm, field)				\
570*53ee8cc1Swenshuai.xi 	(((elm)->field.cqe_prev == (void *)(head))			\
571*53ee8cc1Swenshuai.xi 	    ? ((head)->cqh_last)					\
572*53ee8cc1Swenshuai.xi 	    : (elm->field.cqe_prev))
573*53ee8cc1Swenshuai.xi 
574*53ee8cc1Swenshuai.xi #endif	/* sys/queue.h */
575