VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/queue.h@ 28739

Last change on this file since 28739 was 28449, checked in by vboxsync, 15 years ago

NAT: slirp file headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.7 KB
Line 
1/* $Id: queue.h 28449 2010-04-19 09:52:59Z vboxsync $ */
2/** @file
3 * NAT - Queue handling.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22/*
23 * This code is based on:
24 *
25 * Copyright (c) 1991, 1993
26 * The Regents of the University of California. All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 4. Neither the name of the University nor the names of its contributors
37 * may be used to endorse or promote products derived from this software
38 * without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
51 *
52 * @(#)queue.h 8.5 (Berkeley) 8/20/94
53 * $FreeBSD: src/sys/sys/queue.h,v 1.68 2006/10/24 11:20:29 ru Exp $
54 */
55
56#ifndef _SYS_QUEUE_H_
57#define _SYS_QUEUE_H_
58
59#include <iprt/cdefs.h>
60#ifdef RT_OS_WINDOWS
61#ifdef SLIST_ENTRY
62/*Here is a conflict with winnt.h*/
63#undef SLIST_ENTRY
64#endif
65#endif /* RT_OS_WINDOWS */
66
67/*
68 * This file defines four types of data structures: singly-linked lists,
69 * singly-linked tail queues, lists and tail queues.
70 *
71 * A singly-linked list is headed by a single forward pointer. The elements
72 * are singly linked for minimum space and pointer manipulation overhead at
73 * the expense of O(n) removal for arbitrary elements. New elements can be
74 * added to the list after an existing element or at the head of the list.
75 * Elements being removed from the head of the list should use the explicit
76 * macro for this purpose for optimum efficiency. A singly-linked list may
77 * only be traversed in the forward direction. Singly-linked lists are ideal
78 * for applications with large datasets and few or no removals or for
79 * implementing a LIFO queue.
80 *
81 * A singly-linked tail queue is headed by a pair of pointers, one to the
82 * head of the list and the other to the tail of the list. The elements are
83 * singly linked for minimum space and pointer manipulation overhead at the
84 * expense of O(n) removal for arbitrary elements. New elements can be added
85 * to the list after an existing element, at the head of the list, or at the
86 * end of the list. Elements being removed from the head of the tail queue
87 * should use the explicit macro for this purpose for optimum efficiency.
88 * A singly-linked tail queue may only be traversed in the forward direction.
89 * Singly-linked tail queues are ideal for applications with large datasets
90 * and few or no removals or for implementing a FIFO queue.
91 *
92 * A list is headed by a single forward pointer (or an array of forward
93 * pointers for a hash table header). The elements are doubly linked
94 * so that an arbitrary element can be removed without a need to
95 * traverse the list. New elements can be added to the list before
96 * or after an existing element or at the head of the list. A list
97 * may only be traversed in the forward direction.
98 *
99 * A tail queue is headed by a pair of pointers, one to the head of the
100 * list and the other to the tail of the list. The elements are doubly
101 * linked so that an arbitrary element can be removed without a need to
102 * traverse the list. New elements can be added to the list before or
103 * after an existing element, at the head of the list, or at the end of
104 * the list. A tail queue may be traversed in either direction.
105 *
106 * For details on the use of these macros, see the queue(3) manual page.
107 *
108 *
109 * SLIST LIST STAILQ TAILQ
110 * _HEAD + + + +
111 * _HEAD_INITIALIZER + + + +
112 * _ENTRY + + + +
113 * _INIT + + + +
114 * _EMPTY + + + +
115 * _FIRST + + + +
116 * _NEXT + + + +
117 * _PREV - - - +
118 * _LAST - - + +
119 * _FOREACH + + + +
120 * _FOREACH_SAFE + + + +
121 * _FOREACH_REVERSE - - - +
122 * _FOREACH_REVERSE_SAFE - - - +
123 * _INSERT_HEAD + + + +
124 * _INSERT_BEFORE - + - +
125 * _INSERT_AFTER + + + +
126 * _INSERT_TAIL - - + +
127 * _CONCAT - - + +
128 * _REMOVE_HEAD + - + -
129 * _REMOVE + + + +
130 *
131 */
132#ifdef QUEUE_MACRO_DEBUG
133/* Store the last 2 places the queue element or head was altered */
134struct qm_trace {
135 char * lastfile;
136 int lastline;
137 char * prevfile;
138 int prevline;
139};
140
141#define TRACEBUF struct qm_trace trace;
142#define TRASHIT(x) do {(x) = (void *)-1;} while (0)
143
144#define QMD_TRACE_HEAD(head) do { \
145 (head)->trace.prevline = (head)->trace.lastline; \
146 (head)->trace.prevfile = (head)->trace.lastfile; \
147 (head)->trace.lastline = __LINE__; \
148 (head)->trace.lastfile = __FILE__; \
149} while (0)
150
151#define QMD_TRACE_ELEM(elem) do { \
152 (elem)->trace.prevline = (elem)->trace.lastline; \
153 (elem)->trace.prevfile = (elem)->trace.lastfile; \
154 (elem)->trace.lastline = __LINE__; \
155 (elem)->trace.lastfile = __FILE__; \
156} while (0)
157
158#else
159#define QMD_TRACE_ELEM(elem)
160#define QMD_TRACE_HEAD(head)
161#define TRACEBUF
162#define TRASHIT(x)
163#endif /* QUEUE_MACRO_DEBUG */
164
165/*
166 * Singly-linked List declarations.
167 */
168#define SLIST_HEAD(name, type) \
169struct name { \
170 struct type *slh_first; /* first element */ \
171}
172
173#define SLIST_HEAD_INITIALIZER(head) \
174 { NULL }
175
176#define SLIST_ENTRY(type) \
177struct { \
178 struct type *sle_next; /* next element */ \
179}
180
181/*
182 * Singly-linked List functions.
183 */
184#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
185
186#define SLIST_FIRST(head) ((head)->slh_first)
187
188#define SLIST_FOREACH(var, head, field) \
189 for ((var) = SLIST_FIRST((head)); \
190 (var); \
191 (var) = SLIST_NEXT((var), field))
192
193#define SLIST_FOREACH_SAFE(var, head, field, tvar) \
194 for ((var) = SLIST_FIRST((head)); \
195 (var) && ((tvar) = SLIST_NEXT((var), field), 1); \
196 (var) = (tvar))
197
198#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
199 for ((varp) = &SLIST_FIRST((head)); \
200 ((var) = *(varp)) != NULL; \
201 (varp) = &SLIST_NEXT((var), field))
202
203#define SLIST_INIT(head) do { \
204 SLIST_FIRST((head)) = NULL; \
205} while (0)
206
207#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
208 SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \
209 SLIST_NEXT((slistelm), field) = (elm); \
210} while (0)
211
212#define SLIST_INSERT_HEAD(head, elm, field) do { \
213 SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \
214 SLIST_FIRST((head)) = (elm); \
215} while (0)
216
217#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
218
219#define SLIST_REMOVE(head, elm, type, field) do { \
220 if (SLIST_FIRST((head)) == (elm)) { \
221 SLIST_REMOVE_HEAD((head), field); \
222 } \
223 else { \
224 struct type *curelm = SLIST_FIRST((head)); \
225 while (SLIST_NEXT(curelm, field) != (elm)) \
226 curelm = SLIST_NEXT(curelm, field); \
227 SLIST_NEXT(curelm, field) = \
228 SLIST_NEXT(SLIST_NEXT(curelm, field), field); \
229 } \
230 TRASHIT((elm)->field.sle_next); \
231} while (0)
232
233#define SLIST_REMOVE_HEAD(head, field) do { \
234 SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
235} while (0)
236
237/*
238 * Singly-linked Tail queue declarations.
239 */
240#define STAILQ_HEAD(name, type) \
241struct name { \
242 struct type *stqh_first;/* first element */ \
243 struct type **stqh_last;/* addr of last next element */ \
244}
245
246#define STAILQ_HEAD_INITIALIZER(head) \
247 { NULL, &(head).stqh_first }
248
249#define STAILQ_ENTRY(type) \
250struct { \
251 struct type *stqe_next; /* next element */ \
252}
253
254/*
255 * Singly-linked Tail queue functions.
256 */
257#define STAILQ_CONCAT(head1, head2) do { \
258 if (!STAILQ_EMPTY((head2))) { \
259 *(head1)->stqh_last = (head2)->stqh_first; \
260 (head1)->stqh_last = (head2)->stqh_last; \
261 STAILQ_INIT((head2)); \
262 } \
263} while (0)
264
265#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
266
267#define STAILQ_FIRST(head) ((head)->stqh_first)
268
269#define STAILQ_FOREACH(var, head, field) \
270 for((var) = STAILQ_FIRST((head)); \
271 (var); \
272 (var) = STAILQ_NEXT((var), field))
273
274
275#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
276 for ((var) = STAILQ_FIRST((head)); \
277 (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
278 (var) = (tvar))
279
280#define STAILQ_INIT(head) do { \
281 STAILQ_FIRST((head)) = NULL; \
282 (head)->stqh_last = &STAILQ_FIRST((head)); \
283} while (0)
284
285#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \
286 if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
287 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
288 STAILQ_NEXT((tqelm), field) = (elm); \
289} while (0)
290
291#define STAILQ_INSERT_HEAD(head, elm, field) do { \
292 if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
293 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
294 STAILQ_FIRST((head)) = (elm); \
295} while (0)
296
297#define STAILQ_INSERT_TAIL(head, elm, field) do { \
298 STAILQ_NEXT((elm), field) = NULL; \
299 *(head)->stqh_last = (elm); \
300 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
301} while (0)
302
303#define STAILQ_LAST(head, type, field) \
304 (STAILQ_EMPTY((head)) ? \
305 NULL : \
306 ((struct type *)(void *) \
307 ((char *)((head)->stqh_last) - __offsetof(struct type, field))))
308
309#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
310
311#define STAILQ_REMOVE(head, elm, type, field) do { \
312 if (STAILQ_FIRST((head)) == (elm)) { \
313 STAILQ_REMOVE_HEAD((head), field); \
314 } \
315 else { \
316 struct type *curelm = STAILQ_FIRST((head)); \
317 while (STAILQ_NEXT(curelm, field) != (elm)) \
318 curelm = STAILQ_NEXT(curelm, field); \
319 if ((STAILQ_NEXT(curelm, field) = \
320 STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\
321 (head)->stqh_last = &STAILQ_NEXT((curelm), field);\
322 } \
323 TRASHIT((elm)->field.stqe_next); \
324} while (0)
325
326#define STAILQ_REMOVE_HEAD(head, field) do { \
327 if ((STAILQ_FIRST((head)) = \
328 STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \
329 (head)->stqh_last = &STAILQ_FIRST((head)); \
330} while (0)
331
332/*
333 * List declarations.
334 */
335#define LIST_HEAD(name, type) \
336struct name { \
337 struct type *lh_first; /* first element */ \
338}
339
340#define LIST_HEAD_INITIALIZER(head) \
341 { NULL }
342
343#define LIST_ENTRY(type) \
344struct { \
345 struct type *le_next; /* next element */ \
346 struct type **le_prev; /* address of previous next element */ \
347}
348
349/*
350 * List functions.
351 */
352
353#if (defined(_KERNEL) && defined(INVARIANTS))
354#define QMD_LIST_CHECK_HEAD(head, field) do { \
355 if (LIST_FIRST((head)) != NULL && \
356 LIST_FIRST((head))->field.le_prev != \
357 &LIST_FIRST((head))) \
358 panic("Bad list head %p first->prev != head", (head)); \
359} while (0)
360
361#define QMD_LIST_CHECK_NEXT(elm, field) do { \
362 if (LIST_NEXT((elm), field) != NULL && \
363 LIST_NEXT((elm), field)->field.le_prev != \
364 &((elm)->field.le_next)) \
365 panic("Bad link elm %p next->prev != elm", (elm)); \
366} while (0)
367
368#define QMD_LIST_CHECK_PREV(elm, field) do { \
369 if (*(elm)->field.le_prev != (elm)) \
370 panic("Bad link elm %p prev->next != elm", (elm)); \
371} while (0)
372#else
373#define QMD_LIST_CHECK_HEAD(head, field)
374#define QMD_LIST_CHECK_NEXT(elm, field)
375#define QMD_LIST_CHECK_PREV(elm, field)
376#endif /* (_KERNEL && INVARIANTS) */
377
378#define LIST_EMPTY(head) ((head)->lh_first == NULL)
379
380#define LIST_FIRST(head) ((head)->lh_first)
381
382#define LIST_FOREACH(var, head, field) \
383 for ((var) = LIST_FIRST((head)); \
384 (var); \
385 (var) = LIST_NEXT((var), field))
386
387#define LIST_FOREACH_SAFE(var, head, field, tvar) \
388 for ((var) = LIST_FIRST((head)); \
389 (var) && ((tvar) = LIST_NEXT((var), field), 1); \
390 (var) = (tvar))
391
392#define LIST_INIT(head) do { \
393 LIST_FIRST((head)) = NULL; \
394} while (0)
395
396#define LIST_INSERT_AFTER(listelm, elm, field) do { \
397 QMD_LIST_CHECK_NEXT(listelm, field); \
398 if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
399 LIST_NEXT((listelm), field)->field.le_prev = \
400 &LIST_NEXT((elm), field); \
401 LIST_NEXT((listelm), field) = (elm); \
402 (elm)->field.le_prev = &LIST_NEXT((listelm), field); \
403} while (0)
404
405#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
406 QMD_LIST_CHECK_PREV(listelm, field); \
407 (elm)->field.le_prev = (listelm)->field.le_prev; \
408 LIST_NEXT((elm), field) = (listelm); \
409 *(listelm)->field.le_prev = (elm); \
410 (listelm)->field.le_prev = &LIST_NEXT((elm), field); \
411} while (0)
412
413#define LIST_INSERT_HEAD(head, elm, field) do { \
414 QMD_LIST_CHECK_HEAD((head), field); \
415 if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
416 LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
417 LIST_FIRST((head)) = (elm); \
418 (elm)->field.le_prev = &LIST_FIRST((head)); \
419} while (0)
420
421#define LIST_NEXT(elm, field) ((elm)->field.le_next)
422
423#define LIST_REMOVE(elm, field) do { \
424 QMD_LIST_CHECK_NEXT(elm, field); \
425 QMD_LIST_CHECK_PREV(elm, field); \
426 if (LIST_NEXT((elm), field) != NULL) \
427 LIST_NEXT((elm), field)->field.le_prev = \
428 (elm)->field.le_prev; \
429 *(elm)->field.le_prev = LIST_NEXT((elm), field); \
430 TRASHIT((elm)->field.le_next); \
431 TRASHIT((elm)->field.le_prev); \
432} while (0)
433
434/*
435 * Tail queue declarations.
436 */
437#define TAILQ_HEAD(name, type) \
438struct name { \
439 struct type *tqh_first; /* first element */ \
440 struct type **tqh_last; /* addr of last next element */ \
441 TRACEBUF \
442}
443
444#define TAILQ_HEAD_INITIALIZER(head) \
445 { NULL, &(head).tqh_first }
446
447#define TAILQ_ENTRY(type) \
448struct { \
449 struct type *tqe_next; /* next element */ \
450 struct type **tqe_prev; /* address of previous next element */ \
451 TRACEBUF \
452}
453
454/*
455 * Tail queue functions.
456 */
457#if (defined(_KERNEL) && defined(INVARIANTS))
458#define QMD_TAILQ_CHECK_HEAD(head, field) do { \
459 if (!TAILQ_EMPTY(head) && \
460 TAILQ_FIRST((head))->field.tqe_prev != \
461 &TAILQ_FIRST((head))) \
462 panic("Bad tailq head %p first->prev != head", (head)); \
463} while (0)
464
465#define QMD_TAILQ_CHECK_TAIL(head, field) do { \
466 if (*(head)->tqh_last != NULL) \
467 panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \
468} while (0)
469
470#define QMD_TAILQ_CHECK_NEXT(elm, field) do { \
471 if (TAILQ_NEXT((elm), field) != NULL && \
472 TAILQ_NEXT((elm), field)->field.tqe_prev != \
473 &((elm)->field.tqe_next)) \
474 panic("Bad link elm %p next->prev != elm", (elm)); \
475} while (0)
476
477#define QMD_TAILQ_CHECK_PREV(elm, field) do { \
478 if (*(elm)->field.tqe_prev != (elm)) \
479 panic("Bad link elm %p prev->next != elm", (elm)); \
480} while (0)
481#else
482#define QMD_TAILQ_CHECK_HEAD(head, field)
483#define QMD_TAILQ_CHECK_TAIL(head, headname)
484#define QMD_TAILQ_CHECK_NEXT(elm, field)
485#define QMD_TAILQ_CHECK_PREV(elm, field)
486#endif /* (_KERNEL && INVARIANTS) */
487
488#define TAILQ_CONCAT(head1, head2, field) do { \
489 if (!TAILQ_EMPTY(head2)) { \
490 *(head1)->tqh_last = (head2)->tqh_first; \
491 (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
492 (head1)->tqh_last = (head2)->tqh_last; \
493 TAILQ_INIT((head2)); \
494 QMD_TRACE_HEAD(head1); \
495 QMD_TRACE_HEAD(head2); \
496 } \
497} while (0)
498
499#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
500
501#define TAILQ_FIRST(head) ((head)->tqh_first)
502
503#define TAILQ_FOREACH(var, head, field) \
504 for ((var) = TAILQ_FIRST((head)); \
505 (var); \
506 (var) = TAILQ_NEXT((var), field))
507
508#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
509 for ((var) = TAILQ_FIRST((head)); \
510 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
511 (var) = (tvar))
512
513#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
514 for ((var) = TAILQ_LAST((head), headname); \
515 (var); \
516 (var) = TAILQ_PREV((var), headname, field))
517
518#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
519 for ((var) = TAILQ_LAST((head), headname); \
520 (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
521 (var) = (tvar))
522
523#define TAILQ_INIT(head) do { \
524 TAILQ_FIRST((head)) = NULL; \
525 (head)->tqh_last = &TAILQ_FIRST((head)); \
526 QMD_TRACE_HEAD(head); \
527} while (0)
528
529#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
530 QMD_TAILQ_CHECK_NEXT(listelm, field); \
531 if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
532 TAILQ_NEXT((elm), field)->field.tqe_prev = \
533 &TAILQ_NEXT((elm), field); \
534 else { \
535 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
536 QMD_TRACE_HEAD(head); \
537 } \
538 TAILQ_NEXT((listelm), field) = (elm); \
539 (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
540 QMD_TRACE_ELEM(&(elm)->field); \
541 QMD_TRACE_ELEM(&listelm->field); \
542} while (0)
543
544#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
545 QMD_TAILQ_CHECK_PREV(listelm, field); \
546 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
547 TAILQ_NEXT((elm), field) = (listelm); \
548 *(listelm)->field.tqe_prev = (elm); \
549 (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
550 QMD_TRACE_ELEM(&(elm)->field); \
551 QMD_TRACE_ELEM(&listelm->field); \
552} while (0)
553
554#define TAILQ_INSERT_HEAD(head, elm, field) do { \
555 QMD_TAILQ_CHECK_HEAD(head, field); \
556 if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
557 TAILQ_FIRST((head))->field.tqe_prev = \
558 &TAILQ_NEXT((elm), field); \
559 else \
560 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
561 TAILQ_FIRST((head)) = (elm); \
562 (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
563 QMD_TRACE_HEAD(head); \
564 QMD_TRACE_ELEM(&(elm)->field); \
565} while (0)
566
567#define TAILQ_INSERT_TAIL(head, elm, field) do { \
568 QMD_TAILQ_CHECK_TAIL(head, field); \
569 TAILQ_NEXT((elm), field) = NULL; \
570 (elm)->field.tqe_prev = (head)->tqh_last; \
571 *(head)->tqh_last = (elm); \
572 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
573 QMD_TRACE_HEAD(head); \
574 QMD_TRACE_ELEM(&(elm)->field); \
575} while (0)
576
577#define TAILQ_LAST(head, headname) \
578 (*(((struct headname *)((head)->tqh_last))->tqh_last))
579
580#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
581
582#define TAILQ_PREV(elm, headname, field) \
583 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
584
585#define TAILQ_REMOVE(head, elm, field) do { \
586 QMD_TAILQ_CHECK_NEXT(elm, field); \
587 QMD_TAILQ_CHECK_PREV(elm, field); \
588 if ((TAILQ_NEXT((elm), field)) != NULL) \
589 TAILQ_NEXT((elm), field)->field.tqe_prev = \
590 (elm)->field.tqe_prev; \
591 else { \
592 (head)->tqh_last = (elm)->field.tqe_prev; \
593 QMD_TRACE_HEAD(head); \
594 } \
595 *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
596 TRASHIT((elm)->field.tqe_next); \
597 TRASHIT((elm)->field.tqe_prev); \
598 QMD_TRACE_ELEM(&(elm)->field); \
599} while (0)
600
601
602#ifdef _KERNEL
603
604/*
605 * XXX insque() and remque() are an old way of handling certain queues.
606 * They bogusly assumes that all queue heads look alike.
607 */
608
609struct quehead {
610 struct quehead *qh_link;
611 struct quehead *qh_rlink;
612};
613
614#ifdef __CC_SUPPORTS___INLINE
615
616static __inline void
617insque(void *a, void *b)
618{
619 struct quehead *element = (struct quehead *)a,
620 *head = (struct quehead *)b;
621
622 element->qh_link = head->qh_link;
623 element->qh_rlink = head;
624 head->qh_link = element;
625 element->qh_link->qh_rlink = element;
626}
627
628static __inline void
629remque(void *a)
630{
631 struct quehead *element = (struct quehead *)a;
632
633 element->qh_link->qh_rlink = element->qh_rlink;
634 element->qh_rlink->qh_link = element->qh_link;
635 element->qh_rlink = 0;
636}
637
638#else /* !__CC_SUPPORTS___INLINE */
639
640void insque(void *a, void *b);
641void remque(void *a);
642
643#endif /* __CC_SUPPORTS___INLINE */
644
645#endif /* _KERNEL */
646
647#endif /* !_SYS_QUEUE_H_ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette