85 #if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC))
86 #define TOR_Q_INVALIDATE_(a) (a) = ((void *)-1)
88 #define TOR_Q_INVALIDATE_(a)
94 #define TOR_SLIST_HEAD(name, type) \
96 struct type *slh_first; \
99 #define TOR_SLIST_HEAD_INITIALIZER(head) \
102 #define TOR_SLIST_ENTRY(type) \
104 struct type *sle_next; \
110 #define TOR_SLIST_FIRST(head) ((head)->slh_first)
111 #define TOR_SLIST_END(head) NULL
113 #define TOR_SLIST_EMPTY(head) ((SLIST_FIRST(head) == TOR_SLIST_END(head)) || 0)
114 #define TOR_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
116 #define TOR_SLIST_FOREACH(var, head, field) \
117 for((var) = TOR_SLIST_FIRST(head); \
118 (var) != TOR_SLIST_END(head); \
119 (var) = TOR_SLIST_NEXT(var, field))
121 #define TOR_SLIST_FOREACH_SAFE(var, head, field, tvar) \
122 for ((var) = TOR_SLIST_FIRST(head); \
123 (var) && ((tvar) = TOR_SLIST_NEXT(var, field), 1); \
129 #define TOR_SLIST_INIT(head) { \
130 TOR_SLIST_FIRST(head) = TOR_SLIST_END(head); \
133 #define TOR_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
134 (elm)->field.sle_next = (slistelm)->field.sle_next; \
135 (slistelm)->field.sle_next = (elm); \
138 #define TOR_SLIST_INSERT_HEAD(head, elm, field) do { \
139 (elm)->field.sle_next = (head)->slh_first; \
140 (head)->slh_first = (elm); \
143 #define TOR_SLIST_REMOVE_AFTER(elm, field) do { \
144 (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
147 #define TOR_SLIST_REMOVE_HEAD(head, field) do { \
148 (head)->slh_first = (head)->slh_first->field.sle_next; \
151 #define TOR_SLIST_REMOVE(head, elm, type, field) do { \
152 if ((head)->slh_first == (elm)) { \
153 TOR_SLIST_REMOVE_HEAD((head), field); \
155 struct type *curelm = (head)->slh_first; \
157 while (curelm->field.sle_next != (elm)) \
158 curelm = curelm->field.sle_next; \
159 curelm->field.sle_next = \
160 curelm->field.sle_next->field.sle_next; \
161 TOR_Q_INVALIDATE_((elm)->field.sle_next); \
168 #define TOR_LIST_HEAD(name, type) \
170 struct type *lh_first; \
173 #define TOR_LIST_HEAD_INITIALIZER(head) \
176 #define TOR_LIST_ENTRY(type) \
178 struct type *le_next; \
179 struct type **le_prev; \
185 #define TOR_LIST_FIRST(head) ((head)->lh_first)
186 #define TOR_LIST_END(head) NULL
188 #define TOR_LIST_EMPTY(head) \
189 ((TOR_LIST_FIRST(head) == TOR_LIST_END(head)) || 0)
190 #define TOR_LIST_NEXT(elm, field) ((elm)->field.le_next)
192 #define TOR_LIST_FOREACH(var, head, field) \
193 for((var) = TOR_LIST_FIRST(head); \
194 (var)!= TOR_LIST_END(head); \
195 (var) = TOR_LIST_NEXT(var, field))
197 #define TOR_LIST_FOREACH_SAFE(var, head, field, tvar) \
198 for ((var) = TOR_LIST_FIRST(head); \
199 (var) && ((tvar) = TOR_LIST_NEXT(var, field), 1); \
205 #define TOR_LIST_INIT(head) do { \
206 TOR_LIST_FIRST(head) = TOR_LIST_END(head); \
209 #define TOR_LIST_INSERT_AFTER(listelm, elm, field) do { \
210 if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
211 (listelm)->field.le_next->field.le_prev = \
212 &(elm)->field.le_next; \
213 (listelm)->field.le_next = (elm); \
214 (elm)->field.le_prev = &(listelm)->field.le_next; \
217 #define TOR_LIST_INSERT_BEFORE(listelm, elm, field) do { \
218 (elm)->field.le_prev = (listelm)->field.le_prev; \
219 (elm)->field.le_next = (listelm); \
220 *(listelm)->field.le_prev = (elm); \
221 (listelm)->field.le_prev = &(elm)->field.le_next; \
224 #define TOR_LIST_INSERT_HEAD(head, elm, field) do { \
225 if (((elm)->field.le_next = (head)->lh_first) != NULL) \
226 (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
227 (head)->lh_first = (elm); \
228 (elm)->field.le_prev = &(head)->lh_first; \
231 #define TOR_LIST_REMOVE(elm, field) do { \
232 if ((elm)->field.le_next != NULL) \
233 (elm)->field.le_next->field.le_prev = \
234 (elm)->field.le_prev; \
235 *(elm)->field.le_prev = (elm)->field.le_next; \
236 TOR_Q_INVALIDATE_((elm)->field.le_prev); \
237 TOR_Q_INVALIDATE_((elm)->field.le_next); \
240 #define TOR_LIST_REPLACE(elm, elm2, field) do { \
241 if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
242 (elm2)->field.le_next->field.le_prev = \
243 &(elm2)->field.le_next; \
244 (elm2)->field.le_prev = (elm)->field.le_prev; \
245 *(elm2)->field.le_prev = (elm2); \
246 TOR_Q_INVALIDATE_((elm)->field.le_prev); \
247 TOR_Q_INVALIDATE_((elm)->field.le_next); \
253 #define TOR_SIMPLEQ_HEAD(name, type) \
255 struct type *sqh_first; \
256 struct type **sqh_last; \
259 #define TOR_SIMPLEQ_HEAD_INITIALIZER(head) \
260 { NULL, &(head).sqh_first }
262 #define TOR_SIMPLEQ_ENTRY(type) \
264 struct type *sqe_next; \
270 #define TOR_SIMPLEQ_FIRST(head) ((head)->sqh_first)
271 #define TOR_SIMPLEQ_END(head) NULL
273 #define TOR_SIMPLEQ_EMPTY(head) \
274 ((TOR_SIMPLEQ_FIRST(head) == TOR_SIMPLEQ_END(head)) || 0)
275 #define TOR_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
277 #define TOR_SIMPLEQ_FOREACH(var, head, field) \
278 for((var) = TOR_SIMPLEQ_FIRST(head); \
279 (var) != TOR_SIMPLEQ_END(head); \
280 (var) = TOR_SIMPLEQ_NEXT(var, field))
282 #define TOR_SIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \
283 for ((var) = TOR_SIMPLEQ_FIRST(head); \
284 (var) && ((tvar) = TOR_SIMPLEQ_NEXT(var, field), 1); \
290 #define TOR_SIMPLEQ_INIT(head) do { \
291 (head)->sqh_first = NULL; \
292 (head)->sqh_last = &(head)->sqh_first; \
295 #define TOR_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
296 if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
297 (head)->sqh_last = &(elm)->field.sqe_next; \
298 (head)->sqh_first = (elm); \
301 #define TOR_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
302 (elm)->field.sqe_next = NULL; \
303 *(head)->sqh_last = (elm); \
304 (head)->sqh_last = &(elm)->field.sqe_next; \
307 #define TOR_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
308 if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
309 (head)->sqh_last = &(elm)->field.sqe_next; \
310 (listelm)->field.sqe_next = (elm); \
313 #define TOR_SIMPLEQ_REMOVE_HEAD(head, field) do { \
314 if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
315 (head)->sqh_last = &(head)->sqh_first; \
318 #define TOR_SIMPLEQ_REMOVE_AFTER(head, elm, field) do { \
319 if (((elm)->field.sqe_next = (elm)->field.sqe_next->field.sqe_next) \
321 (head)->sqh_last = &(elm)->field.sqe_next; \
327 #define TOR_TAILQ_HEAD(name, type) \
329 struct type *tqh_first; \
330 struct type **tqh_last; \
333 #define TOR_TAILQ_HEAD_INITIALIZER(head) \
334 { NULL, &(head).tqh_first }
336 #define TOR_TAILQ_ENTRY(type) \
338 struct type *tqe_next; \
339 struct type **tqe_prev; \
345 #define TOR_TAILQ_FIRST(head) ((head)->tqh_first)
346 #define TOR_TAILQ_END(head) NULL
347 #define TOR_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
348 #define TOR_TAILQ_LAST(head, headname) \
349 (*(((struct headname *)((head)->tqh_last))->tqh_last))
351 #define TOR_TAILQ_PREV(elm, headname, field) \
352 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
354 #define TOR_TAILQ_EMPTY(head) \
355 ((TOR_TAILQ_FIRST(head) == TOR_TAILQ_END(head)) || 0)
357 #define TOR_TAILQ_FOREACH(var, head, field) \
358 for((var) = TOR_TAILQ_FIRST(head); \
359 (var) != TOR_TAILQ_END(head); \
360 (var) = TOR_TAILQ_NEXT(var, field))
362 #define TOR_TAILQ_FOREACH_SAFE(var, head, field, tvar) \
363 for ((var) = TOR_TAILQ_FIRST(head); \
364 (var) != TOR_TAILQ_END(head) && \
365 ((tvar) = TOR_TAILQ_NEXT(var, field), 1); \
369 #define TOR_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
370 for((var) = TOR_TAILQ_LAST(head, headname); \
371 (var) != TOR_TAILQ_END(head); \
372 (var) = TOR_TAILQ_PREV(var, headname, field))
374 #define TOR_TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
375 for ((var) = TOR_TAILQ_LAST(head, headname); \
376 (var) != TOR_TAILQ_END(head) && \
377 ((tvar) = TOR_TAILQ_PREV(var, headname, field), 1); \
383 #define TOR_TAILQ_INIT(head) do { \
384 (head)->tqh_first = NULL; \
385 (head)->tqh_last = &(head)->tqh_first; \
388 #define TOR_TAILQ_INSERT_HEAD(head, elm, field) do { \
389 if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
390 (head)->tqh_first->field.tqe_prev = \
391 &(elm)->field.tqe_next; \
393 (head)->tqh_last = &(elm)->field.tqe_next; \
394 (head)->tqh_first = (elm); \
395 (elm)->field.tqe_prev = &(head)->tqh_first; \
398 #define TOR_TAILQ_INSERT_TAIL(head, elm, field) do { \
399 (elm)->field.tqe_next = NULL; \
400 (elm)->field.tqe_prev = (head)->tqh_last; \
401 *(head)->tqh_last = (elm); \
402 (head)->tqh_last = &(elm)->field.tqe_next; \
405 #define TOR_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
406 if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
407 (elm)->field.tqe_next->field.tqe_prev = \
408 &(elm)->field.tqe_next; \
410 (head)->tqh_last = &(elm)->field.tqe_next; \
411 (listelm)->field.tqe_next = (elm); \
412 (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
415 #define TOR_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
416 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
417 (elm)->field.tqe_next = (listelm); \
418 *(listelm)->field.tqe_prev = (elm); \
419 (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
422 #define TOR_TAILQ_REMOVE(head, elm, field) do { \
423 if (((elm)->field.tqe_next) != NULL) \
424 (elm)->field.tqe_next->field.tqe_prev = \
425 (elm)->field.tqe_prev; \
427 (head)->tqh_last = (elm)->field.tqe_prev; \
428 *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
429 TOR_Q_INVALIDATE_((elm)->field.tqe_prev); \
430 TOR_Q_INVALIDATE_((elm)->field.tqe_next); \
433 #define TOR_TAILQ_REPLACE(head, elm, elm2, field) do { \
434 if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
435 (elm2)->field.tqe_next->field.tqe_prev = \
436 &(elm2)->field.tqe_next; \
438 (head)->tqh_last = &(elm2)->field.tqe_next; \
439 (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
440 *(elm2)->field.tqe_prev = (elm2); \
441 TOR_Q_INVALIDATE_((elm)->field.tqe_prev); \
442 TOR_Q_INVALIDATE_((elm)->field.tqe_next); \
448 #define TOR_CIRCLEQ_HEAD(name, type) \
450 struct type *cqh_first; \
451 struct type *cqh_last; \
454 #define TOR_CIRCLEQ_HEAD_INITIALIZER(head) \
455 { TOR_CIRCLEQ_END(&head), TOR_CIRCLEQ_END(&head) }
457 #define TOR_CIRCLEQ_ENTRY(type) \
459 struct type *cqe_next; \
460 struct type *cqe_prev; \
466 #define TOR_CIRCLEQ_FIRST(head) ((head)->cqh_first)
467 #define TOR_CIRCLEQ_LAST(head) ((head)->cqh_last)
468 #define TOR_CIRCLEQ_END(head) ((void *)(head))
469 #define TOR_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
470 #define TOR_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
472 #define TOR_CIRCLEQ_EMPTY(head) \
473 ((TOR_CIRCLEQ_FIRST(head) == TOR_CIRCLEQ_END(head)) || 0)
475 #define TOR_CIRCLEQ_FOREACH(var, head, field) \
476 for((var) = TOR_CIRCLEQ_FIRST(head); \
477 (var) != TOR_CIRCLEQ_END(head); \
478 (var) = TOR_CIRCLEQ_NEXT(var, field))
480 #define TOR_CIRCLEQ_FOREACH_SAFE(var, head, field, tvar) \
481 for ((var) = TOR_CIRCLEQ_FIRST(head); \
482 (var) != TOR_CIRCLEQ_END(head) && \
483 ((tvar) = TOR_CIRCLEQ_NEXT(var, field), 1); \
486 #define TOR_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
487 for((var) = TOR_CIRCLEQ_LAST(head); \
488 (var) != TOR_CIRCLEQ_END(head); \
489 (var) = TOR_CIRCLEQ_PREV(var, field))
491 #define TOR_CIRCLEQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
492 for ((var) = TOR_CIRCLEQ_LAST(head, headname); \
493 (var) != TOR_CIRCLEQ_END(head) && \
494 ((tvar) = TOR_CIRCLEQ_PREV(var, headname, field), 1); \
500 #define TOR_CIRCLEQ_INIT(head) do { \
501 (head)->cqh_first = TOR_CIRCLEQ_END(head); \
502 (head)->cqh_last = TOR_CIRCLEQ_END(head); \
505 #define TOR_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
506 (elm)->field.cqe_next = (listelm)->field.cqe_next; \
507 (elm)->field.cqe_prev = (listelm); \
508 if ((listelm)->field.cqe_next == TOR_CIRCLEQ_END(head)) \
509 (head)->cqh_last = (elm); \
511 (listelm)->field.cqe_next->field.cqe_prev = (elm); \
512 (listelm)->field.cqe_next = (elm); \
515 #define TOR_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
516 (elm)->field.cqe_next = (listelm); \
517 (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
518 if ((listelm)->field.cqe_prev == TOR_CIRCLEQ_END(head)) \
519 (head)->cqh_first = (elm); \
521 (listelm)->field.cqe_prev->field.cqe_next = (elm); \
522 (listelm)->field.cqe_prev = (elm); \
525 #define TOR_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
526 (elm)->field.cqe_next = (head)->cqh_first; \
527 (elm)->field.cqe_prev = TOR_CIRCLEQ_END(head); \
528 if ((head)->cqh_last == TOR_CIRCLEQ_END(head)) \
529 (head)->cqh_last = (elm); \
531 (head)->cqh_first->field.cqe_prev = (elm); \
532 (head)->cqh_first = (elm); \
535 #define TOR_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
536 (elm)->field.cqe_next = TOR_CIRCLEQ_END(head); \
537 (elm)->field.cqe_prev = (head)->cqh_last; \
538 if ((head)->cqh_first == TOR_CIRCLEQ_END(head)) \
539 (head)->cqh_first = (elm); \
541 (head)->cqh_last->field.cqe_next = (elm); \
542 (head)->cqh_last = (elm); \
545 #define TOR_CIRCLEQ_REMOVE(head, elm, field) do { \
546 if ((elm)->field.cqe_next == TOR_CIRCLEQ_END(head)) \
547 (head)->cqh_last = (elm)->field.cqe_prev; \
549 (elm)->field.cqe_next->field.cqe_prev = \
550 (elm)->field.cqe_prev; \
551 if ((elm)->field.cqe_prev == TOR_CIRCLEQ_END(head)) \
552 (head)->cqh_first = (elm)->field.cqe_next; \
554 (elm)->field.cqe_prev->field.cqe_next = \
555 (elm)->field.cqe_next; \
556 TOR_Q_INVALIDATE_((elm)->field.cqe_prev); \
557 TOR_Q_INVALIDATE_((elm)->field.cqe_next); \
560 #define TOR_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
561 if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
562 TOR_CIRCLEQ_END(head)) \
563 (head).cqh_last = (elm2); \
565 (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
566 if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
567 TOR_CIRCLEQ_END(head)) \
568 (head).cqh_first = (elm2); \
570 (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
571 TOR_Q_INVALIDATE_((elm)->field.cqe_prev); \
572 TOR_Q_INVALIDATE_((elm)->field.cqe_next); \