Go to the documentation of this file. 36 #include <sys/cdefs.h> 115 #ifdef QUEUE_MACRO_DEBUG 116 #warn Use QUEUE_MACRO_DEBUG_TRACE and/or QUEUE_MACRO_DEBUG_TRASH 117 #define QUEUE_MACRO_DEBUG_TRACE 118 #define QUEUE_MACRO_DEBUG_TRASH 121 #ifdef QUEUE_MACRO_DEBUG_TRACE 124 unsigned long lastline;
125 unsigned long prevline;
126 const char *lastfile;
127 const char *prevfile;
130 #define TRACEBUF struct qm_trace trace; 131 #define TRACEBUF_INITIALIZER { __LINE__, 0, __FILE__, NULL } , 133 #define QMD_TRACE_HEAD(head) do { \ 134 (head)->trace.prevline = (head)->trace.lastline; \ 135 (head)->trace.prevfile = (head)->trace.lastfile; \ 136 (head)->trace.lastline = __LINE__; \ 137 (head)->trace.lastfile = __FILE__; \ 140 #define QMD_TRACE_ELEM(elem) do { \ 141 (elem)->trace.prevline = (elem)->trace.lastline; \ 142 (elem)->trace.prevfile = (elem)->trace.lastfile; \ 143 (elem)->trace.lastline = __LINE__; \ 144 (elem)->trace.lastfile = __FILE__; \ 148 #define QMD_TRACE_ELEM(elem) 149 #define QMD_TRACE_HEAD(head) 151 #define TRACEBUF_INITIALIZER 154 #ifdef QUEUE_MACRO_DEBUG_TRASH 155 #define TRASHIT(x) do {(x) = (void *)-1;} while (0) 156 #define QMD_IS_TRASHED(x) ((x) == (void *)(intptr_t)-1) 159 #define QMD_IS_TRASHED(x) 0 162 #if defined(QUEUE_MACRO_DEBUG_TRACE) || defined(QUEUE_MACRO_DEBUG_TRASH) 163 #define QMD_SAVELINK(name, link) void **name = (void *)&(link) 165 #define QMD_SAVELINK(name, link) 172 #define QUEUE_TYPEOF(type) type 174 #define QUEUE_TYPEOF(type) struct type 180 #define SLIST_HEAD(name, type) \ 182 struct type *slh_first; \ 185 #define SLIST_CLASS_HEAD(name, type) \ 187 class type *slh_first; \ 190 #define SLIST_HEAD_INITIALIZER(head) \ 193 #define SLIST_ENTRY(type) \ 195 struct type *sle_next; \ 198 #define SLIST_CLASS_ENTRY(type) \ 200 class type *sle_next; \ 206 #if (defined(_KERNEL) && defined(INVARIANTS)) 207 #define QMD_SLIST_CHECK_PREVPTR(prevp, elm) do { \ 208 if (*(prevp) != (elm)) \ 209 panic("Bad prevptr *(%p) == %p != %p", \ 210 (prevp), *(prevp), (elm)); \ 213 #define QMD_SLIST_CHECK_PREVPTR(prevp, elm) 216 #define SLIST_CONCAT(head1, head2, type, field) do { \ 217 QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head1); \ 218 if (curelm == NULL) { \ 219 if ((SLIST_FIRST(head1) = SLIST_FIRST(head2)) != NULL) \ 221 } else if (SLIST_FIRST(head2) != NULL) { \ 222 while (SLIST_NEXT(curelm, field) != NULL) \ 223 curelm = SLIST_NEXT(curelm, field); \ 224 SLIST_NEXT(curelm, field) = SLIST_FIRST(head2); \ 229 #define SLIST_EMPTY(head) ((head)->slh_first == NULL) 231 #define SLIST_FIRST(head) ((head)->slh_first) 233 #define SLIST_FOREACH(var, head, field) \ 234 for ((var) = SLIST_FIRST((head)); \ 236 (var) = SLIST_NEXT((var), field)) 238 #define SLIST_FOREACH_FROM(var, head, field) \ 239 for ((var) = ((var) ? (var) : SLIST_FIRST((head))); \ 241 (var) = SLIST_NEXT((var), field)) 243 #define SLIST_FOREACH_SAFE(var, head, field, tvar) \ 244 for ((var) = SLIST_FIRST((head)); \ 245 (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ 248 #define SLIST_FOREACH_FROM_SAFE(var, head, field, tvar) \ 249 for ((var) = ((var) ? (var) : SLIST_FIRST((head))); \ 250 (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ 253 #define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ 254 for ((varp) = &SLIST_FIRST((head)); \ 255 ((var) = *(varp)) != NULL; \ 256 (varp) = &SLIST_NEXT((var), field)) 258 #define SLIST_INIT(head) do { \ 259 SLIST_FIRST((head)) = NULL; \ 262 #define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ 263 SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \ 264 SLIST_NEXT((slistelm), field) = (elm); \ 267 #define SLIST_INSERT_HEAD(head, elm, field) do { \ 268 SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \ 269 SLIST_FIRST((head)) = (elm); \ 272 #define SLIST_NEXT(elm, field) ((elm)->field.sle_next) 274 #define SLIST_REMOVE(head, elm, type, field) do { \ 275 QMD_SAVELINK(oldnext, (elm)->field.sle_next); \ 276 if (SLIST_FIRST((head)) == (elm)) { \ 277 SLIST_REMOVE_HEAD((head), field); \ 280 QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head); \ 281 while (SLIST_NEXT(curelm, field) != (elm)) \ 282 curelm = SLIST_NEXT(curelm, field); \ 283 SLIST_REMOVE_AFTER(curelm, field); \ 288 #define SLIST_REMOVE_AFTER(elm, field) do { \ 289 SLIST_NEXT(elm, field) = \ 290 SLIST_NEXT(SLIST_NEXT(elm, field), field); \ 293 #define SLIST_REMOVE_HEAD(head, field) do { \ 294 SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \ 297 #define SLIST_REMOVE_PREVPTR(prevp, elm, field) do { \ 298 QMD_SLIST_CHECK_PREVPTR(prevp, elm); \ 299 *(prevp) = SLIST_NEXT(elm, field); \ 300 TRASHIT((elm)->field.sle_next); \ 303 #define SLIST_SWAP(head1, head2, type) do { \ 304 QUEUE_TYPEOF(type) *swap_first = SLIST_FIRST(head1); \ 305 SLIST_FIRST(head1) = SLIST_FIRST(head2); \ 306 SLIST_FIRST(head2) = swap_first; \ 312 #define STAILQ_HEAD(name, type) \ 314 struct type *stqh_first; \ 315 struct type **stqh_last; \ 318 #define STAILQ_CLASS_HEAD(name, type) \ 320 class type *stqh_first; \ 321 class type **stqh_last; \ 324 #define STAILQ_HEAD_INITIALIZER(head) \ 325 { NULL, &(head).stqh_first } 327 #define STAILQ_ENTRY(type) \ 329 struct type *stqe_next; \ 332 #define STAILQ_CLASS_ENTRY(type) \ 334 class type *stqe_next; \ 340 #define STAILQ_CONCAT(head1, head2) do { \ 341 if (!STAILQ_EMPTY((head2))) { \ 342 *(head1)->stqh_last = (head2)->stqh_first; \ 343 (head1)->stqh_last = (head2)->stqh_last; \ 344 STAILQ_INIT((head2)); \ 348 #define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) 350 #define STAILQ_FIRST(head) ((head)->stqh_first) 352 #define STAILQ_FOREACH(var, head, field) \ 353 for((var) = STAILQ_FIRST((head)); \ 355 (var) = STAILQ_NEXT((var), field)) 357 #define STAILQ_FOREACH_FROM(var, head, field) \ 358 for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); \ 360 (var) = STAILQ_NEXT((var), field)) 362 #define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ 363 for ((var) = STAILQ_FIRST((head)); \ 364 (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ 367 #define STAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \ 368 for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); \ 369 (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ 372 #define STAILQ_INIT(head) do { \ 373 STAILQ_FIRST((head)) = NULL; \ 374 (head)->stqh_last = &STAILQ_FIRST((head)); \ 377 #define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ 378 if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\ 379 (head)->stqh_last = &STAILQ_NEXT((elm), field); \ 380 STAILQ_NEXT((tqelm), field) = (elm); \ 383 #define STAILQ_INSERT_HEAD(head, elm, field) do { \ 384 if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ 385 (head)->stqh_last = &STAILQ_NEXT((elm), field); \ 386 STAILQ_FIRST((head)) = (elm); \ 389 #define STAILQ_INSERT_TAIL(head, elm, field) do { \ 390 STAILQ_NEXT((elm), field) = NULL; \ 391 *(head)->stqh_last = (elm); \ 392 (head)->stqh_last = &STAILQ_NEXT((elm), field); \ 395 #define STAILQ_LAST(head, type, field) \ 396 (STAILQ_EMPTY((head)) ? NULL : \ 397 __containerof((head)->stqh_last, \ 398 QUEUE_TYPEOF(type), field.stqe_next)) 400 #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) 402 #define STAILQ_REMOVE(head, elm, type, field) do { \ 403 QMD_SAVELINK(oldnext, (elm)->field.stqe_next); \ 404 if (STAILQ_FIRST((head)) == (elm)) { \ 405 STAILQ_REMOVE_HEAD((head), field); \ 408 QUEUE_TYPEOF(type) *curelm = STAILQ_FIRST(head); \ 409 while (STAILQ_NEXT(curelm, field) != (elm)) \ 410 curelm = STAILQ_NEXT(curelm, field); \ 411 STAILQ_REMOVE_AFTER(head, curelm, field); \ 416 #define STAILQ_REMOVE_AFTER(head, elm, field) do { \ 417 if ((STAILQ_NEXT(elm, field) = \ 418 STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \ 419 (head)->stqh_last = &STAILQ_NEXT((elm), field); \ 422 #define STAILQ_REMOVE_HEAD(head, field) do { \ 423 if ((STAILQ_FIRST((head)) = \ 424 STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ 425 (head)->stqh_last = &STAILQ_FIRST((head)); \ 428 #define STAILQ_SWAP(head1, head2, type) do { \ 429 QUEUE_TYPEOF(type) *swap_first = STAILQ_FIRST(head1); \ 430 QUEUE_TYPEOF(type) **swap_last = (head1)->stqh_last; \ 431 STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \ 432 (head1)->stqh_last = (head2)->stqh_last; \ 433 STAILQ_FIRST(head2) = swap_first; \ 434 (head2)->stqh_last = swap_last; \ 435 if (STAILQ_EMPTY(head1)) \ 436 (head1)->stqh_last = &STAILQ_FIRST(head1); \ 437 if (STAILQ_EMPTY(head2)) \ 438 (head2)->stqh_last = &STAILQ_FIRST(head2); \ 445 #define LIST_HEAD(name, type) \ 447 struct type *lh_first; \ 450 #define LIST_CLASS_HEAD(name, type) \ 452 class type *lh_first; \ 455 #define LIST_HEAD_INITIALIZER(head) \ 458 #define LIST_ENTRY(type) \ 460 struct type *le_next; \ 461 struct type **le_prev; \ 464 #define LIST_CLASS_ENTRY(type) \ 466 class type *le_next; \ 467 class type **le_prev; \ 474 #if (defined(_KERNEL) && defined(INVARIANTS)) 481 #define QMD_LIST_CHECK_HEAD(head, field) do { \ 482 if (LIST_FIRST((head)) != NULL && \ 483 LIST_FIRST((head))->field.le_prev != \ 484 &LIST_FIRST((head))) \ 485 panic("Bad list head %p first->prev != head", (head)); \ 494 #define QMD_LIST_CHECK_NEXT(elm, field) do { \ 495 if (LIST_NEXT((elm), field) != NULL && \ 496 LIST_NEXT((elm), field)->field.le_prev != \ 497 &((elm)->field.le_next)) \ 498 panic("Bad link elm %p next->prev != elm", (elm)); \ 506 #define QMD_LIST_CHECK_PREV(elm, field) do { \ 507 if (*(elm)->field.le_prev != (elm)) \ 508 panic("Bad link elm %p prev->next != elm", (elm)); \ 511 #define QMD_LIST_CHECK_HEAD(head, field) 512 #define QMD_LIST_CHECK_NEXT(elm, field) 513 #define QMD_LIST_CHECK_PREV(elm, field) 516 #define LIST_CONCAT(head1, head2, type, field) do { \ 517 QUEUE_TYPEOF(type) *curelm = LIST_FIRST(head1); \ 518 if (curelm == NULL) { \ 519 if ((LIST_FIRST(head1) = LIST_FIRST(head2)) != NULL) { \ 520 LIST_FIRST(head2)->field.le_prev = \ 521 &LIST_FIRST((head1)); \ 524 } else if (LIST_FIRST(head2) != NULL) { \ 525 while (LIST_NEXT(curelm, field) != NULL) \ 526 curelm = LIST_NEXT(curelm, field); \ 527 LIST_NEXT(curelm, field) = LIST_FIRST(head2); \ 528 LIST_FIRST(head2)->field.le_prev = &LIST_NEXT(curelm, field); \ 533 #define LIST_EMPTY(head) ((head)->lh_first == NULL) 535 #define LIST_FIRST(head) ((head)->lh_first) 537 #define LIST_FOREACH(var, head, field) \ 538 for ((var) = LIST_FIRST((head)); \ 540 (var) = LIST_NEXT((var), field)) 542 #define LIST_FOREACH_FROM(var, head, field) \ 543 for ((var) = ((var) ? (var) : LIST_FIRST((head))); \ 545 (var) = LIST_NEXT((var), field)) 547 #define LIST_FOREACH_SAFE(var, head, field, tvar) \ 548 for ((var) = LIST_FIRST((head)); \ 549 (var) && ((tvar) = LIST_NEXT((var), field), 1); \ 552 #define LIST_FOREACH_FROM_SAFE(var, head, field, tvar) \ 553 for ((var) = ((var) ? (var) : LIST_FIRST((head))); \ 554 (var) && ((tvar) = LIST_NEXT((var), field), 1); \ 557 #define LIST_INIT(head) do { \ 558 LIST_FIRST((head)) = NULL; \ 561 #define LIST_INSERT_AFTER(listelm, elm, field) do { \ 562 QMD_LIST_CHECK_NEXT(listelm, field); \ 563 if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\ 564 LIST_NEXT((listelm), field)->field.le_prev = \ 565 &LIST_NEXT((elm), field); \ 566 LIST_NEXT((listelm), field) = (elm); \ 567 (elm)->field.le_prev = &LIST_NEXT((listelm), field); \ 570 #define LIST_INSERT_BEFORE(listelm, elm, field) do { \ 571 QMD_LIST_CHECK_PREV(listelm, field); \ 572 (elm)->field.le_prev = (listelm)->field.le_prev; \ 573 LIST_NEXT((elm), field) = (listelm); \ 574 *(listelm)->field.le_prev = (elm); \ 575 (listelm)->field.le_prev = &LIST_NEXT((elm), field); \ 578 #define LIST_INSERT_HEAD(head, elm, field) do { \ 579 QMD_LIST_CHECK_HEAD((head), field); \ 580 if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \ 581 LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\ 582 LIST_FIRST((head)) = (elm); \ 583 (elm)->field.le_prev = &LIST_FIRST((head)); \ 586 #define LIST_NEXT(elm, field) ((elm)->field.le_next) 588 #define LIST_PREV(elm, head, type, field) \ 589 ((elm)->field.le_prev == &LIST_FIRST((head)) ? NULL : \ 590 __containerof((elm)->field.le_prev, \ 591 QUEUE_TYPEOF(type), field.le_next)) 593 #define LIST_REMOVE(elm, field) do { \ 594 QMD_SAVELINK(oldnext, (elm)->field.le_next); \ 595 QMD_SAVELINK(oldprev, (elm)->field.le_prev); \ 596 QMD_LIST_CHECK_NEXT(elm, field); \ 597 QMD_LIST_CHECK_PREV(elm, field); \ 598 if (LIST_NEXT((elm), field) != NULL) \ 599 LIST_NEXT((elm), field)->field.le_prev = \ 600 (elm)->field.le_prev; \ 601 *(elm)->field.le_prev = LIST_NEXT((elm), field); \ 606 #define LIST_SWAP(head1, head2, type, field) do { \ 607 QUEUE_TYPEOF(type) *swap_tmp = LIST_FIRST(head1); \ 608 LIST_FIRST((head1)) = LIST_FIRST((head2)); \ 609 LIST_FIRST((head2)) = swap_tmp; \ 610 if ((swap_tmp = LIST_FIRST((head1))) != NULL) \ 611 swap_tmp->field.le_prev = &LIST_FIRST((head1)); \ 612 if ((swap_tmp = LIST_FIRST((head2))) != NULL) \ 613 swap_tmp->field.le_prev = &LIST_FIRST((head2)); \ 619 #define TAILQ_HEAD(name, type) \ 621 struct type *tqh_first; \ 622 struct type **tqh_last; \ 626 #define TAILQ_CLASS_HEAD(name, type) \ 628 class type *tqh_first; \ 629 class type **tqh_last; \ 633 #define TAILQ_HEAD_INITIALIZER(head) \ 634 { NULL, &(head).tqh_first, TRACEBUF_INITIALIZER } 636 #define TAILQ_ENTRY(type) \ 638 struct type *tqe_next; \ 639 struct type **tqe_prev; \ 643 #define TAILQ_CLASS_ENTRY(type) \ 645 class type *tqe_next; \ 646 class type **tqe_prev; \ 653 #if (defined(_KERNEL) && defined(INVARIANTS)) 660 #define QMD_TAILQ_CHECK_HEAD(head, field) do { \ 661 if (!TAILQ_EMPTY(head) && \ 662 TAILQ_FIRST((head))->field.tqe_prev != \ 663 &TAILQ_FIRST((head))) \ 664 panic("Bad tailq head %p first->prev != head", (head)); \ 672 #define QMD_TAILQ_CHECK_TAIL(head, field) do { \ 673 if (*(head)->tqh_last != NULL) \ 674 panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \ 683 #define QMD_TAILQ_CHECK_NEXT(elm, field) do { \ 684 if (TAILQ_NEXT((elm), field) != NULL && \ 685 TAILQ_NEXT((elm), field)->field.tqe_prev != \ 686 &((elm)->field.tqe_next)) \ 687 panic("Bad link elm %p next->prev != elm", (elm)); \ 695 #define QMD_TAILQ_CHECK_PREV(elm, field) do { \ 696 if (*(elm)->field.tqe_prev != (elm)) \ 697 panic("Bad link elm %p prev->next != elm", (elm)); \ 700 #define QMD_TAILQ_CHECK_HEAD(head, field) 701 #define QMD_TAILQ_CHECK_TAIL(head, headname) 702 #define QMD_TAILQ_CHECK_NEXT(elm, field) 703 #define QMD_TAILQ_CHECK_PREV(elm, field) 706 #define TAILQ_CONCAT(head1, head2, field) do { \ 707 if (!TAILQ_EMPTY(head2)) { \ 708 *(head1)->tqh_last = (head2)->tqh_first; \ 709 (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ 710 (head1)->tqh_last = (head2)->tqh_last; \ 711 TAILQ_INIT((head2)); \ 712 QMD_TRACE_HEAD(head1); \ 713 QMD_TRACE_HEAD(head2); \ 717 #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) 719 #define TAILQ_FIRST(head) ((head)->tqh_first) 721 #define TAILQ_FOREACH(var, head, field) \ 722 for ((var) = TAILQ_FIRST((head)); \ 724 (var) = TAILQ_NEXT((var), field)) 726 #define TAILQ_FOREACH_FROM(var, head, field) \ 727 for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); \ 729 (var) = TAILQ_NEXT((var), field)) 731 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ 732 for ((var) = TAILQ_FIRST((head)); \ 733 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ 736 #define TAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \ 737 for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); \ 738 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ 741 #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ 742 for ((var) = TAILQ_LAST((head), headname); \ 744 (var) = TAILQ_PREV((var), headname, field)) 746 #define TAILQ_FOREACH_REVERSE_FROM(var, head, headname, field) \ 747 for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); \ 749 (var) = TAILQ_PREV((var), headname, field)) 751 #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ 752 for ((var) = TAILQ_LAST((head), headname); \ 753 (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ 756 #define TAILQ_FOREACH_REVERSE_FROM_SAFE(var, head, headname, field, tvar) \ 757 for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); \ 758 (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ 761 #define TAILQ_INIT(head) do { \ 762 TAILQ_FIRST((head)) = NULL; \ 763 (head)->tqh_last = &TAILQ_FIRST((head)); \ 764 QMD_TRACE_HEAD(head); \ 767 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ 768 QMD_TAILQ_CHECK_NEXT(listelm, field); \ 769 if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\ 770 TAILQ_NEXT((elm), field)->field.tqe_prev = \ 771 &TAILQ_NEXT((elm), field); \ 773 (head)->tqh_last = &TAILQ_NEXT((elm), field); \ 774 QMD_TRACE_HEAD(head); \ 776 TAILQ_NEXT((listelm), field) = (elm); \ 777 (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \ 778 QMD_TRACE_ELEM(&(elm)->field); \ 779 QMD_TRACE_ELEM(&(listelm)->field); \ 782 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ 783 QMD_TAILQ_CHECK_PREV(listelm, field); \ 784 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ 785 TAILQ_NEXT((elm), field) = (listelm); \ 786 *(listelm)->field.tqe_prev = (elm); \ 787 (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \ 788 QMD_TRACE_ELEM(&(elm)->field); \ 789 QMD_TRACE_ELEM(&(listelm)->field); \ 792 #define TAILQ_INSERT_HEAD(head, elm, field) do { \ 793 QMD_TAILQ_CHECK_HEAD(head, field); \ 794 if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \ 795 TAILQ_FIRST((head))->field.tqe_prev = \ 796 &TAILQ_NEXT((elm), field); \ 798 (head)->tqh_last = &TAILQ_NEXT((elm), field); \ 799 TAILQ_FIRST((head)) = (elm); \ 800 (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \ 801 QMD_TRACE_HEAD(head); \ 802 QMD_TRACE_ELEM(&(elm)->field); \ 805 #define TAILQ_INSERT_TAIL(head, elm, field) do { \ 806 QMD_TAILQ_CHECK_TAIL(head, field); \ 807 TAILQ_NEXT((elm), field) = NULL; \ 808 (elm)->field.tqe_prev = (head)->tqh_last; \ 809 *(head)->tqh_last = (elm); \ 810 (head)->tqh_last = &TAILQ_NEXT((elm), field); \ 811 QMD_TRACE_HEAD(head); \ 812 QMD_TRACE_ELEM(&(elm)->field); \ 815 #define TAILQ_LAST(head, headname) \ 816 (*(((struct headname *)((head)->tqh_last))->tqh_last)) 818 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) 820 #define TAILQ_PREV(elm, headname, field) \ 821 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) 823 #define TAILQ_REMOVE(head, elm, field) do { \ 824 QMD_SAVELINK(oldnext, (elm)->field.tqe_next); \ 825 QMD_SAVELINK(oldprev, (elm)->field.tqe_prev); \ 826 QMD_TAILQ_CHECK_NEXT(elm, field); \ 827 QMD_TAILQ_CHECK_PREV(elm, field); \ 828 if ((TAILQ_NEXT((elm), field)) != NULL) \ 829 TAILQ_NEXT((elm), field)->field.tqe_prev = \ 830 (elm)->field.tqe_prev; \ 832 (head)->tqh_last = (elm)->field.tqe_prev; \ 833 QMD_TRACE_HEAD(head); \ 835 *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ 838 QMD_TRACE_ELEM(&(elm)->field); \ 841 #define TAILQ_SWAP(head1, head2, type, field) do { \ 842 QUEUE_TYPEOF(type) *swap_first = (head1)->tqh_first; \ 843 QUEUE_TYPEOF(type) **swap_last = (head1)->tqh_last; \ 844 (head1)->tqh_first = (head2)->tqh_first; \ 845 (head1)->tqh_last = (head2)->tqh_last; \ 846 (head2)->tqh_first = swap_first; \ 847 (head2)->tqh_last = swap_last; \ 848 if ((swap_first = (head1)->tqh_first) != NULL) \ 849 swap_first->field.tqe_prev = &(head1)->tqh_first; \ 851 (head1)->tqh_last = &(head1)->tqh_first; \ 852 if ((swap_first = (head2)->tqh_first) != NULL) \ 853 swap_first->field.tqe_prev = &(head2)->tqh_first; \ 855 (head2)->tqh_last = &(head2)->tqh_first; \