Blame


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