The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/queue.h

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1991, 1993
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 4. Neither the name of the University nor the names of its contributors
   14  *    may be used to endorse or promote products derived from this software
   15  *    without specific prior written permission.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  *
   29  *      @(#)queue.h     8.5 (Berkeley) 8/20/94
   30  * $FreeBSD: releng/7.3/sys/sys/queue.h 200647 2009-12-17 19:56:09Z jhb $
   31  */
   32 
   33 #ifndef _SYS_QUEUE_H_
   34 #define _SYS_QUEUE_H_
   35 
   36 #include <sys/cdefs.h>
   37 
   38 /*
   39  * This file defines four types of data structures: singly-linked lists,
   40  * singly-linked tail queues, lists and tail queues.
   41  *
   42  * A singly-linked list is headed by a single forward pointer. The elements
   43  * are singly linked for minimum space and pointer manipulation overhead at
   44  * the expense of O(n) removal for arbitrary elements. New elements can be
   45  * added to the list after an existing element or at the head of the list.
   46  * Elements being removed from the head of the list should use the explicit
   47  * macro for this purpose for optimum efficiency. A singly-linked list may
   48  * only be traversed in the forward direction.  Singly-linked lists are ideal
   49  * for applications with large datasets and few or no removals or for
   50  * implementing a LIFO queue.
   51  *
   52  * A singly-linked tail queue is headed by a pair of pointers, one to the
   53  * head of the list and the other to the tail of the list. The elements are
   54  * singly linked for minimum space and pointer manipulation overhead at the
   55  * expense of O(n) removal for arbitrary elements. New elements can be added
   56  * to the list after an existing element, at the head of the list, or at the
   57  * end of the list. Elements being removed from the head of the tail queue
   58  * should use the explicit macro for this purpose for optimum efficiency.
   59  * A singly-linked tail queue may only be traversed in the forward direction.
   60  * Singly-linked tail queues are ideal for applications with large datasets
   61  * and few or no removals or for implementing a FIFO queue.
   62  *
   63  * A list is headed by a single forward pointer (or an array of forward
   64  * pointers for a hash table header). The elements are doubly linked
   65  * so that an arbitrary element can be removed without a need to
   66  * traverse the list. New elements can be added to the list before
   67  * or after an existing element or at the head of the list. A list
   68  * may only be traversed in the forward direction.
   69  *
   70  * A tail queue is headed by a pair of pointers, one to the head of the
   71  * list and the other to the tail of the list. The elements are doubly
   72  * linked so that an arbitrary element can be removed without a need to
   73  * traverse the list. New elements can be added to the list before or
   74  * after an existing element, at the head of the list, or at the end of
   75  * the list. A tail queue may be traversed in either direction.
   76  *
   77  * For details on the use of these macros, see the queue(3) manual page.
   78  *
   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_AFTER                +       -       +       -
  100  * _REMOVE_HEAD                 +       -       +       -
  101  * _REMOVE                      +       +       +       +
  102  *
  103  */
  104 #ifdef QUEUE_MACRO_DEBUG
  105 /* Store the last 2 places the queue element or head was altered */
  106 struct qm_trace {
  107         char * lastfile;
  108         int lastline;
  109         char * prevfile;
  110         int prevline;
  111 };
  112 
  113 #define TRACEBUF        struct qm_trace trace;
  114 #define TRASHIT(x)      do {(x) = (void *)-1;} while (0)
  115 
  116 #define QMD_TRACE_HEAD(head) do {                                       \
  117         (head)->trace.prevline = (head)->trace.lastline;                \
  118         (head)->trace.prevfile = (head)->trace.lastfile;                \
  119         (head)->trace.lastline = __LINE__;                              \
  120         (head)->trace.lastfile = __FILE__;                              \
  121 } while (0)
  122 
  123 #define QMD_TRACE_ELEM(elem) do {                                       \
  124         (elem)->trace.prevline = (elem)->trace.lastline;                \
  125         (elem)->trace.prevfile = (elem)->trace.lastfile;                \
  126         (elem)->trace.lastline = __LINE__;                              \
  127         (elem)->trace.lastfile = __FILE__;                              \
  128 } while (0)
  129 
  130 #else
  131 #define QMD_TRACE_ELEM(elem)
  132 #define QMD_TRACE_HEAD(head)
  133 #define TRACEBUF
  134 #define TRASHIT(x)
  135 #endif  /* QUEUE_MACRO_DEBUG */
  136 
  137 /*
  138  * Singly-linked List declarations.
  139  */
  140 #define SLIST_HEAD(name, type)                                          \
  141 struct name {                                                           \
  142         struct type *slh_first; /* first element */                     \
  143 }
  144 
  145 #define SLIST_HEAD_INITIALIZER(head)                                    \
  146         { NULL }
  147 
  148 #define SLIST_ENTRY(type)                                               \
  149 struct {                                                                \
  150         struct type *sle_next;  /* next element */                      \
  151 }
  152 
  153 /*
  154  * Singly-linked List functions.
  155  */
  156 #define SLIST_EMPTY(head)       ((head)->slh_first == NULL)
  157 
  158 #define SLIST_FIRST(head)       ((head)->slh_first)
  159 
  160 #define SLIST_FOREACH(var, head, field)                                 \
  161         for ((var) = SLIST_FIRST((head));                               \
  162             (var);                                                      \
  163             (var) = SLIST_NEXT((var), field))
  164 
  165 #define SLIST_FOREACH_SAFE(var, head, field, tvar)                      \
  166         for ((var) = SLIST_FIRST((head));                               \
  167             (var) && ((tvar) = SLIST_NEXT((var), field), 1);            \
  168             (var) = (tvar))
  169 
  170 #define SLIST_FOREACH_PREVPTR(var, varp, head, field)                   \
  171         for ((varp) = &SLIST_FIRST((head));                             \
  172             ((var) = *(varp)) != NULL;                                  \
  173             (varp) = &SLIST_NEXT((var), field))
  174 
  175 #define SLIST_INIT(head) do {                                           \
  176         SLIST_FIRST((head)) = NULL;                                     \
  177 } while (0)
  178 
  179 #define SLIST_INSERT_AFTER(slistelm, elm, field) do {                   \
  180         SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field);       \
  181         SLIST_NEXT((slistelm), field) = (elm);                          \
  182 } while (0)
  183 
  184 #define SLIST_INSERT_HEAD(head, elm, field) do {                        \
  185         SLIST_NEXT((elm), field) = SLIST_FIRST((head));                 \
  186         SLIST_FIRST((head)) = (elm);                                    \
  187 } while (0)
  188 
  189 #define SLIST_NEXT(elm, field)  ((elm)->field.sle_next)
  190 
  191 #define SLIST_REMOVE(head, elm, type, field) do {                       \
  192         if (SLIST_FIRST((head)) == (elm)) {                             \
  193                 SLIST_REMOVE_HEAD((head), field);                       \
  194         }                                                               \
  195         else {                                                          \
  196                 struct type *curelm = SLIST_FIRST((head));              \
  197                 while (SLIST_NEXT(curelm, field) != (elm))              \
  198                         curelm = SLIST_NEXT(curelm, field);             \
  199                 SLIST_REMOVE_AFTER(curelm, field);                      \
  200         }                                                               \
  201         TRASHIT((elm)->field.sle_next);                                 \
  202 } while (0)
  203 
  204 #define SLIST_REMOVE_AFTER(elm, field) do {                             \
  205         SLIST_NEXT(elm, field) =                                        \
  206             SLIST_NEXT(SLIST_NEXT(elm, field), field);                  \
  207 } while (0)
  208 
  209 #define SLIST_REMOVE_HEAD(head, field) do {                             \
  210         SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field);   \
  211 } while (0)
  212 
  213 /*
  214  * Singly-linked Tail queue declarations.
  215  */
  216 #define STAILQ_HEAD(name, type)                                         \
  217 struct name {                                                           \
  218         struct type *stqh_first;/* first element */                     \
  219         struct type **stqh_last;/* addr of last next element */         \
  220 }
  221 
  222 #define STAILQ_HEAD_INITIALIZER(head)                                   \
  223         { NULL, &(head).stqh_first }
  224 
  225 #define STAILQ_ENTRY(type)                                              \
  226 struct {                                                                \
  227         struct type *stqe_next; /* next element */                      \
  228 }
  229 
  230 /*
  231  * Singly-linked Tail queue functions.
  232  */
  233 #define STAILQ_CONCAT(head1, head2) do {                                \
  234         if (!STAILQ_EMPTY((head2))) {                                   \
  235                 *(head1)->stqh_last = (head2)->stqh_first;              \
  236                 (head1)->stqh_last = (head2)->stqh_last;                \
  237                 STAILQ_INIT((head2));                                   \
  238         }                                                               \
  239 } while (0)
  240 
  241 #define STAILQ_EMPTY(head)      ((head)->stqh_first == NULL)
  242 
  243 #define STAILQ_FIRST(head)      ((head)->stqh_first)
  244 
  245 #define STAILQ_FOREACH(var, head, field)                                \
  246         for((var) = STAILQ_FIRST((head));                               \
  247            (var);                                                       \
  248            (var) = STAILQ_NEXT((var), field))
  249 
  250 
  251 #define STAILQ_FOREACH_SAFE(var, head, field, tvar)                     \
  252         for ((var) = STAILQ_FIRST((head));                              \
  253             (var) && ((tvar) = STAILQ_NEXT((var), field), 1);           \
  254             (var) = (tvar))
  255 
  256 #define STAILQ_INIT(head) do {                                          \
  257         STAILQ_FIRST((head)) = NULL;                                    \
  258         (head)->stqh_last = &STAILQ_FIRST((head));                      \
  259 } while (0)
  260 
  261 #define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do {               \
  262         if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
  263                 (head)->stqh_last = &STAILQ_NEXT((elm), field);         \
  264         STAILQ_NEXT((tqelm), field) = (elm);                            \
  265 } while (0)
  266 
  267 #define STAILQ_INSERT_HEAD(head, elm, field) do {                       \
  268         if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
  269                 (head)->stqh_last = &STAILQ_NEXT((elm), field);         \
  270         STAILQ_FIRST((head)) = (elm);                                   \
  271 } while (0)
  272 
  273 #define STAILQ_INSERT_TAIL(head, elm, field) do {                       \
  274         STAILQ_NEXT((elm), field) = NULL;                               \
  275         *(head)->stqh_last = (elm);                                     \
  276         (head)->stqh_last = &STAILQ_NEXT((elm), field);                 \
  277 } while (0)
  278 
  279 #define STAILQ_LAST(head, type, field)                                  \
  280         (STAILQ_EMPTY((head)) ?                                         \
  281                 NULL :                                                  \
  282                 ((struct type *)(void *)                                \
  283                 ((char *)((head)->stqh_last) - __offsetof(struct type, field))))
  284 
  285 #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
  286 
  287 #define STAILQ_REMOVE(head, elm, type, field) do {                      \
  288         if (STAILQ_FIRST((head)) == (elm)) {                            \
  289                 STAILQ_REMOVE_HEAD((head), field);                      \
  290         }                                                               \
  291         else {                                                          \
  292                 struct type *curelm = STAILQ_FIRST((head));             \
  293                 while (STAILQ_NEXT(curelm, field) != (elm))             \
  294                         curelm = STAILQ_NEXT(curelm, field);            \
  295                 STAILQ_REMOVE_AFTER(head, curelm, field);               \
  296         }                                                               \
  297         TRASHIT((elm)->field.stqe_next);                                \
  298 } while (0)
  299 
  300 #define STAILQ_REMOVE_HEAD(head, field) do {                            \
  301         if ((STAILQ_FIRST((head)) =                                     \
  302              STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL)         \
  303                 (head)->stqh_last = &STAILQ_FIRST((head));              \
  304 } while (0)
  305 
  306 #define STAILQ_REMOVE_AFTER(head, elm, field) do {                      \
  307         if ((STAILQ_NEXT(elm, field) =                                  \
  308              STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL)      \
  309                 (head)->stqh_last = &STAILQ_NEXT((elm), field);         \
  310 } while (0)
  311 
  312 /*
  313  * List declarations.
  314  */
  315 #define LIST_HEAD(name, type)                                           \
  316 struct name {                                                           \
  317         struct type *lh_first;  /* first element */                     \
  318 }
  319 
  320 #define LIST_HEAD_INITIALIZER(head)                                     \
  321         { NULL }
  322 
  323 #define LIST_ENTRY(type)                                                \
  324 struct {                                                                \
  325         struct type *le_next;   /* next element */                      \
  326         struct type **le_prev;  /* address of previous next element */  \
  327 }
  328 
  329 /*
  330  * List functions.
  331  */
  332 
  333 #if (defined(_KERNEL) && defined(INVARIANTS))
  334 #define QMD_LIST_CHECK_HEAD(head, field) do {                           \
  335         if (LIST_FIRST((head)) != NULL &&                               \
  336             LIST_FIRST((head))->field.le_prev !=                        \
  337              &LIST_FIRST((head)))                                       \
  338                 panic("Bad list head %p first->prev != head", (head));  \
  339 } while (0)
  340 
  341 #define QMD_LIST_CHECK_NEXT(elm, field) do {                            \
  342         if (LIST_NEXT((elm), field) != NULL &&                          \
  343             LIST_NEXT((elm), field)->field.le_prev !=                   \
  344              &((elm)->field.le_next))                                   \
  345                 panic("Bad link elm %p next->prev != elm", (elm));      \
  346 } while (0)
  347 
  348 #define QMD_LIST_CHECK_PREV(elm, field) do {                            \
  349         if (*(elm)->field.le_prev != (elm))                             \
  350                 panic("Bad link elm %p prev->next != elm", (elm));      \
  351 } while (0)
  352 #else
  353 #define QMD_LIST_CHECK_HEAD(head, field)
  354 #define QMD_LIST_CHECK_NEXT(elm, field)
  355 #define QMD_LIST_CHECK_PREV(elm, field)
  356 #endif /* (_KERNEL && INVARIANTS) */
  357 
  358 #define LIST_EMPTY(head)        ((head)->lh_first == NULL)
  359 
  360 #define LIST_FIRST(head)        ((head)->lh_first)
  361 
  362 #define LIST_FOREACH(var, head, field)                                  \
  363         for ((var) = LIST_FIRST((head));                                \
  364             (var);                                                      \
  365             (var) = LIST_NEXT((var), field))
  366 
  367 #define LIST_FOREACH_SAFE(var, head, field, tvar)                       \
  368         for ((var) = LIST_FIRST((head));                                \
  369             (var) && ((tvar) = LIST_NEXT((var), field), 1);             \
  370             (var) = (tvar))
  371 
  372 #define LIST_INIT(head) do {                                            \
  373         LIST_FIRST((head)) = NULL;                                      \
  374 } while (0)
  375 
  376 #define LIST_INSERT_AFTER(listelm, elm, field) do {                     \
  377         QMD_LIST_CHECK_NEXT(listelm, field);                            \
  378         if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
  379                 LIST_NEXT((listelm), field)->field.le_prev =            \
  380                     &LIST_NEXT((elm), field);                           \
  381         LIST_NEXT((listelm), field) = (elm);                            \
  382         (elm)->field.le_prev = &LIST_NEXT((listelm), field);            \
  383 } while (0)
  384 
  385 #define LIST_INSERT_BEFORE(listelm, elm, field) do {                    \
  386         QMD_LIST_CHECK_PREV(listelm, field);                            \
  387         (elm)->field.le_prev = (listelm)->field.le_prev;                \
  388         LIST_NEXT((elm), field) = (listelm);                            \
  389         *(listelm)->field.le_prev = (elm);                              \
  390         (listelm)->field.le_prev = &LIST_NEXT((elm), field);            \
  391 } while (0)
  392 
  393 #define LIST_INSERT_HEAD(head, elm, field) do {                         \
  394         QMD_LIST_CHECK_HEAD((head), field);                             \
  395         if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL)     \
  396                 LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
  397         LIST_FIRST((head)) = (elm);                                     \
  398         (elm)->field.le_prev = &LIST_FIRST((head));                     \
  399 } while (0)
  400 
  401 #define LIST_NEXT(elm, field)   ((elm)->field.le_next)
  402 
  403 #define LIST_REMOVE(elm, field) do {                                    \
  404         QMD_LIST_CHECK_NEXT(elm, field);                                \
  405         QMD_LIST_CHECK_PREV(elm, field);                                \
  406         if (LIST_NEXT((elm), field) != NULL)                            \
  407                 LIST_NEXT((elm), field)->field.le_prev =                \
  408                     (elm)->field.le_prev;                               \
  409         *(elm)->field.le_prev = LIST_NEXT((elm), field);                \
  410         TRASHIT((elm)->field.le_next);                                  \
  411         TRASHIT((elm)->field.le_prev);                                  \
  412 } while (0)
  413 
  414 /*
  415  * Tail queue declarations.
  416  */
  417 #define TAILQ_HEAD(name, type)                                          \
  418 struct name {                                                           \
  419         struct type *tqh_first; /* first element */                     \
  420         struct type **tqh_last; /* addr of last next element */         \
  421         TRACEBUF                                                        \
  422 }
  423 
  424 #define TAILQ_HEAD_INITIALIZER(head)                                    \
  425         { NULL, &(head).tqh_first }
  426 
  427 #define TAILQ_ENTRY(type)                                               \
  428 struct {                                                                \
  429         struct type *tqe_next;  /* next element */                      \
  430         struct type **tqe_prev; /* address of previous next element */  \
  431         TRACEBUF                                                        \
  432 }
  433 
  434 /*
  435  * Tail queue functions.
  436  */
  437 #if (defined(_KERNEL) && defined(INVARIANTS))
  438 #define QMD_TAILQ_CHECK_HEAD(head, field) do {                          \
  439         if (!TAILQ_EMPTY(head) &&                                       \
  440             TAILQ_FIRST((head))->field.tqe_prev !=                      \
  441              &TAILQ_FIRST((head)))                                      \
  442                 panic("Bad tailq head %p first->prev != head", (head)); \
  443 } while (0)
  444 
  445 #define QMD_TAILQ_CHECK_TAIL(head, field) do {                          \
  446         if (*(head)->tqh_last != NULL)                                  \
  447                 panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head));  \
  448 } while (0)
  449 
  450 #define QMD_TAILQ_CHECK_NEXT(elm, field) do {                           \
  451         if (TAILQ_NEXT((elm), field) != NULL &&                         \
  452             TAILQ_NEXT((elm), field)->field.tqe_prev !=                 \
  453              &((elm)->field.tqe_next))                                  \
  454                 panic("Bad link elm %p next->prev != elm", (elm));      \
  455 } while (0)
  456 
  457 #define QMD_TAILQ_CHECK_PREV(elm, field) do {                           \
  458         if (*(elm)->field.tqe_prev != (elm))                            \
  459                 panic("Bad link elm %p prev->next != elm", (elm));      \
  460 } while (0)
  461 #else
  462 #define QMD_TAILQ_CHECK_HEAD(head, field)
  463 #define QMD_TAILQ_CHECK_TAIL(head, headname)
  464 #define QMD_TAILQ_CHECK_NEXT(elm, field)
  465 #define QMD_TAILQ_CHECK_PREV(elm, field)
  466 #endif /* (_KERNEL && INVARIANTS) */
  467 
  468 #define TAILQ_CONCAT(head1, head2, field) do {                          \
  469         if (!TAILQ_EMPTY(head2)) {                                      \
  470                 *(head1)->tqh_last = (head2)->tqh_first;                \
  471                 (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
  472                 (head1)->tqh_last = (head2)->tqh_last;                  \
  473                 TAILQ_INIT((head2));                                    \
  474                 QMD_TRACE_HEAD(head1);                                  \
  475                 QMD_TRACE_HEAD(head2);                                  \
  476         }                                                               \
  477 } while (0)
  478 
  479 #define TAILQ_EMPTY(head)       ((head)->tqh_first == NULL)
  480 
  481 #define TAILQ_FIRST(head)       ((head)->tqh_first)
  482 
  483 #define TAILQ_FOREACH(var, head, field)                                 \
  484         for ((var) = TAILQ_FIRST((head));                               \
  485             (var);                                                      \
  486             (var) = TAILQ_NEXT((var), field))
  487 
  488 #define TAILQ_FOREACH_SAFE(var, head, field, tvar)                      \
  489         for ((var) = TAILQ_FIRST((head));                               \
  490             (var) && ((tvar) = TAILQ_NEXT((var), field), 1);            \
  491             (var) = (tvar))
  492 
  493 #define TAILQ_FOREACH_REVERSE(var, head, headname, field)               \
  494         for ((var) = TAILQ_LAST((head), headname);                      \
  495             (var);                                                      \
  496             (var) = TAILQ_PREV((var), headname, field))
  497 
  498 #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar)    \
  499         for ((var) = TAILQ_LAST((head), headname);                      \
  500             (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1);  \
  501             (var) = (tvar))
  502 
  503 #define TAILQ_INIT(head) do {                                           \
  504         TAILQ_FIRST((head)) = NULL;                                     \
  505         (head)->tqh_last = &TAILQ_FIRST((head));                        \
  506         QMD_TRACE_HEAD(head);                                           \
  507 } while (0)
  508 
  509 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do {              \
  510         QMD_TAILQ_CHECK_NEXT(listelm, field);                           \
  511         if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
  512                 TAILQ_NEXT((elm), field)->field.tqe_prev =              \
  513                     &TAILQ_NEXT((elm), field);                          \
  514         else {                                                          \
  515                 (head)->tqh_last = &TAILQ_NEXT((elm), field);           \
  516                 QMD_TRACE_HEAD(head);                                   \
  517         }                                                               \
  518         TAILQ_NEXT((listelm), field) = (elm);                           \
  519         (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field);          \
  520         QMD_TRACE_ELEM(&(elm)->field);                                  \
  521         QMD_TRACE_ELEM(&listelm->field);                                \
  522 } while (0)
  523 
  524 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do {                   \
  525         QMD_TAILQ_CHECK_PREV(listelm, field);                           \
  526         (elm)->field.tqe_prev = (listelm)->field.tqe_prev;              \
  527         TAILQ_NEXT((elm), field) = (listelm);                           \
  528         *(listelm)->field.tqe_prev = (elm);                             \
  529         (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field);          \
  530         QMD_TRACE_ELEM(&(elm)->field);                                  \
  531         QMD_TRACE_ELEM(&listelm->field);                                \
  532 } while (0)
  533 
  534 #define TAILQ_INSERT_HEAD(head, elm, field) do {                        \
  535         QMD_TAILQ_CHECK_HEAD(head, field);                              \
  536         if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL)   \
  537                 TAILQ_FIRST((head))->field.tqe_prev =                   \
  538                     &TAILQ_NEXT((elm), field);                          \
  539         else                                                            \
  540                 (head)->tqh_last = &TAILQ_NEXT((elm), field);           \
  541         TAILQ_FIRST((head)) = (elm);                                    \
  542         (elm)->field.tqe_prev = &TAILQ_FIRST((head));                   \
  543         QMD_TRACE_HEAD(head);                                           \
  544         QMD_TRACE_ELEM(&(elm)->field);                                  \
  545 } while (0)
  546 
  547 #define TAILQ_INSERT_TAIL(head, elm, field) do {                        \
  548         QMD_TAILQ_CHECK_TAIL(head, field);                              \
  549         TAILQ_NEXT((elm), field) = NULL;                                \
  550         (elm)->field.tqe_prev = (head)->tqh_last;                       \
  551         *(head)->tqh_last = (elm);                                      \
  552         (head)->tqh_last = &TAILQ_NEXT((elm), field);                   \
  553         QMD_TRACE_HEAD(head);                                           \
  554         QMD_TRACE_ELEM(&(elm)->field);                                  \
  555 } while (0)
  556 
  557 #define TAILQ_LAST(head, headname)                                      \
  558         (*(((struct headname *)((head)->tqh_last))->tqh_last))
  559 
  560 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  561 
  562 #define TAILQ_PREV(elm, headname, field)                                \
  563         (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  564 
  565 #define TAILQ_REMOVE(head, elm, field) do {                             \
  566         QMD_TAILQ_CHECK_NEXT(elm, field);                               \
  567         QMD_TAILQ_CHECK_PREV(elm, field);                               \
  568         if ((TAILQ_NEXT((elm), field)) != NULL)                         \
  569                 TAILQ_NEXT((elm), field)->field.tqe_prev =              \
  570                     (elm)->field.tqe_prev;                              \
  571         else {                                                          \
  572                 (head)->tqh_last = (elm)->field.tqe_prev;               \
  573                 QMD_TRACE_HEAD(head);                                   \
  574         }                                                               \
  575         *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field);              \
  576         TRASHIT((elm)->field.tqe_next);                                 \
  577         TRASHIT((elm)->field.tqe_prev);                                 \
  578         QMD_TRACE_ELEM(&(elm)->field);                                  \
  579 } while (0)
  580 
  581 
  582 #ifdef _KERNEL
  583 
  584 /*
  585  * XXX insque() and remque() are an old way of handling certain queues.
  586  * They bogusly assumes that all queue heads look alike.
  587  */
  588 
  589 struct quehead {
  590         struct quehead *qh_link;
  591         struct quehead *qh_rlink;
  592 };
  593 
  594 #ifdef __CC_SUPPORTS___INLINE
  595 
  596 static __inline void
  597 insque(void *a, void *b)
  598 {
  599         struct quehead *element = (struct quehead *)a,
  600                  *head = (struct quehead *)b;
  601 
  602         element->qh_link = head->qh_link;
  603         element->qh_rlink = head;
  604         head->qh_link = element;
  605         element->qh_link->qh_rlink = element;
  606 }
  607 
  608 static __inline void
  609 remque(void *a)
  610 {
  611         struct quehead *element = (struct quehead *)a;
  612 
  613         element->qh_link->qh_rlink = element->qh_rlink;
  614         element->qh_rlink->qh_link = element->qh_link;
  615         element->qh_rlink = 0;
  616 }
  617 
  618 #else /* !__CC_SUPPORTS___INLINE */
  619 
  620 void    insque(void *a, void *b);
  621 void    remque(void *a);
  622 
  623 #endif /* __CC_SUPPORTS___INLINE */
  624 
  625 #endif /* _KERNEL */
  626 
  627 #endif /* !_SYS_QUEUE_H_ */

Cache object: 70797dd8a84a05f5d5b2e85715857f0c


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.