1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#ifndef QEMU_SYS_QUEUE_H_
41#define QEMU_SYS_QUEUE_H_
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81#include "qemu/atomic.h"
82
83
84
85
86#define QLIST_HEAD(name, type) \
87struct name { \
88 struct type *lh_first; \
89}
90
91#define QLIST_HEAD_INITIALIZER(head) \
92 { NULL }
93
94#define QLIST_ENTRY(type) \
95struct { \
96 struct type *le_next; \
97 struct type **le_prev; \
98}
99
100
101
102
103#define QLIST_INIT(head) do { \
104 (head)->lh_first = NULL; \
105} while (0)
106
107#define QLIST_INSERT_AFTER(listelm, elm, field) do { \
108 if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
109 (listelm)->field.le_next->field.le_prev = \
110 &(elm)->field.le_next; \
111 (listelm)->field.le_next = (elm); \
112 (elm)->field.le_prev = &(listelm)->field.le_next; \
113} while (0)
114
115#define QLIST_INSERT_BEFORE(listelm, elm, field) do { \
116 (elm)->field.le_prev = (listelm)->field.le_prev; \
117 (elm)->field.le_next = (listelm); \
118 *(listelm)->field.le_prev = (elm); \
119 (listelm)->field.le_prev = &(elm)->field.le_next; \
120} while (0)
121
122#define QLIST_INSERT_HEAD(head, elm, field) do { \
123 if (((elm)->field.le_next = (head)->lh_first) != NULL) \
124 (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
125 (head)->lh_first = (elm); \
126 (elm)->field.le_prev = &(head)->lh_first; \
127} while (0)
128
129#define QLIST_INSERT_HEAD_RCU(head, elm, field) do { \
130 (elm)->field.le_prev = &(head)->lh_first; \
131 (elm)->field.le_next = (head)->lh_first; \
132 smp_wmb(); \
133 if ((head)->lh_first != NULL) { \
134 (head)->lh_first->field.le_prev = &(elm)->field.le_next; \
135 } \
136 (head)->lh_first = (elm); \
137 smp_wmb(); \
138} while (0)
139
140#define QLIST_REMOVE(elm, field) do { \
141 if ((elm)->field.le_next != NULL) \
142 (elm)->field.le_next->field.le_prev = \
143 (elm)->field.le_prev; \
144 *(elm)->field.le_prev = (elm)->field.le_next; \
145} while (0)
146
147#define QLIST_FOREACH(var, head, field) \
148 for ((var) = ((head)->lh_first); \
149 (var); \
150 (var) = ((var)->field.le_next))
151
152#define QLIST_FOREACH_SAFE(var, head, field, next_var) \
153 for ((var) = ((head)->lh_first); \
154 (var) && ((next_var) = ((var)->field.le_next), 1); \
155 (var) = (next_var))
156
157
158
159
160#define QLIST_EMPTY(head) ((head)->lh_first == NULL)
161#define QLIST_FIRST(head) ((head)->lh_first)
162#define QLIST_NEXT(elm, field) ((elm)->field.le_next)
163
164
165
166
167
168#define QSLIST_HEAD(name, type) \
169struct name { \
170 struct type *slh_first; \
171}
172
173#define QSLIST_HEAD_INITIALIZER(head) \
174 { NULL }
175
176#define QSLIST_ENTRY(type) \
177struct { \
178 struct type *sle_next; \
179}
180
181
182
183
184#define QSLIST_INIT(head) do { \
185 (head)->slh_first = NULL; \
186} while (0)
187
188#define QSLIST_INSERT_AFTER(slistelm, elm, field) do { \
189 (elm)->field.sle_next = (slistelm)->field.sle_next; \
190 (slistelm)->field.sle_next = (elm); \
191} while (0)
192
193#define QSLIST_INSERT_HEAD(head, elm, field) do { \
194 (elm)->field.sle_next = (head)->slh_first; \
195 (head)->slh_first = (elm); \
196} while (0)
197
198#define QSLIST_REMOVE_HEAD(head, field) do { \
199 (head)->slh_first = (head)->slh_first->field.sle_next; \
200} while (0)
201
202#define QSLIST_REMOVE_AFTER(slistelm, field) do { \
203 (slistelm)->field.sle_next = \
204 QSLIST_NEXT(QSLIST_NEXT((slistelm), field), field); \
205} while (0)
206
207#define QSLIST_FOREACH(var, head, field) \
208 for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
209
210#define QSLIST_FOREACH_SAFE(var, head, field, tvar) \
211 for ((var) = QSLIST_FIRST((head)); \
212 (var) && ((tvar) = QSLIST_NEXT((var), field), 1); \
213 (var) = (tvar))
214
215
216
217
218#define QSLIST_EMPTY(head) ((head)->slh_first == NULL)
219#define QSLIST_FIRST(head) ((head)->slh_first)
220#define QSLIST_NEXT(elm, field) ((elm)->field.sle_next)
221
222
223
224
225
226#define QSIMPLEQ_HEAD(name, type) \
227struct name { \
228 struct type *sqh_first; \
229 struct type **sqh_last; \
230}
231
232#define QSIMPLEQ_HEAD_INITIALIZER(head) \
233 { NULL, &(head).sqh_first }
234
235#define QSIMPLEQ_ENTRY(type) \
236struct { \
237 struct type *sqe_next; \
238}
239
240
241
242
243#define QSIMPLEQ_INIT(head) do { \
244 (head)->sqh_first = NULL; \
245 (head)->sqh_last = &(head)->sqh_first; \
246} while (0)
247
248#define QSIMPLEQ_INSERT_HEAD(head, elm, field) do { \
249 if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
250 (head)->sqh_last = &(elm)->field.sqe_next; \
251 (head)->sqh_first = (elm); \
252} while (0)
253
254#define QSIMPLEQ_INSERT_TAIL(head, elm, field) do { \
255 (elm)->field.sqe_next = NULL; \
256 *(head)->sqh_last = (elm); \
257 (head)->sqh_last = &(elm)->field.sqe_next; \
258} while (0)
259
260#define QSIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
261 if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL) \
262 (head)->sqh_last = &(elm)->field.sqe_next; \
263 (listelm)->field.sqe_next = (elm); \
264} while (0)
265
266#define QSIMPLEQ_REMOVE_HEAD(head, field) do { \
267 if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL)\
268 (head)->sqh_last = &(head)->sqh_first; \
269} while (0)
270
271#define QSIMPLEQ_REMOVE(head, elm, type, field) do { \
272 if ((head)->sqh_first == (elm)) { \
273 QSIMPLEQ_REMOVE_HEAD((head), field); \
274 } else { \
275 struct type *curelm = (head)->sqh_first; \
276 while (curelm->field.sqe_next != (elm)) \
277 curelm = curelm->field.sqe_next; \
278 if ((curelm->field.sqe_next = \
279 curelm->field.sqe_next->field.sqe_next) == NULL) \
280 (head)->sqh_last = &(curelm)->field.sqe_next; \
281 } \
282} while (0)
283
284#define QSIMPLEQ_FOREACH(var, head, field) \
285 for ((var) = ((head)->sqh_first); \
286 (var); \
287 (var) = ((var)->field.sqe_next))
288
289#define QSIMPLEQ_FOREACH_SAFE(var, head, field, next) \
290 for ((var) = ((head)->sqh_first); \
291 (var) && ((next = ((var)->field.sqe_next)), 1); \
292 (var) = (next))
293
294#define QSIMPLEQ_CONCAT(head1, head2) do { \
295 if (!QSIMPLEQ_EMPTY((head2))) { \
296 *(head1)->sqh_last = (head2)->sqh_first; \
297 (head1)->sqh_last = (head2)->sqh_last; \
298 QSIMPLEQ_INIT((head2)); \
299 } \
300} while (0)
301
302#define QSIMPLEQ_LAST(head, type, field) \
303 (QSIMPLEQ_EMPTY((head)) ? \
304 NULL : \
305 ((struct type *)(void *) \
306 ((char *)((head)->sqh_last) - offsetof(struct type, field))))
307
308
309
310
311#define QSIMPLEQ_EMPTY(head) ((head)->sqh_first == NULL)
312#define QSIMPLEQ_FIRST(head) ((head)->sqh_first)
313#define QSIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
314
315
316
317
318
319#define Q_TAILQ_HEAD(name, type, qual) \
320struct name { \
321 qual type *tqh_first; \
322 qual type *qual *tqh_last; \
323}
324#define QTAILQ_HEAD(name, type) Q_TAILQ_HEAD(name, struct type,)
325
326#define QTAILQ_HEAD_INITIALIZER(head) \
327 { NULL, &(head).tqh_first }
328
329#define Q_TAILQ_ENTRY(type, qual) \
330struct { \
331 qual type *tqe_next; \
332 qual type *qual *tqe_prev; \
333}
334#define QTAILQ_ENTRY(type) Q_TAILQ_ENTRY(struct type,)
335
336
337
338
339#define QTAILQ_INIT(head) do { \
340 (head)->tqh_first = NULL; \
341 (head)->tqh_last = &(head)->tqh_first; \
342} while (0)
343
344#define QTAILQ_INSERT_HEAD(head, elm, field) do { \
345 if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
346 (head)->tqh_first->field.tqe_prev = \
347 &(elm)->field.tqe_next; \
348 else \
349 (head)->tqh_last = &(elm)->field.tqe_next; \
350 (head)->tqh_first = (elm); \
351 (elm)->field.tqe_prev = &(head)->tqh_first; \
352} while (0)
353
354#define QTAILQ_INSERT_TAIL(head, elm, field) do { \
355 (elm)->field.tqe_next = NULL; \
356 (elm)->field.tqe_prev = (head)->tqh_last; \
357 *(head)->tqh_last = (elm); \
358 (head)->tqh_last = &(elm)->field.tqe_next; \
359} while (0)
360
361#define QTAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
362 if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
363 (elm)->field.tqe_next->field.tqe_prev = \
364 &(elm)->field.tqe_next; \
365 else \
366 (head)->tqh_last = &(elm)->field.tqe_next; \
367 (listelm)->field.tqe_next = (elm); \
368 (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
369} while (0)
370
371#define QTAILQ_INSERT_BEFORE(listelm, elm, field) do { \
372 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
373 (elm)->field.tqe_next = (listelm); \
374 *(listelm)->field.tqe_prev = (elm); \
375 (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
376} while (0)
377
378#define QTAILQ_REMOVE(head, elm, field) do { \
379 if (((elm)->field.tqe_next) != NULL) \
380 (elm)->field.tqe_next->field.tqe_prev = \
381 (elm)->field.tqe_prev; \
382 else \
383 (head)->tqh_last = (elm)->field.tqe_prev; \
384 *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
385} while (0)
386
387#define QTAILQ_FOREACH(var, head, field) \
388 for ((var) = ((head)->tqh_first); \
389 (var); \
390 (var) = ((var)->field.tqe_next))
391
392#define QTAILQ_FOREACH_SAFE(var, head, field, next_var) \
393 for ((var) = ((head)->tqh_first); \
394 (var) && ((next_var) = ((var)->field.tqe_next), 1); \
395 (var) = (next_var))
396
397#define QTAILQ_FOREACH_REVERSE(var, head, headname, field) \
398 for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \
399 (var); \
400 (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
401
402
403
404
405#define QTAILQ_EMPTY(head) ((head)->tqh_first == NULL)
406#define QTAILQ_FIRST(head) ((head)->tqh_first)
407#define QTAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
408
409#define QTAILQ_LAST(head, headname) \
410 (*(((struct headname *)((head)->tqh_last))->tqh_last))
411#define QTAILQ_PREV(elm, headname, field) \
412 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
413
414#endif
415