Go to the documentation of this file.
40 #ifndef SURICATA_QUEUE_H
41 #define SURICATA_QUEUE_H
53 #if defined(HAVE_SYS_QUEUE_H) && !defined(__clang_analyzer__)
54 #include <sys/queue.h>
57 #if defined(__clang_analyzer__)
58 #define _Q_ASSERT(a) assert((a))
76 #define CIRCLEQ_HEAD(name, type) \
78 struct type *cqh_first; \
79 struct type *cqh_last; \
82 #define CIRCLEQ_HEAD_INITIALIZER(head) \
83 { CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
85 #define CIRCLEQ_ENTRY(type) \
87 struct type *cqe_next; \
88 struct type *cqe_prev; \
94 #define CIRCLEQ_FIRST(head) ((head)->cqh_first)
95 #define CIRCLEQ_LAST(head) ((head)->cqh_last)
96 #define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
97 #define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
98 #define CIRCLEQ_EMPTY(head) \
99 (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))
101 #define CIRCLEQ_FOREACH(var, head, field) \
102 for((var) = CIRCLEQ_FIRST(head); \
103 (var) != CIRCLEQ_END(head); \
104 (var) = CIRCLEQ_NEXT(var, field))
106 #define CIRCLEQ_FOREACH_SAFE(var, head, field, tvar) \
107 for ((var) = CIRCLEQ_FIRST(head); \
108 (var) != CIRCLEQ_END(head) && \
109 ((tvar) = CIRCLEQ_NEXT(var, field), 1); \
112 #define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
113 for((var) = CIRCLEQ_LAST(head); \
114 (var) != CIRCLEQ_END(head); \
115 (var) = CIRCLEQ_PREV(var, field))
117 #define CIRCLEQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
118 for ((var) = CIRCLEQ_LAST(head, headname); \
119 (var) != CIRCLEQ_END(head) && \
120 ((tvar) = CIRCLEQ_PREV(var, headname, field), 1); \
126 #define CIRCLEQ_INIT(head) do { \
127 (head)->cqh_first = CIRCLEQ_END(head); \
128 (head)->cqh_last = CIRCLEQ_END(head); \
131 #define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
132 (elm)->field.cqe_next = (listelm)->field.cqe_next; \
133 (elm)->field.cqe_prev = (listelm); \
134 if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \
135 (head)->cqh_last = (elm); \
137 (listelm)->field.cqe_next->field.cqe_prev = (elm); \
138 (listelm)->field.cqe_next = (elm); \
141 #define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
142 (elm)->field.cqe_next = (listelm); \
143 (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
144 if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \
145 (head)->cqh_first = (elm); \
147 (listelm)->field.cqe_prev->field.cqe_next = (elm); \
148 (listelm)->field.cqe_prev = (elm); \
151 #define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
152 (elm)->field.cqe_next = (head)->cqh_first; \
153 (elm)->field.cqe_prev = CIRCLEQ_END(head); \
154 if ((head)->cqh_last == CIRCLEQ_END(head)) \
155 (head)->cqh_last = (elm); \
157 (head)->cqh_first->field.cqe_prev = (elm); \
158 (head)->cqh_first = (elm); \
161 #define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
162 (elm)->field.cqe_next = CIRCLEQ_END(head); \
163 (elm)->field.cqe_prev = (head)->cqh_last; \
164 if ((head)->cqh_first == CIRCLEQ_END(head)) \
165 (head)->cqh_first = (elm); \
167 (head)->cqh_last->field.cqe_next = (elm); \
168 (head)->cqh_last = (elm); \
171 #define CIRCLEQ_REMOVE(head, elm, field) do { \
172 if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \
173 (head)->cqh_last = (elm)->field.cqe_prev; \
175 (elm)->field.cqe_next->field.cqe_prev = \
176 (elm)->field.cqe_prev; \
177 if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \
178 (head)->cqh_first = (elm)->field.cqe_next; \
180 (elm)->field.cqe_prev->field.cqe_next = \
181 (elm)->field.cqe_next; \
184 #define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
185 if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
187 (head)->cqh_last = (elm2); \
189 (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
190 if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
192 (head)->cqh_first = (elm2); \
194 (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
201 #define CIRCLEQ_END(head) ((void *)(head))
204 #ifndef CIRCLEQ_FOREACH_SAFE
205 #define CIRCLEQ_FOREACH_SAFE(var, head, field, tvar) \
206 for ((var) = CIRCLEQ_FIRST(head); \
207 (var) != CIRCLEQ_END(head) && \
208 ((tvar) = CIRCLEQ_NEXT(var, field), 1); \
211 #define CIRCLEQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
212 for ((var) = CIRCLEQ_LAST(head, headname); \
213 (var) != CIRCLEQ_END(head) && \
214 ((tvar) = CIRCLEQ_PREV(var, headname, field), 1); \
230 #define TAILQ_HEAD(name, type) \
232 struct type *tqh_first; \
233 struct type **tqh_last; \
236 #define TAILQ_HEAD_INITIALIZER(head) \
237 { NULL, &(head).tqh_first }
239 #define TAILQ_ENTRY(type) \
241 struct type *tqe_next; \
242 struct type **tqe_prev; \
248 #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
250 #define TAILQ_FIRST(head) ((head)->tqh_first)
252 #define TAILQ_FOREACH(var, head, field) \
253 for ((var) = TAILQ_FIRST((head)); \
255 (var) = TAILQ_NEXT((var), field))
257 #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
258 for ((var) = TAILQ_LAST((head), headname); \
260 (var) = TAILQ_PREV((var), headname, field))
262 #define TAILQ_INIT(head) do { \
263 TAILQ_FIRST((head)) = NULL; \
264 (head)->tqh_last = &TAILQ_FIRST((head)); \
267 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
268 if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
269 TAILQ_NEXT((elm), field)->field.tqe_prev = \
270 &TAILQ_NEXT((elm), field); \
272 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
273 TAILQ_NEXT((listelm), field) = (elm); \
274 (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
277 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
278 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
279 TAILQ_NEXT((elm), field) = (listelm); \
280 *(listelm)->field.tqe_prev = (elm); \
281 (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
284 #define TAILQ_INSERT_HEAD(head, elm, field) do { \
285 if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
286 TAILQ_FIRST((head))->field.tqe_prev = \
287 &TAILQ_NEXT((elm), field); \
289 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
290 TAILQ_FIRST((head)) = (elm); \
291 (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
294 #define TAILQ_INSERT_TAIL(head, elm, field) do { \
297 TAILQ_NEXT((elm), field) = NULL; \
298 (elm)->field.tqe_prev = (head)->tqh_last; \
299 *(head)->tqh_last = (elm); \
300 _Q_ASSERT(*(head)->tqh_last); \
301 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
304 #define TAILQ_LAST(head, headname) \
305 (*(((struct headname *)((head)->tqh_last))->tqh_last))
307 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
309 #define TAILQ_PREV(elm, headname, field) \
310 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
312 #define TAILQ_REMOVE(head, elm, field) do { \
313 if ((TAILQ_NEXT((elm), field)) != NULL) \
314 TAILQ_NEXT((elm), field)->field.tqe_prev = \
315 (elm)->field.tqe_prev; \
317 (head)->tqh_last = (elm)->field.tqe_prev; \
318 _Q_ASSERT((head)->tqh_first != (elm)); \
319 *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
328 #ifndef TAILQ_FOREACH_SAFE
329 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
330 for ((var) = TAILQ_FIRST((head)); \
331 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \