williamr@2: /*- williamr@2: * Copyright (c) 1991, 1993 williamr@2: * The Regents of the University of California. All rights reserved. williamr@2: * williamr@2: * Redistribution and use in source and binary forms, with or without williamr@2: * modification, are permitted provided that the following conditions williamr@2: * are met: williamr@2: * 1. Redistributions of source code must retain the above copyright williamr@2: * notice, this list of conditions and the following disclaimer. williamr@2: * 2. Redistributions in binary form must reproduce the above copyright williamr@2: * notice, this list of conditions and the following disclaimer in the williamr@2: * documentation and/or other materials provided with the distribution. williamr@2: * 4. Neither the name of the University nor the names of its contributors williamr@2: * may be used to endorse or promote products derived from this software williamr@2: * without specific prior written permission. williamr@2: * williamr@2: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND williamr@2: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE williamr@2: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE williamr@2: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE williamr@2: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL williamr@2: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS williamr@2: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) williamr@2: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT williamr@2: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY williamr@2: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF williamr@2: * SUCH DAMAGE. williamr@2: * © Portions copyright (c) 2007 Symbian Software Ltd. All rights reserved. williamr@2: * @(#)queue.h 8.5 (Berkeley) 8/20/94 williamr@2: * $FreeBSD: src/sys/sys/queue.h,v 1.60.2.1 2005/08/16 22:41:39 phk Exp $ williamr@2: */ williamr@2: williamr@2: #ifndef _SYS_QUEUE_H_ williamr@2: #define _SYS_QUEUE_H_ williamr@2: williamr@2: #include williamr@2: williamr@2: /* williamr@2: * This file defines four types of data structures: singly-linked lists, williamr@2: * singly-linked tail queues, lists and tail queues. williamr@2: * williamr@2: * A singly-linked list is headed by a single forward pointer. The elements williamr@2: * are singly linked for minimum space and pointer manipulation overhead at williamr@2: * the expense of O(n) removal for arbitrary elements. New elements can be williamr@2: * added to the list after an existing element or at the head of the list. williamr@2: * Elements being removed from the head of the list should use the explicit williamr@2: * macro for this purpose for optimum efficiency. A singly-linked list may williamr@2: * only be traversed in the forward direction. Singly-linked lists are ideal williamr@2: * for applications with large datasets and few or no removals or for williamr@2: * implementing a LIFO queue. williamr@2: * williamr@2: * A singly-linked tail queue is headed by a pair of pointers, one to the williamr@2: * head of the list and the other to the tail of the list. The elements are williamr@2: * singly linked for minimum space and pointer manipulation overhead at the williamr@2: * expense of O(n) removal for arbitrary elements. New elements can be added williamr@2: * to the list after an existing element, at the head of the list, or at the williamr@2: * end of the list. Elements being removed from the head of the tail queue williamr@2: * should use the explicit macro for this purpose for optimum efficiency. williamr@2: * A singly-linked tail queue may only be traversed in the forward direction. williamr@2: * Singly-linked tail queues are ideal for applications with large datasets williamr@2: * and few or no removals or for implementing a FIFO queue. williamr@2: * williamr@2: * A list is headed by a single forward pointer (or an array of forward williamr@2: * pointers for a hash table header). The elements are doubly linked williamr@2: * so that an arbitrary element can be removed without a need to williamr@2: * traverse the list. New elements can be added to the list before williamr@2: * or after an existing element or at the head of the list. A list williamr@2: * may only be traversed in the forward direction. williamr@2: * williamr@2: * A tail queue is headed by a pair of pointers, one to the head of the williamr@2: * list and the other to the tail of the list. The elements are doubly williamr@2: * linked so that an arbitrary element can be removed without a need to williamr@2: * traverse the list. New elements can be added to the list before or williamr@2: * after an existing element, at the head of the list, or at the end of williamr@2: * the list. A tail queue may be traversed in either direction. williamr@2: * williamr@2: * For details on the use of these macros, see the queue(3) manual page. williamr@2: * williamr@2: * williamr@2: * SLIST LIST STAILQ TAILQ williamr@2: * _HEAD + + + + williamr@2: * _HEAD_INITIALIZER + + + + williamr@2: * _ENTRY + + + + williamr@2: * _INIT + + + + williamr@2: * _EMPTY + + + + williamr@2: * _FIRST + + + + williamr@2: * _NEXT + + + + williamr@2: * _PREV - - - + williamr@2: * _LAST - - + + williamr@2: * _FOREACH + + + + williamr@2: * _FOREACH_SAFE + + + + williamr@2: * _FOREACH_REVERSE - - - + williamr@2: * _FOREACH_REVERSE_SAFE - - - + williamr@2: * _INSERT_HEAD + + + + williamr@2: * _INSERT_BEFORE - + - + williamr@2: * _INSERT_AFTER + + + + williamr@2: * _INSERT_TAIL - - + + williamr@2: * _CONCAT - - + + williamr@2: * _REMOVE_HEAD + - + - williamr@2: * _REMOVE + + + + williamr@2: * williamr@2: */ williamr@2: #define QUEUE_MACRO_DEBUG 0 williamr@2: #if QUEUE_MACRO_DEBUG williamr@2: /* Store the last 2 places the queue element or head was altered */ williamr@2: struct qm_trace { williamr@2: char * lastfile; williamr@2: int lastline; williamr@2: char * prevfile; williamr@2: int prevline; williamr@2: }; williamr@2: williamr@2: #define TRACEBUF struct qm_trace trace; williamr@2: #define TRASHIT(x) do {(x) = (void *)-1;} while (0) williamr@2: williamr@2: #define QMD_TRACE_HEAD(head) do { \ williamr@2: (head)->trace.prevline = (head)->trace.lastline; \ williamr@2: (head)->trace.prevfile = (head)->trace.lastfile; \ williamr@2: (head)->trace.lastline = __LINE__; \ williamr@2: (head)->trace.lastfile = __FILE__; \ williamr@2: } while (0) williamr@2: williamr@2: #define QMD_TRACE_ELEM(elem) do { \ williamr@2: (elem)->trace.prevline = (elem)->trace.lastline; \ williamr@2: (elem)->trace.prevfile = (elem)->trace.lastfile; \ williamr@2: (elem)->trace.lastline = __LINE__; \ williamr@2: (elem)->trace.lastfile = __FILE__; \ williamr@2: } while (0) williamr@2: williamr@2: #else williamr@2: #define QMD_TRACE_ELEM(elem) williamr@2: #define QMD_TRACE_HEAD(head) williamr@2: #define TRACEBUF williamr@2: #define TRASHIT(x) williamr@2: #endif /* QUEUE_MACRO_DEBUG */ williamr@2: williamr@2: /* williamr@2: * Singly-linked List declarations. williamr@2: */ williamr@2: #define SLIST_HEAD(name, type) \ williamr@2: struct name { \ williamr@2: struct type *slh_first; /* first element */ \ williamr@2: } williamr@2: williamr@2: #define SLIST_HEAD_INITIALIZER(head) \ williamr@2: { NULL } williamr@2: williamr@2: #define SLIST_ENTRY(type) \ williamr@2: struct { \ williamr@2: struct type *sle_next; /* next element */ \ williamr@2: } williamr@2: williamr@2: /* williamr@2: * Singly-linked List functions. williamr@2: */ williamr@2: #define SLIST_EMPTY(head) ((head)->slh_first == NULL) williamr@2: williamr@2: #define SLIST_FIRST(head) ((head)->slh_first) williamr@2: williamr@2: #define SLIST_FOREACH(var, head, field) \ williamr@2: for ((var) = SLIST_FIRST((head)); \ williamr@2: (var); \ williamr@2: (var) = SLIST_NEXT((var), field)) williamr@2: williamr@2: #define SLIST_FOREACH_SAFE(var, head, field, tvar) \ williamr@2: for ((var) = SLIST_FIRST((head)); \ williamr@2: (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ williamr@2: (var) = (tvar)) williamr@2: williamr@2: #define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ williamr@2: for ((varp) = &SLIST_FIRST((head)); \ williamr@2: ((var) = *(varp)) != NULL; \ williamr@2: (varp) = &SLIST_NEXT((var), field)) williamr@2: williamr@2: #define SLIST_INIT(head) do { \ williamr@2: SLIST_FIRST((head)) = NULL; \ williamr@2: } while (0) williamr@2: williamr@2: #define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ williamr@2: SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \ williamr@2: SLIST_NEXT((slistelm), field) = (elm); \ williamr@2: } while (0) williamr@2: williamr@2: #define SLIST_INSERT_HEAD(head, elm, field) do { \ williamr@2: SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \ williamr@2: SLIST_FIRST((head)) = (elm); \ williamr@2: } while (0) williamr@2: williamr@2: #define SLIST_NEXT(elm, field) ((elm)->field.sle_next) williamr@2: williamr@2: #define SLIST_REMOVE(head, elm, type, field) do { \ williamr@2: if (SLIST_FIRST((head)) == (elm)) { \ williamr@2: SLIST_REMOVE_HEAD((head), field); \ williamr@2: } \ williamr@2: else { \ williamr@2: struct type *curelm = SLIST_FIRST((head)); \ williamr@2: while (SLIST_NEXT(curelm, field) != (elm)) \ williamr@2: curelm = SLIST_NEXT(curelm, field); \ williamr@2: SLIST_NEXT(curelm, field) = \ williamr@2: SLIST_NEXT(SLIST_NEXT(curelm, field), field); \ williamr@2: } \ williamr@2: } while (0) williamr@2: williamr@2: #define SLIST_REMOVE_HEAD(head, field) do { \ williamr@2: SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \ williamr@2: } while (0) williamr@2: williamr@2: /* williamr@2: * Singly-linked Tail queue declarations. williamr@2: */ williamr@2: #define STAILQ_HEAD(name, type) \ williamr@2: struct name { \ williamr@2: struct type *stqh_first;/* first element */ \ williamr@2: struct type **stqh_last;/* addr of last next element */ \ williamr@2: } williamr@2: williamr@2: #define STAILQ_HEAD_INITIALIZER(head) \ williamr@2: { NULL, &(head).stqh_first } williamr@2: williamr@2: #define STAILQ_ENTRY(type) \ williamr@2: struct { \ williamr@2: struct type *stqe_next; /* next element */ \ williamr@2: } williamr@2: williamr@2: /* williamr@2: * Singly-linked Tail queue functions. williamr@2: */ williamr@2: #define STAILQ_CONCAT(head1, head2) do { \ williamr@2: if (!STAILQ_EMPTY((head2))) { \ williamr@2: *(head1)->stqh_last = (head2)->stqh_first; \ williamr@2: (head1)->stqh_last = (head2)->stqh_last; \ williamr@2: STAILQ_INIT((head2)); \ williamr@2: } \ williamr@2: } while (0) williamr@2: williamr@2: #define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) williamr@2: williamr@2: #define STAILQ_FIRST(head) ((head)->stqh_first) williamr@2: williamr@2: #define STAILQ_FOREACH(var, head, field) \ williamr@2: for((var) = STAILQ_FIRST((head)); \ williamr@2: (var); \ williamr@2: (var) = STAILQ_NEXT((var), field)) williamr@2: williamr@2: williamr@2: #define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ williamr@2: for ((var) = STAILQ_FIRST((head)); \ williamr@2: (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ williamr@2: (var) = (tvar)) williamr@2: williamr@2: #define STAILQ_INIT(head) do { \ williamr@2: STAILQ_FIRST((head)) = NULL; \ williamr@2: (head)->stqh_last = &STAILQ_FIRST((head)); \ williamr@2: } while (0) williamr@2: williamr@2: #define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ williamr@2: if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\ williamr@2: (head)->stqh_last = &STAILQ_NEXT((elm), field); \ williamr@2: STAILQ_NEXT((tqelm), field) = (elm); \ williamr@2: } while (0) williamr@2: williamr@2: #define STAILQ_INSERT_HEAD(head, elm, field) do { \ williamr@2: if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ williamr@2: (head)->stqh_last = &STAILQ_NEXT((elm), field); \ williamr@2: STAILQ_FIRST((head)) = (elm); \ williamr@2: } while (0) williamr@2: williamr@2: #define STAILQ_INSERT_TAIL(head, elm, field) do { \ williamr@2: STAILQ_NEXT((elm), field) = NULL; \ williamr@2: *(head)->stqh_last = (elm); \ williamr@2: (head)->stqh_last = &STAILQ_NEXT((elm), field); \ williamr@2: } while (0) williamr@2: williamr@2: #define STAILQ_LAST(head, type, field) \ williamr@2: (STAILQ_EMPTY((head)) ? \ williamr@2: NULL : \ williamr@2: ((struct type *) \ williamr@2: ((char *)((head)->stqh_last) - __offsetof(struct type, field)))) williamr@2: williamr@2: #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) williamr@2: williamr@2: #define STAILQ_REMOVE(head, elm, type, field) do { \ williamr@2: if (STAILQ_FIRST((head)) == (elm)) { \ williamr@2: STAILQ_REMOVE_HEAD((head), field); \ williamr@2: } \ williamr@2: else { \ williamr@2: struct type *curelm = STAILQ_FIRST((head)); \ williamr@2: while (STAILQ_NEXT(curelm, field) != (elm)) \ williamr@2: curelm = STAILQ_NEXT(curelm, field); \ williamr@2: if ((STAILQ_NEXT(curelm, field) = \ williamr@2: STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\ williamr@2: (head)->stqh_last = &STAILQ_NEXT((curelm), field);\ williamr@2: } \ williamr@2: } while (0) williamr@2: williamr@2: #define STAILQ_REMOVE_HEAD(head, field) do { \ williamr@2: if ((STAILQ_FIRST((head)) = \ williamr@2: STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ williamr@2: (head)->stqh_last = &STAILQ_FIRST((head)); \ williamr@2: } while (0) williamr@2: williamr@2: #define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \ williamr@2: if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \ williamr@2: (head)->stqh_last = &STAILQ_FIRST((head)); \ williamr@2: } while (0) williamr@2: williamr@2: /* williamr@2: * List declarations. williamr@2: */ williamr@2: #define LIST_HEAD(name, type) \ williamr@2: struct name { \ williamr@2: struct type *lh_first; /* first element */ \ williamr@2: } williamr@2: williamr@2: #define LIST_HEAD_INITIALIZER(head) \ williamr@2: { NULL } williamr@2: williamr@2: #define LIST_ENTRY(type) \ williamr@2: struct { \ williamr@2: struct type *le_next; /* next element */ \ williamr@2: struct type **le_prev; /* address of previous next element */ \ williamr@2: } williamr@2: williamr@2: /* williamr@2: * List functions. williamr@2: */ williamr@2: williamr@2: #define LIST_EMPTY(head) ((head)->lh_first == NULL) williamr@2: williamr@2: #define LIST_FIRST(head) ((head)->lh_first) williamr@2: williamr@2: #define LIST_FOREACH(var, head, field) \ williamr@2: for ((var) = LIST_FIRST((head)); \ williamr@2: (var); \ williamr@2: (var) = LIST_NEXT((var), field)) williamr@2: williamr@2: #define LIST_FOREACH_SAFE(var, head, field, tvar) \ williamr@2: for ((var) = LIST_FIRST((head)); \ williamr@2: (var) && ((tvar) = LIST_NEXT((var), field), 1); \ williamr@2: (var) = (tvar)) williamr@2: williamr@2: #define LIST_INIT(head) do { \ williamr@2: LIST_FIRST((head)) = NULL; \ williamr@2: } while (0) williamr@2: williamr@2: #define LIST_INSERT_AFTER(listelm, elm, field) do { \ williamr@2: if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\ williamr@2: LIST_NEXT((listelm), field)->field.le_prev = \ williamr@2: &LIST_NEXT((elm), field); \ williamr@2: LIST_NEXT((listelm), field) = (elm); \ williamr@2: (elm)->field.le_prev = &LIST_NEXT((listelm), field); \ williamr@2: } while (0) williamr@2: williamr@2: #define LIST_INSERT_BEFORE(listelm, elm, field) do { \ williamr@2: (elm)->field.le_prev = (listelm)->field.le_prev; \ williamr@2: LIST_NEXT((elm), field) = (listelm); \ williamr@2: *(listelm)->field.le_prev = (elm); \ williamr@2: (listelm)->field.le_prev = &LIST_NEXT((elm), field); \ williamr@2: } while (0) williamr@2: williamr@2: #define LIST_INSERT_HEAD(head, elm, field) do { \ williamr@2: if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \ williamr@2: LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\ williamr@2: LIST_FIRST((head)) = (elm); \ williamr@2: (elm)->field.le_prev = &LIST_FIRST((head)); \ williamr@2: } while (0) williamr@2: williamr@2: #define LIST_NEXT(elm, field) ((elm)->field.le_next) williamr@2: williamr@2: #define LIST_REMOVE(elm, field) do { \ williamr@2: if (LIST_NEXT((elm), field) != NULL) \ williamr@2: LIST_NEXT((elm), field)->field.le_prev = \ williamr@2: (elm)->field.le_prev; \ williamr@2: *(elm)->field.le_prev = LIST_NEXT((elm), field); \ williamr@2: } while (0) williamr@2: williamr@2: /* williamr@2: * Tail queue declarations. williamr@2: */ williamr@2: #define TAILQ_HEAD(name, type) \ williamr@2: struct name { \ williamr@2: struct type *tqh_first; /* first element */ \ williamr@2: struct type **tqh_last; /* addr of last next element */ \ williamr@2: TRACEBUF \ williamr@2: } williamr@2: williamr@2: #define TAILQ_HEAD_INITIALIZER(head) \ williamr@2: { NULL, &(head).tqh_first } williamr@2: williamr@2: #define TAILQ_ENTRY(type) \ williamr@2: struct { \ williamr@2: struct type *tqe_next; /* next element */ \ williamr@2: struct type **tqe_prev; /* address of previous next element */ \ williamr@2: TRACEBUF \ williamr@2: } williamr@2: williamr@2: /* williamr@2: * Tail queue functions. williamr@2: */ williamr@2: #define TAILQ_CONCAT(head1, head2, field) do { \ williamr@2: if (!TAILQ_EMPTY(head2)) { \ williamr@2: *(head1)->tqh_last = (head2)->tqh_first; \ williamr@2: (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ williamr@2: (head1)->tqh_last = (head2)->tqh_last; \ williamr@2: TAILQ_INIT((head2)); \ williamr@2: QMD_TRACE_HEAD(head1); \ williamr@2: QMD_TRACE_HEAD(head2); \ williamr@2: } \ williamr@2: } while (0) williamr@2: williamr@2: #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) williamr@2: williamr@2: #define TAILQ_FIRST(head) ((head)->tqh_first) williamr@2: williamr@2: #define TAILQ_FOREACH(var, head, field) \ williamr@2: for ((var) = TAILQ_FIRST((head)); \ williamr@2: (var); \ williamr@2: (var) = TAILQ_NEXT((var), field)) williamr@2: williamr@2: #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ williamr@2: for ((var) = TAILQ_FIRST((head)); \ williamr@2: (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ williamr@2: (var) = (tvar)) williamr@2: williamr@2: #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ williamr@2: for ((var) = TAILQ_LAST((head), headname); \ williamr@2: (var); \ williamr@2: (var) = TAILQ_PREV((var), headname, field)) williamr@2: williamr@2: #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ williamr@2: for ((var) = TAILQ_LAST((head), headname); \ williamr@2: (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ williamr@2: (var) = (tvar)) williamr@2: williamr@2: #define TAILQ_INIT(head) do { \ williamr@2: TAILQ_FIRST((head)) = NULL; \ williamr@2: (head)->tqh_last = &TAILQ_FIRST((head)); \ williamr@2: QMD_TRACE_HEAD(head); \ williamr@2: } while (0) williamr@2: williamr@2: #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ williamr@2: if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\ williamr@2: TAILQ_NEXT((elm), field)->field.tqe_prev = \ williamr@2: &TAILQ_NEXT((elm), field); \ williamr@2: else { \ williamr@2: (head)->tqh_last = &TAILQ_NEXT((elm), field); \ williamr@2: QMD_TRACE_HEAD(head); \ williamr@2: } \ williamr@2: TAILQ_NEXT((listelm), field) = (elm); \ williamr@2: (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \ williamr@2: QMD_TRACE_ELEM(&(elm)->field); \ williamr@2: QMD_TRACE_ELEM(&listelm->field); \ williamr@2: } while (0) williamr@2: williamr@2: #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ williamr@2: (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ williamr@2: TAILQ_NEXT((elm), field) = (listelm); \ williamr@2: *(listelm)->field.tqe_prev = (elm); \ williamr@2: (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \ williamr@2: QMD_TRACE_ELEM(&(elm)->field); \ williamr@2: QMD_TRACE_ELEM(&listelm->field); \ williamr@2: } while (0) williamr@2: williamr@2: #define TAILQ_INSERT_HEAD(head, elm, field) do { \ williamr@2: if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \ williamr@2: TAILQ_FIRST((head))->field.tqe_prev = \ williamr@2: &TAILQ_NEXT((elm), field); \ williamr@2: else \ williamr@2: (head)->tqh_last = &TAILQ_NEXT((elm), field); \ williamr@2: TAILQ_FIRST((head)) = (elm); \ williamr@2: (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \ williamr@2: QMD_TRACE_HEAD(head); \ williamr@2: QMD_TRACE_ELEM(&(elm)->field); \ williamr@2: } while (0) williamr@2: williamr@2: #define TAILQ_INSERT_TAIL(head, elm, field) do { \ williamr@2: TAILQ_NEXT((elm), field) = NULL; \ williamr@2: (elm)->field.tqe_prev = (head)->tqh_last; \ williamr@2: *(head)->tqh_last = (elm); \ williamr@2: (head)->tqh_last = &TAILQ_NEXT((elm), field); \ williamr@2: QMD_TRACE_HEAD(head); \ williamr@2: QMD_TRACE_ELEM(&(elm)->field); \ williamr@2: } while (0) williamr@2: williamr@2: #define TAILQ_LAST(head, headname) \ williamr@2: (*(((struct headname *)((head)->tqh_last))->tqh_last)) williamr@2: williamr@2: #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) williamr@2: williamr@2: #define TAILQ_PREV(elm, headname, field) \ williamr@2: (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) williamr@2: williamr@2: #define TAILQ_REMOVE(head, elm, field) do { \ williamr@2: if ((TAILQ_NEXT((elm), field)) != NULL) \ williamr@2: TAILQ_NEXT((elm), field)->field.tqe_prev = \ williamr@2: (elm)->field.tqe_prev; \ williamr@2: else { \ williamr@2: (head)->tqh_last = (elm)->field.tqe_prev; \ williamr@2: QMD_TRACE_HEAD(head); \ williamr@2: } \ williamr@2: *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ williamr@2: TRASHIT((elm)->field.tqe_next); \ williamr@2: TRASHIT((elm)->field.tqe_prev); \ williamr@2: QMD_TRACE_ELEM(&(elm)->field); \ williamr@2: } while (0) williamr@2: williamr@2: williamr@2: #ifdef _KERNEL williamr@2: williamr@2: /* williamr@2: * XXX insque() and remque() are an old way of handling certain queues. williamr@2: * They bogusly assumes that all queue heads look alike. williamr@2: */ williamr@2: williamr@2: struct quehead { williamr@2: struct quehead *qh_link; williamr@2: struct quehead *qh_rlink; williamr@2: }; williamr@2: williamr@2: #ifdef __CC_SUPPORTS___INLINE williamr@2: williamr@2: static __inline void williamr@2: insque(void *a, void *b) williamr@2: { williamr@2: struct quehead *element = (struct quehead *)a, williamr@2: *head = (struct quehead *)b; williamr@2: williamr@2: element->qh_link = head->qh_link; williamr@2: element->qh_rlink = head; williamr@2: head->qh_link = element; williamr@2: element->qh_link->qh_rlink = element; williamr@2: } williamr@2: williamr@2: static __inline void williamr@2: remque(void *a) williamr@2: { williamr@2: struct quehead *element = (struct quehead *)a; williamr@2: williamr@2: element->qh_link->qh_rlink = element->qh_rlink; williamr@2: element->qh_rlink->qh_link = element->qh_link; williamr@2: element->qh_rlink = 0; williamr@2: } williamr@2: williamr@2: #endif /* __CC_SUPPORTS___INLINE */ williamr@2: williamr@2: #endif /* _KERNEL */ williamr@2: williamr@2: #endif /* !_SYS_QUEUE_H_ */