Blame


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