95a1276908d51679c2244bb9e64f920583bd9614
1 /* This is a stripped down version of FreeBSD's
2 * src/sys/sys/queue.h,v 1.60.2.1
4 * The original file's license:
6 * Copyright (c) 1991, 1993
7 * The Regents of the University of California. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #define STAILQ_HEAD(name, type) \
36 struct type *stqh_first;/* first element */ \
37 struct type **stqh_last;/* addr of last next element */ \
40 #define STAILQ_HEAD_INITIALIZER(head) \
41 { NULL, &(head).stqh_first }
43 #define STAILQ_ENTRY(type) \
45 struct type *stqe_next; /* next element */ \
48 #define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
50 #define STAILQ_FIRST(head) ((head)->stqh_first)
52 #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
54 #ifdef STAILQ_INSERT_TAIL
55 #undef STAILQ_INSERT_TAIL
58 #define STAILQ_INSERT_TAIL(head, elm, field) do { \
59 STAILQ_NEXT((elm), field) = NULL; \
60 *(head)->stqh_last = (elm); \
61 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
64 #ifdef STAILQ_REMOVE_HEAD
65 #undef STAILQ_REMOVE_HEAD
68 #define STAILQ_REMOVE_HEAD(head, field) do { \
69 if ((STAILQ_FIRST((head)) = \
70 STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \
71 (head)->stqh_last = &STAILQ_FIRST((head)); \
75 #define LIST_HEAD(name, type) \
77 struct type *lh_first; /* first element */ \
80 #undef LIST_HEAD_INITIALIZER
81 #define LIST_HEAD_INITIALIZER(head) \
85 #define LIST_ENTRY(type) \
87 struct type *le_next; /* next element */ \
88 struct type **le_prev; /* address of previous next element */ \
92 #define LIST_FIRST(head) ((head)->lh_first)
95 #define LIST_FOREACH(var, head, field) \
96 for ((var) = LIST_FIRST((head)); \
98 (var) = LIST_NEXT((var), field))
100 #undef LIST_FOREACH_SAFE
101 #define LIST_FOREACH_SAFE(var, head, field, tvar) \
102 for ((var) = LIST_FIRST((head)); \
103 (var) && ((tvar) = LIST_NEXT((var), field), 1); \
107 #define LIST_INIT(head) do { \
108 LIST_FIRST((head)) = NULL; \
111 #undef LIST_INSERT_HEAD
112 #define LIST_INSERT_HEAD(head, elm, field) do { \
113 if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
114 LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
115 LIST_FIRST((head)) = (elm); \
116 (elm)->field.le_prev = &LIST_FIRST((head)); \
120 #define LIST_NEXT(elm, field) ((elm)->field.le_next)
123 #define LIST_REMOVE(elm, field) do { \
124 if (LIST_NEXT((elm), field) != NULL) \
125 LIST_NEXT((elm), field)->field.le_prev = \
126 (elm)->field.le_prev; \
127 *(elm)->field.le_prev = LIST_NEXT((elm), field); \