make depend
[darkstat] / queue.h
1 /* This is a stripped down version of FreeBSD's
2 * src/sys/sys/queue.h,v 1.60.2.1
3 *
4 * The original file's license:
5 *
6 * Copyright (c) 1991, 1993
7 * The Regents of the University of California. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
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.
20 *
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
31 * SUCH DAMAGE.
32 */
33
34 #define STAILQ_HEAD(name, type) \
35 struct name { \
36 struct type *stqh_first;/* first element */ \
37 struct type **stqh_last;/* addr of last next element */ \
38 }
39
40 #define STAILQ_HEAD_INITIALIZER(head) \
41 { NULL, &(head).stqh_first }
42
43 #define STAILQ_ENTRY(type) \
44 struct { \
45 struct type *stqe_next; /* next element */ \
46 }
47
48 #define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
49
50 #define STAILQ_FIRST(head) ((head)->stqh_first)
51
52 #define STAILQ_FOREACH(var, head, field) \
53 for((var) = STAILQ_FIRST((head)); \
54 (var); \
55 (var) = STAILQ_NEXT((var), field))
56
57 #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
58
59 #ifdef STAILQ_INSERT_TAIL
60 #undef STAILQ_INSERT_TAIL
61 #endif
62
63 #define STAILQ_INSERT_TAIL(head, elm, field) do { \
64 STAILQ_NEXT((elm), field) = NULL; \
65 *(head)->stqh_last = (elm); \
66 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
67 } while (0)
68
69 #ifdef STAILQ_REMOVE_HEAD
70 #undef STAILQ_REMOVE_HEAD
71 #endif
72
73 #define STAILQ_REMOVE_HEAD(head, field) do { \
74 if ((STAILQ_FIRST((head)) = \
75 STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \
76 (head)->stqh_last = &STAILQ_FIRST((head)); \
77 } while (0)
78
79 #undef LIST_HEAD
80 #define LIST_HEAD(name, type) \
81 struct name { \
82 struct type *lh_first; /* first element */ \
83 }
84
85 #undef LIST_HEAD_INITIALIZER
86 #define LIST_HEAD_INITIALIZER(head) \
87 { NULL }
88
89 #undef LIST_ENTRY
90 #define LIST_ENTRY(type) \
91 struct { \
92 struct type *le_next; /* next element */ \
93 struct type **le_prev; /* address of previous next element */ \
94 }
95
96 #undef LIST_FIRST
97 #define LIST_FIRST(head) ((head)->lh_first)
98
99 #undef LIST_FOREACH
100 #define LIST_FOREACH(var, head, field) \
101 for ((var) = LIST_FIRST((head)); \
102 (var); \
103 (var) = LIST_NEXT((var), field))
104
105 #undef LIST_FOREACH_SAFE
106 #define LIST_FOREACH_SAFE(var, head, field, tvar) \
107 for ((var) = LIST_FIRST((head)); \
108 (var) && ((tvar) = LIST_NEXT((var), field), 1); \
109 (var) = (tvar))
110
111 #undef LIST_INIT
112 #define LIST_INIT(head) do { \
113 LIST_FIRST((head)) = NULL; \
114 } while (0)
115
116 #undef LIST_INSERT_HEAD
117 #define LIST_INSERT_HEAD(head, elm, field) do { \
118 if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
119 LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
120 LIST_FIRST((head)) = (elm); \
121 (elm)->field.le_prev = &LIST_FIRST((head)); \
122 } while (0)
123
124 #undef LIST_NEXT
125 #define LIST_NEXT(elm, field) ((elm)->field.le_next)
126
127 #undef LIST_REMOVE
128 #define LIST_REMOVE(elm, field) do { \
129 if (LIST_NEXT((elm), field) != NULL) \
130 LIST_NEXT((elm), field)->field.le_prev = \
131 (elm)->field.le_prev; \
132 *(elm)->field.le_prev = LIST_NEXT((elm), field); \
133 } while (0)