queue.h revision 158929
1139969Simp/*- 269110Sphk * Copyright (c) 1991, 1993 369110Sphk * The Regents of the University of California. All rights reserved. 469110Sphk * 569110Sphk * Redistribution and use in source and binary forms, with or without 669110Sphk * modification, are permitted provided that the following conditions 769110Sphk * are met: 869110Sphk * 1. Redistributions of source code must retain the above copyright 969110Sphk * notice, this list of conditions and the following disclaimer. 1069110Sphk * 2. Redistributions in binary form must reproduce the above copyright 1169110Sphk * notice, this list of conditions and the following disclaimer in the 1269110Sphk * documentation and/or other materials provided with the distribution. 1369110Sphk * 4. Neither the name of the University nor the names of its contributors 1469110Sphk * may be used to endorse or promote products derived from this software 1569110Sphk * without specific prior written permission. 1669110Sphk * 1769110Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1869110Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1969110Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2069110Sphk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2169110Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2269110Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2369110Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2469110Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2569110Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2669110Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2769110Sphk * SUCH DAMAGE. 2869110Sphk * 2969110Sphk * @(#)queue.h 8.5 (Berkeley) 8/20/94 3069110Sphk * $FreeBSD: head/sys/sys/queue.h 158929 2006-05-26 02:26:53Z emaste $ 3169110Sphk */ 3269110Sphk 3369110Sphk#ifndef _SYS_QUEUE_H_ 3469110Sphk#define _SYS_QUEUE_H_ 3569110Sphk 36223372Sru#include <sys/cdefs.h> 3769110Sphk 3879526Sru/* 3969110Sphk * This file defines four types of data structures: singly-linked lists, 4069110Sphk * singly-linked tail queues, lists and tail queues. 4169110Sphk * 4269110Sphk * A singly-linked list is headed by a single forward pointer. The elements 4369110Sphk * are singly linked for minimum space and pointer manipulation overhead at 44176977Srwatson * the expense of O(n) removal for arbitrary elements. New elements can be 45223372Sru * added to the list after an existing element or at the head of the list. 4669110Sphk * Elements being removed from the head of the list should use the explicit 4795122Scharnier * macro for this purpose for optimum efficiency. A singly-linked list may 4869119Sru * only be traversed in the forward direction. Singly-linked lists are ideal 4995122Scharnier * for applications with large datasets and few or no removals or for 5069110Sphk * implementing a LIFO queue. 5169119Sru * 5269119Sru * A singly-linked tail queue is headed by a pair of pointers, one to the 5369119Sru * head of the list and the other to the tail of the list. The elements are 5469119Sru * singly linked for minimum space and pointer manipulation overhead at the 5569119Sru * expense of O(n) removal for arbitrary elements. New elements can be added 5669110Sphk * to the list after an existing element, at the head of the list, or at the 5769110Sphk * end of the list. Elements being removed from the head of the tail queue 5869110Sphk * should use the explicit macro for this purpose for optimum efficiency. 59223372Sru * A singly-linked tail queue may only be traversed in the forward direction. 60223372Sru * Singly-linked tail queues are ideal for applications with large datasets 61223372Sru * and few or no removals or for implementing a FIFO queue. 62223372Sru * 63223372Sru * A list is headed by a single forward pointer (or an array of forward 64176977Srwatson * pointers for a hash table header). The elements are doubly linked 65176977Srwatson * so that an arbitrary element can be removed without a need to 66176977Srwatson * traverse the list. New elements can be added to the list before 67176977Srwatson * or after an existing element or at the head of the list. A list 68176977Srwatson * may only be traversed in the forward direction. 69176977Srwatson * 70140353Sru * A tail queue is headed by a pair of pointers, one to the head of the 7181687Sru * list and the other to the tail of the list. The elements are doubly 7269110Sphk * linked so that an arbitrary element can be removed without a need to 7369119Sru * traverse the list. New elements can be added to the list before or 7469119Sru * after an existing element, at the head of the list, or at the end of 7569119Sru * the list. A tail queue may be traversed in either direction. 7669119Sru * 7769119Sru * For details on the use of these macros, see the queue(3) manual page. 7872853Sru * 79 * 80 * SLIST LIST STAILQ TAILQ 81 * _HEAD + + + + 82 * _HEAD_INITIALIZER + + + + 83 * _ENTRY + + + + 84 * _INIT + + + + 85 * _EMPTY + + + + 86 * _FIRST + + + + 87 * _NEXT + + + + 88 * _PREV - - - + 89 * _LAST - - + + 90 * _FOREACH + + + + 91 * _FOREACH_SAFE + + + + 92 * _FOREACH_REVERSE - - - + 93 * _FOREACH_REVERSE_SAFE - - - + 94 * _INSERT_HEAD + + + + 95 * _INSERT_BEFORE - + - + 96 * _INSERT_AFTER + + + + 97 * _INSERT_TAIL - - + + 98 * _CONCAT - - + + 99 * _REMOVE_HEAD + - + - 100 * _REMOVE + + + + 101 * 102 */ 103#ifdef QUEUE_MACRO_DEBUG 104/* Store the last 2 places the queue element or head was altered */ 105struct qm_trace { 106 char * lastfile; 107 int lastline; 108 char * prevfile; 109 int prevline; 110}; 111 112#define TRACEBUF struct qm_trace trace; 113#define TRASHIT(x) do {(x) = (void *)-1;} while (0) 114 115#define QMD_TRACE_HEAD(head) do { \ 116 (head)->trace.prevline = (head)->trace.lastline; \ 117 (head)->trace.prevfile = (head)->trace.lastfile; \ 118 (head)->trace.lastline = __LINE__; \ 119 (head)->trace.lastfile = __FILE__; \ 120} while (0) 121 122#define QMD_TRACE_ELEM(elem) do { \ 123 (elem)->trace.prevline = (elem)->trace.lastline; \ 124 (elem)->trace.prevfile = (elem)->trace.lastfile; \ 125 (elem)->trace.lastline = __LINE__; \ 126 (elem)->trace.lastfile = __FILE__; \ 127} while (0) 128 129#else 130#define QMD_TRACE_ELEM(elem) 131#define QMD_TRACE_HEAD(head) 132#define TRACEBUF 133#define TRASHIT(x) 134#endif /* QUEUE_MACRO_DEBUG */ 135 136/* 137 * Singly-linked List declarations. 138 */ 139#define SLIST_HEAD(name, type) \ 140struct name { \ 141 struct type *slh_first; /* first element */ \ 142} 143 144#define SLIST_HEAD_INITIALIZER(head) \ 145 { NULL } 146 147#define SLIST_ENTRY(type) \ 148struct { \ 149 struct type *sle_next; /* next element */ \ 150} 151 152/* 153 * Singly-linked List functions. 154 */ 155#define SLIST_EMPTY(head) ((head)->slh_first == NULL) 156 157#define SLIST_FIRST(head) ((head)->slh_first) 158 159#define SLIST_FOREACH(var, head, field) \ 160 for ((var) = SLIST_FIRST((head)); \ 161 (var); \ 162 (var) = SLIST_NEXT((var), field)) 163 164#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ 165 for ((var) = SLIST_FIRST((head)); \ 166 (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ 167 (var) = (tvar)) 168 169#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ 170 for ((varp) = &SLIST_FIRST((head)); \ 171 ((var) = *(varp)) != NULL; \ 172 (varp) = &SLIST_NEXT((var), field)) 173 174#define SLIST_INIT(head) do { \ 175 SLIST_FIRST((head)) = NULL; \ 176} while (0) 177 178#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ 179 SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \ 180 SLIST_NEXT((slistelm), field) = (elm); \ 181} while (0) 182 183#define SLIST_INSERT_HEAD(head, elm, field) do { \ 184 SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \ 185 SLIST_FIRST((head)) = (elm); \ 186} while (0) 187 188#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) 189 190#define SLIST_REMOVE(head, elm, type, field) do { \ 191 if (SLIST_FIRST((head)) == (elm)) { \ 192 SLIST_REMOVE_HEAD((head), field); \ 193 } \ 194 else { \ 195 struct type *curelm = SLIST_FIRST((head)); \ 196 while (SLIST_NEXT(curelm, field) != (elm)) \ 197 curelm = SLIST_NEXT(curelm, field); \ 198 SLIST_NEXT(curelm, field) = \ 199 SLIST_NEXT(SLIST_NEXT(curelm, field), field); \ 200 } \ 201 TRASHIT((elm)->field.sle_next); \ 202} while (0) 203 204#define SLIST_REMOVE_HEAD(head, field) do { \ 205 SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \ 206} while (0) 207 208/* 209 * Singly-linked Tail queue declarations. 210 */ 211#define STAILQ_HEAD(name, type) \ 212struct name { \ 213 struct type *stqh_first;/* first element */ \ 214 struct type **stqh_last;/* addr of last next element */ \ 215} 216 217#define STAILQ_HEAD_INITIALIZER(head) \ 218 { NULL, &(head).stqh_first } 219 220#define STAILQ_ENTRY(type) \ 221struct { \ 222 struct type *stqe_next; /* next element */ \ 223} 224 225/* 226 * Singly-linked Tail queue functions. 227 */ 228#define STAILQ_CONCAT(head1, head2) do { \ 229 if (!STAILQ_EMPTY((head2))) { \ 230 *(head1)->stqh_last = (head2)->stqh_first; \ 231 (head1)->stqh_last = (head2)->stqh_last; \ 232 STAILQ_INIT((head2)); \ 233 } \ 234} while (0) 235 236#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) 237 238#define STAILQ_FIRST(head) ((head)->stqh_first) 239 240#define STAILQ_FOREACH(var, head, field) \ 241 for((var) = STAILQ_FIRST((head)); \ 242 (var); \ 243 (var) = STAILQ_NEXT((var), field)) 244 245 246#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ 247 for ((var) = STAILQ_FIRST((head)); \ 248 (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ 249 (var) = (tvar)) 250 251#define STAILQ_INIT(head) do { \ 252 STAILQ_FIRST((head)) = NULL; \ 253 (head)->stqh_last = &STAILQ_FIRST((head)); \ 254} while (0) 255 256#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ 257 if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\ 258 (head)->stqh_last = &STAILQ_NEXT((elm), field); \ 259 STAILQ_NEXT((tqelm), field) = (elm); \ 260} while (0) 261 262#define STAILQ_INSERT_HEAD(head, elm, field) do { \ 263 if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ 264 (head)->stqh_last = &STAILQ_NEXT((elm), field); \ 265 STAILQ_FIRST((head)) = (elm); \ 266} while (0) 267 268#define STAILQ_INSERT_TAIL(head, elm, field) do { \ 269 STAILQ_NEXT((elm), field) = NULL; \ 270 *(head)->stqh_last = (elm); \ 271 (head)->stqh_last = &STAILQ_NEXT((elm), field); \ 272} while (0) 273 274#define STAILQ_LAST(head, type, field) \ 275 (STAILQ_EMPTY((head)) ? \ 276 NULL : \ 277 ((struct type *)(void *) \ 278 ((char *)((head)->stqh_last) - __offsetof(struct type, field)))) 279 280#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) 281 282#define STAILQ_REMOVE(head, elm, type, field) do { \ 283 if (STAILQ_FIRST((head)) == (elm)) { \ 284 STAILQ_REMOVE_HEAD((head), field); \ 285 } \ 286 else { \ 287 struct type *curelm = STAILQ_FIRST((head)); \ 288 while (STAILQ_NEXT(curelm, field) != (elm)) \ 289 curelm = STAILQ_NEXT(curelm, field); \ 290 if ((STAILQ_NEXT(curelm, field) = \ 291 STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\ 292 (head)->stqh_last = &STAILQ_NEXT((curelm), field);\ 293 } \ 294 TRASHIT((elm)->field.stqe_next); \ 295} while (0) 296 297#define STAILQ_REMOVE_HEAD(head, field) do { \ 298 if ((STAILQ_FIRST((head)) = \ 299 STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ 300 (head)->stqh_last = &STAILQ_FIRST((head)); \ 301} while (0) 302 303#define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \ 304 if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \ 305 (head)->stqh_last = &STAILQ_FIRST((head)); \ 306} while (0) 307 308/* 309 * List declarations. 310 */ 311#define LIST_HEAD(name, type) \ 312struct name { \ 313 struct type *lh_first; /* first element */ \ 314} 315 316#define LIST_HEAD_INITIALIZER(head) \ 317 { NULL } 318 319#define LIST_ENTRY(type) \ 320struct { \ 321 struct type *le_next; /* next element */ \ 322 struct type **le_prev; /* address of previous next element */ \ 323} 324 325/* 326 * List functions. 327 */ 328 329#if (defined(_KERNEL) && defined(INVARIANTS)) 330#define QMD_LIST_CHECK_HEAD(head, field) do { \ 331 if (LIST_FIRST((head)) != NULL && \ 332 LIST_FIRST((head))->field.le_prev != \ 333 &LIST_FIRST((head))) \ 334 panic("Bad list head %p first->prev != head", (head)); \ 335} while (0) 336 337#define QMD_LIST_CHECK_NEXT(elm, field) do { \ 338 if (LIST_NEXT((elm), field) != NULL && \ 339 LIST_NEXT((elm), field)->field.le_prev != \ 340 &((elm)->field.le_next)) \ 341 panic("Bad link elm %p next->prev != elm", (elm)); \ 342} while (0) 343 344#define QMD_LIST_CHECK_PREV(elm, field) do { \ 345 if (*(elm)->field.le_prev != (elm)) \ 346 panic("Bad link elm %p prev->next != elm", (elm)); \ 347} while (0) 348#else 349#define QMD_LIST_CHECK_HEAD(head, field) 350#define QMD_LIST_CHECK_NEXT(elm, field) 351#define QMD_LIST_CHECK_PREV(elm, field) 352#endif /* (_KERNEL && INVARIANTS) */ 353 354#define LIST_EMPTY(head) ((head)->lh_first == NULL) 355 356#define LIST_FIRST(head) ((head)->lh_first) 357 358#define LIST_FOREACH(var, head, field) \ 359 for ((var) = LIST_FIRST((head)); \ 360 (var); \ 361 (var) = LIST_NEXT((var), field)) 362 363#define LIST_FOREACH_SAFE(var, head, field, tvar) \ 364 for ((var) = LIST_FIRST((head)); \ 365 (var) && ((tvar) = LIST_NEXT((var), field), 1); \ 366 (var) = (tvar)) 367 368#define LIST_INIT(head) do { \ 369 LIST_FIRST((head)) = NULL; \ 370} while (0) 371 372#define LIST_INSERT_AFTER(listelm, elm, field) do { \ 373 QMD_LIST_CHECK_NEXT(listelm, field); \ 374 if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\ 375 LIST_NEXT((listelm), field)->field.le_prev = \ 376 &LIST_NEXT((elm), field); \ 377 LIST_NEXT((listelm), field) = (elm); \ 378 (elm)->field.le_prev = &LIST_NEXT((listelm), field); \ 379} while (0) 380 381#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ 382 QMD_LIST_CHECK_PREV(listelm, field); \ 383 (elm)->field.le_prev = (listelm)->field.le_prev; \ 384 LIST_NEXT((elm), field) = (listelm); \ 385 *(listelm)->field.le_prev = (elm); \ 386 (listelm)->field.le_prev = &LIST_NEXT((elm), field); \ 387} while (0) 388 389#define LIST_INSERT_HEAD(head, elm, field) do { \ 390 QMD_LIST_CHECK_HEAD((head), field); \ 391 if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \ 392 LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\ 393 LIST_FIRST((head)) = (elm); \ 394 (elm)->field.le_prev = &LIST_FIRST((head)); \ 395} while (0) 396 397#define LIST_NEXT(elm, field) ((elm)->field.le_next) 398 399#define LIST_REMOVE(elm, field) do { \ 400 QMD_LIST_CHECK_NEXT(elm, field); \ 401 QMD_LIST_CHECK_PREV(elm, field); \ 402 if (LIST_NEXT((elm), field) != NULL) \ 403 LIST_NEXT((elm), field)->field.le_prev = \ 404 (elm)->field.le_prev; \ 405 *(elm)->field.le_prev = LIST_NEXT((elm), field); \ 406 TRASHIT((elm)->field.le_next); \ 407 TRASHIT((elm)->field.le_prev); \ 408} while (0) 409 410/* 411 * Tail queue declarations. 412 */ 413#define TAILQ_HEAD(name, type) \ 414struct name { \ 415 struct type *tqh_first; /* first element */ \ 416 struct type **tqh_last; /* addr of last next element */ \ 417 TRACEBUF \ 418} 419 420#define TAILQ_HEAD_INITIALIZER(head) \ 421 { NULL, &(head).tqh_first } 422 423#define TAILQ_ENTRY(type) \ 424struct { \ 425 struct type *tqe_next; /* next element */ \ 426 struct type **tqe_prev; /* address of previous next element */ \ 427 TRACEBUF \ 428} 429 430/* 431 * Tail queue functions. 432 */ 433#define TAILQ_CONCAT(head1, head2, field) do { \ 434 if (!TAILQ_EMPTY(head2)) { \ 435 *(head1)->tqh_last = (head2)->tqh_first; \ 436 (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ 437 (head1)->tqh_last = (head2)->tqh_last; \ 438 TAILQ_INIT((head2)); \ 439 QMD_TRACE_HEAD(head1); \ 440 QMD_TRACE_HEAD(head2); \ 441 } \ 442} while (0) 443 444#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) 445 446#define TAILQ_FIRST(head) ((head)->tqh_first) 447 448#define TAILQ_FOREACH(var, head, field) \ 449 for ((var) = TAILQ_FIRST((head)); \ 450 (var); \ 451 (var) = TAILQ_NEXT((var), field)) 452 453#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ 454 for ((var) = TAILQ_FIRST((head)); \ 455 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ 456 (var) = (tvar)) 457 458#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ 459 for ((var) = TAILQ_LAST((head), headname); \ 460 (var); \ 461 (var) = TAILQ_PREV((var), headname, field)) 462 463#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ 464 for ((var) = TAILQ_LAST((head), headname); \ 465 (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ 466 (var) = (tvar)) 467 468#define TAILQ_INIT(head) do { \ 469 TAILQ_FIRST((head)) = NULL; \ 470 (head)->tqh_last = &TAILQ_FIRST((head)); \ 471 QMD_TRACE_HEAD(head); \ 472} while (0) 473 474#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ 475 if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\ 476 TAILQ_NEXT((elm), field)->field.tqe_prev = \ 477 &TAILQ_NEXT((elm), field); \ 478 else { \ 479 (head)->tqh_last = &TAILQ_NEXT((elm), field); \ 480 QMD_TRACE_HEAD(head); \ 481 } \ 482 TAILQ_NEXT((listelm), field) = (elm); \ 483 (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \ 484 QMD_TRACE_ELEM(&(elm)->field); \ 485 QMD_TRACE_ELEM(&listelm->field); \ 486} while (0) 487 488#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ 489 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ 490 TAILQ_NEXT((elm), field) = (listelm); \ 491 *(listelm)->field.tqe_prev = (elm); \ 492 (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \ 493 QMD_TRACE_ELEM(&(elm)->field); \ 494 QMD_TRACE_ELEM(&listelm->field); \ 495} while (0) 496 497#define TAILQ_INSERT_HEAD(head, elm, field) do { \ 498 if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \ 499 TAILQ_FIRST((head))->field.tqe_prev = \ 500 &TAILQ_NEXT((elm), field); \ 501 else \ 502 (head)->tqh_last = &TAILQ_NEXT((elm), field); \ 503 TAILQ_FIRST((head)) = (elm); \ 504 (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \ 505 QMD_TRACE_HEAD(head); \ 506 QMD_TRACE_ELEM(&(elm)->field); \ 507} while (0) 508 509#define TAILQ_INSERT_TAIL(head, elm, field) do { \ 510 TAILQ_NEXT((elm), field) = NULL; \ 511 (elm)->field.tqe_prev = (head)->tqh_last; \ 512 *(head)->tqh_last = (elm); \ 513 (head)->tqh_last = &TAILQ_NEXT((elm), field); \ 514 QMD_TRACE_HEAD(head); \ 515 QMD_TRACE_ELEM(&(elm)->field); \ 516} while (0) 517 518#define TAILQ_LAST(head, headname) \ 519 (*(((struct headname *)((head)->tqh_last))->tqh_last)) 520 521#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) 522 523#define TAILQ_PREV(elm, headname, field) \ 524 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) 525 526#define TAILQ_REMOVE(head, elm, field) do { \ 527 if ((TAILQ_NEXT((elm), field)) != NULL) \ 528 TAILQ_NEXT((elm), field)->field.tqe_prev = \ 529 (elm)->field.tqe_prev; \ 530 else { \ 531 (head)->tqh_last = (elm)->field.tqe_prev; \ 532 QMD_TRACE_HEAD(head); \ 533 } \ 534 *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ 535 TRASHIT((elm)->field.tqe_next); \ 536 TRASHIT((elm)->field.tqe_prev); \ 537 QMD_TRACE_ELEM(&(elm)->field); \ 538} while (0) 539 540 541#ifdef _KERNEL 542 543/* 544 * XXX insque() and remque() are an old way of handling certain queues. 545 * They bogusly assumes that all queue heads look alike. 546 */ 547 548struct quehead { 549 struct quehead *qh_link; 550 struct quehead *qh_rlink; 551}; 552 553#ifdef __CC_SUPPORTS___INLINE 554 555static __inline void 556insque(void *a, void *b) 557{ 558 struct quehead *element = (struct quehead *)a, 559 *head = (struct quehead *)b; 560 561 element->qh_link = head->qh_link; 562 element->qh_rlink = head; 563 head->qh_link = element; 564 element->qh_link->qh_rlink = element; 565} 566 567static __inline void 568remque(void *a) 569{ 570 struct quehead *element = (struct quehead *)a; 571 572 element->qh_link->qh_rlink = element->qh_rlink; 573 element->qh_rlink->qh_link = element->qh_link; 574 element->qh_rlink = 0; 575} 576 577#else /* !__CC_SUPPORTS___INLINE */ 578 579void insque(void *a, void *b); 580void remque(void *a); 581 582#endif /* __CC_SUPPORTS___INLINE */ 583 584#endif /* _KERNEL */ 585 586#endif /* !_SYS_QUEUE_H_ */ 587