Blame


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