Imported Debian patch 3.0.715-1
[darkstat-debian] / 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_NEXT(elm, field) ((elm)->field.stqe_next)
53
54 #ifdef STAILQ_INSERT_TAIL
55 #undef STAILQ_INSERT_TAIL
56 #endif
57
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); \
62 } while (0)
63
64 #ifdef STAILQ_REMOVE_HEAD
65 #undef STAILQ_REMOVE_HEAD
66 #endif
67
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)); \
72 } while (0)
73
74 #undef LIST_HEAD
75 #define LIST_HEAD(name, type) \
76 struct name { \
77 struct type *lh_first; /* first element */ \
78 }
79
80 #undef LIST_HEAD_INITIALIZER
81 #define LIST_HEAD_INITIALIZER(head) \
82 { NULL }
83
84 #undef LIST_ENTRY
85 #define LIST_ENTRY(type) \
86 struct { \
87 struct type *le_next; /* next element */ \
88 struct type **le_prev; /* address of previous next element */ \
89 }
90
91 #undef LIST_FIRST
92 #define LIST_FIRST(head) ((head)->lh_first)
93
94 #undef LIST_FOREACH
95 #define LIST_FOREACH(var, head, field) \
96 for ((var) = LIST_FIRST((head)); \
97 (var); \
98 (var) = LIST_NEXT((var), field))
99
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); \
104 (var) = (tvar))
105
106 #undef LIST_INIT
107 #define LIST_INIT(head) do { \
108 LIST_FIRST((head)) = NULL; \
109 } while (0)
110
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)); \
117 } while (0)
118
119 #undef LIST_NEXT
120 #define LIST_NEXT(elm, field) ((elm)->field.le_next)
121
122 #undef LIST_REMOVE
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); \
128 } while (0)