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: stable/8/sys/sys/queue.h 279635 2015-03-05 09:29:05Z hselasky $
   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_FROM                +       +       +       +
   92  * _FOREACH_SAFE                +       +       +       +
   93  * _FOREACH_FROM_SAFE           +       +       +       +
   94  * _FOREACH_REVERSE             -       -       -       +
   95  * _FOREACH_REVERSE_FROM        -       -       -       +
   96  * _FOREACH_REVERSE_SAFE        -       -       -       +
   97  * _FOREACH_REVERSE_FROM_SAFE   -       -       -       +
   98  * _INSERT_HEAD                 +       +       +       +
   99  * _INSERT_BEFORE               -       +       -       +
  100  * _INSERT_AFTER                +       +       +       +
  101  * _INSERT_TAIL                 -       -       +       +
  102  * _CONCAT                      -       -       +       +
  103  * _REMOVE_AFTER                +       -       +       -
  104  * _REMOVE_HEAD                 +       -       +       -
  105  * _REMOVE                      +       +       +       +
  106  * _SWAP                        +       +       +       +
  107  *
  108  */
  109 #ifdef QUEUE_MACRO_DEBUG
  110 /* Store the last 2 places the queue element or head was altered */
  111 struct qm_trace {
  112         char * lastfile;
  113         int lastline;
  114         char * prevfile;
  115         int prevline;
  116 };
  117 
  118 #define TRACEBUF        struct qm_trace trace;
  119 #define TRASHIT(x)      do {(x) = (void *)-1;} while (0)
  120 #define QMD_SAVELINK(name, link)        void **name = (void *)&(link)
  121 
  122 #define QMD_TRACE_HEAD(head) do {                                       \
  123         (head)->trace.prevline = (head)->trace.lastline;                \
  124         (head)->trace.prevfile = (head)->trace.lastfile;                \
  125         (head)->trace.lastline = __LINE__;                              \
  126         (head)->trace.lastfile = __FILE__;                              \
  127 } while (0)
  128 
  129 #define QMD_TRACE_ELEM(elem) do {                                       \
  130         (elem)->trace.prevline = (elem)->trace.lastline;                \
  131         (elem)->trace.prevfile = (elem)->trace.lastfile;                \
  132         (elem)->trace.lastline = __LINE__;                              \
  133         (elem)->trace.lastfile = __FILE__;                              \
  134 } while (0)
  135 
  136 #else
  137 #define QMD_TRACE_ELEM(elem)
  138 #define QMD_TRACE_HEAD(head)
  139 #define QMD_SAVELINK(name, link)
  140 #define TRACEBUF
  141 #define TRASHIT(x)
  142 #endif  /* QUEUE_MACRO_DEBUG */
  143 
  144 /*
  145  * Singly-linked List declarations.
  146  */
  147 #define SLIST_HEAD(name, type)                                          \
  148 struct name {                                                           \
  149         struct type *slh_first; /* first element */                     \
  150 }
  151 
  152 #define SLIST_HEAD_INITIALIZER(head)                                    \
  153         { NULL }
  154 
  155 #define SLIST_ENTRY(type)                                               \
  156 struct {                                                                \
  157         struct type *sle_next;  /* next element */                      \
  158 }
  159 
  160 /*
  161  * Singly-linked List functions.
  162  */
  163 #define SLIST_EMPTY(head)       ((head)->slh_first == NULL)
  164 
  165 #define SLIST_FIRST(head)       ((head)->slh_first)
  166 
  167 #define SLIST_FOREACH(var, head, field)                                 \
  168         for ((var) = SLIST_FIRST((head));                               \
  169             (var);                                                      \
  170             (var) = SLIST_NEXT((var), field))
  171 
  172 #define SLIST_FOREACH_FROM(var, head, field)                            \
  173         for ((var) = ((var) ? (var) : SLIST_FIRST((head)));             \
  174             (var);                                                      \
  175             (var) = SLIST_NEXT((var), field))
  176 
  177 #define SLIST_FOREACH_SAFE(var, head, field, tvar)                      \
  178         for ((var) = SLIST_FIRST((head));                               \
  179             (var) && ((tvar) = SLIST_NEXT((var), field), 1);            \
  180             (var) = (tvar))
  181 
  182 #define SLIST_FOREACH_FROM_SAFE(var, head, field, tvar)                 \
  183         for ((var) = ((var) ? (var) : SLIST_FIRST((head)));             \
  184             (var) && ((tvar) = SLIST_NEXT((var), field), 1);            \
  185             (var) = (tvar))
  186 
  187 #define SLIST_FOREACH_PREVPTR(var, varp, head, field)                   \
  188         for ((varp) = &SLIST_FIRST((head));                             \
  189             ((var) = *(varp)) != NULL;                                  \
  190             (varp) = &SLIST_NEXT((var), field))
  191 
  192 #define SLIST_INIT(head) do {                                           \
  193         SLIST_FIRST((head)) = NULL;                                     \
  194 } while (0)
  195 
  196 #define SLIST_INSERT_AFTER(slistelm, elm, field) do {                   \
  197         SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field);       \
  198         SLIST_NEXT((slistelm), field) = (elm);                          \
  199 } while (0)
  200 
  201 #define SLIST_INSERT_HEAD(head, elm, field) do {                        \
  202         SLIST_NEXT((elm), field) = SLIST_FIRST((head));                 \
  203         SLIST_FIRST((head)) = (elm);                                    \
  204 } while (0)
  205 
  206 #define SLIST_NEXT(elm, field)  ((elm)->field.sle_next)
  207 
  208 #define SLIST_REMOVE(head, elm, type, field) do {                       \
  209         QMD_SAVELINK(oldnext, (elm)->field.sle_next);                   \
  210         if (SLIST_FIRST((head)) == (elm)) {                             \
  211                 SLIST_REMOVE_HEAD((head), field);                       \
  212         }                                                               \
  213         else {                                                          \
  214                 struct type *curelm = SLIST_FIRST((head));              \
  215                 while (SLIST_NEXT(curelm, field) != (elm))              \
  216                         curelm = SLIST_NEXT(curelm, field);             \
  217                 SLIST_REMOVE_AFTER(curelm, field);                      \
  218         }                                                               \
  219         TRASHIT(*oldnext);                                              \
  220 } while (0)
  221 
  222 #define SLIST_REMOVE_AFTER(elm, field) do {                             \
  223         SLIST_NEXT(elm, field) =                                        \
  224             SLIST_NEXT(SLIST_NEXT(elm, field), field);                  \
  225 } while (0)
  226 
  227 #define SLIST_REMOVE_HEAD(head, field) do {                             \
  228         SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field);   \
  229 } while (0)
  230 
  231 #define SLIST_SWAP(head1, head2, type) do {                             \
  232         struct type *swap_first = SLIST_FIRST(head1);                   \
  233         SLIST_FIRST(head1) = SLIST_FIRST(head2);                        \
  234         SLIST_FIRST(head2) = swap_first;                                \
  235 } while (0)
  236 
  237 /*
  238  * Singly-linked Tail queue declarations.
  239  */
  240 #define STAILQ_HEAD(name, type)                                         \
  241 struct name {                                                           \
  242         struct type *stqh_first;/* first element */                     \
  243         struct type **stqh_last;/* addr of last next element */         \
  244 }
  245 
  246 #define STAILQ_HEAD_INITIALIZER(head)                                   \
  247         { NULL, &(head).stqh_first }
  248 
  249 #define STAILQ_ENTRY(type)                                              \
  250 struct {                                                                \
  251         struct type *stqe_next; /* next element */                      \
  252 }
  253 
  254 /*
  255  * Singly-linked Tail queue functions.
  256  */
  257 #define STAILQ_CONCAT(head1, head2) do {                                \
  258         if (!STAILQ_EMPTY((head2))) {                                   \
  259                 *(head1)->stqh_last = (head2)->stqh_first;              \
  260                 (head1)->stqh_last = (head2)->stqh_last;                \
  261                 STAILQ_INIT((head2));                                   \
  262         }                                                               \
  263 } while (0)
  264 
  265 #define STAILQ_EMPTY(head)      ((head)->stqh_first == NULL)
  266 
  267 #define STAILQ_FIRST(head)      ((head)->stqh_first)
  268 
  269 #define STAILQ_FOREACH(var, head, field)                                \
  270         for((var) = STAILQ_FIRST((head));                               \
  271            (var);                                                       \
  272            (var) = STAILQ_NEXT((var), field))
  273 
  274 #define STAILQ_FOREACH_FROM(var, head, field)                           \
  275         for ((var) = ((var) ? (var) : STAILQ_FIRST((head)));            \
  276            (var);                                                       \
  277            (var) = STAILQ_NEXT((var), field))
  278 
  279 #define STAILQ_FOREACH_SAFE(var, head, field, tvar)                     \
  280         for ((var) = STAILQ_FIRST((head));                              \
  281             (var) && ((tvar) = STAILQ_NEXT((var), field), 1);           \
  282             (var) = (tvar))
  283 
  284 #define STAILQ_FOREACH_FROM_SAFE(var, head, field, tvar)                \
  285         for ((var) = ((var) ? (var) : STAILQ_FIRST((head)));            \
  286             (var) && ((tvar) = STAILQ_NEXT((var), field), 1);           \
  287             (var) = (tvar))
  288 
  289 #define STAILQ_INIT(head) do {                                          \
  290         STAILQ_FIRST((head)) = NULL;                                    \
  291         (head)->stqh_last = &STAILQ_FIRST((head));                      \
  292 } while (0)
  293 
  294 #define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do {               \
  295         if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
  296                 (head)->stqh_last = &STAILQ_NEXT((elm), field);         \
  297         STAILQ_NEXT((tqelm), field) = (elm);                            \
  298 } while (0)
  299 
  300 #define STAILQ_INSERT_HEAD(head, elm, field) do {                       \
  301         if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
  302                 (head)->stqh_last = &STAILQ_NEXT((elm), field);         \
  303         STAILQ_FIRST((head)) = (elm);                                   \
  304 } while (0)
  305 
  306 #define STAILQ_INSERT_TAIL(head, elm, field) do {                       \
  307         STAILQ_NEXT((elm), field) = NULL;                               \
  308         *(head)->stqh_last = (elm);                                     \
  309         (head)->stqh_last = &STAILQ_NEXT((elm), field);                 \
  310 } while (0)
  311 
  312 #define STAILQ_LAST(head, type, field)                                  \
  313         (STAILQ_EMPTY((head)) ?                                         \
  314                 NULL :                                                  \
  315                 ((struct type *)(void *)                                \
  316                 ((char *)((head)->stqh_last) - __offsetof(struct type, field))))
  317 
  318 #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
  319 
  320 #define STAILQ_REMOVE(head, elm, type, field) do {                      \
  321         QMD_SAVELINK(oldnext, (elm)->field.stqe_next);                  \
  322         if (STAILQ_FIRST((head)) == (elm)) {                            \
  323                 STAILQ_REMOVE_HEAD((head), field);                      \
  324         }                                                               \
  325         else {                                                          \
  326                 struct type *curelm = STAILQ_FIRST((head));             \
  327                 while (STAILQ_NEXT(curelm, field) != (elm))             \
  328                         curelm = STAILQ_NEXT(curelm, field);            \
  329                 STAILQ_REMOVE_AFTER(head, curelm, field);               \
  330         }                                                               \
  331         TRASHIT(*oldnext);                                              \
  332 } while (0)
  333 
  334 #define STAILQ_REMOVE_AFTER(head, elm, field) do {                      \
  335         if ((STAILQ_NEXT(elm, field) =                                  \
  336              STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL)      \
  337                 (head)->stqh_last = &STAILQ_NEXT((elm), field);         \
  338 } while (0)
  339 
  340 #define STAILQ_REMOVE_HEAD(head, field) do {                            \
  341         if ((STAILQ_FIRST((head)) =                                     \
  342              STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL)         \
  343                 (head)->stqh_last = &STAILQ_FIRST((head));              \
  344 } while (0)
  345 
  346 #define STAILQ_SWAP(head1, head2, type) do {                            \
  347         struct type *swap_first = STAILQ_FIRST(head1);                  \
  348         struct type **swap_last = (head1)->stqh_last;                   \
  349         STAILQ_FIRST(head1) = STAILQ_FIRST(head2);                      \
  350         (head1)->stqh_last = (head2)->stqh_last;                        \
  351         STAILQ_FIRST(head2) = swap_first;                               \
  352         (head2)->stqh_last = swap_last;                                 \
  353         if (STAILQ_EMPTY(head1))                                        \
  354                 (head1)->stqh_last = &STAILQ_FIRST(head1);              \
  355         if (STAILQ_EMPTY(head2))                                        \
  356                 (head2)->stqh_last = &STAILQ_FIRST(head2);              \
  357 } while (0)
  358 
  359 
  360 /*
  361  * List declarations.
  362  */
  363 #define LIST_HEAD(name, type)                                           \
  364 struct name {                                                           \
  365         struct type *lh_first;  /* first element */                     \
  366 }
  367 
  368 #define LIST_HEAD_INITIALIZER(head)                                     \
  369         { NULL }
  370 
  371 #define LIST_ENTRY(type)                                                \
  372 struct {                                                                \
  373         struct type *le_next;   /* next element */                      \
  374         struct type **le_prev;  /* address of previous next element */  \
  375 }
  376 
  377 /*
  378  * List functions.
  379  */
  380 
  381 #if (defined(_KERNEL) && defined(INVARIANTS))
  382 #define QMD_LIST_CHECK_HEAD(head, field) do {                           \
  383         if (LIST_FIRST((head)) != NULL &&                               \
  384             LIST_FIRST((head))->field.le_prev !=                        \
  385              &LIST_FIRST((head)))                                       \
  386                 panic("Bad list head %p first->prev != head", (head));  \
  387 } while (0)
  388 
  389 #define QMD_LIST_CHECK_NEXT(elm, field) do {                            \
  390         if (LIST_NEXT((elm), field) != NULL &&                          \
  391             LIST_NEXT((elm), field)->field.le_prev !=                   \
  392              &((elm)->field.le_next))                                   \
  393                 panic("Bad link elm %p next->prev != elm", (elm));      \
  394 } while (0)
  395 
  396 #define QMD_LIST_CHECK_PREV(elm, field) do {                            \
  397         if (*(elm)->field.le_prev != (elm))                             \
  398                 panic("Bad link elm %p prev->next != elm", (elm));      \
  399 } while (0)
  400 #else
  401 #define QMD_LIST_CHECK_HEAD(head, field)
  402 #define QMD_LIST_CHECK_NEXT(elm, field)
  403 #define QMD_LIST_CHECK_PREV(elm, field)
  404 #endif /* (_KERNEL && INVARIANTS) */
  405 
  406 #define LIST_EMPTY(head)        ((head)->lh_first == NULL)
  407 
  408 #define LIST_FIRST(head)        ((head)->lh_first)
  409 
  410 #define LIST_FOREACH(var, head, field)                                  \
  411         for ((var) = LIST_FIRST((head));                                \
  412             (var);                                                      \
  413             (var) = LIST_NEXT((var), field))
  414 
  415 #define LIST_FOREACH_FROM(var, head, field)                             \
  416         for ((var) = ((var) ? (var) : LIST_FIRST((head)));              \
  417             (var);                                                      \
  418             (var) = LIST_NEXT((var), field))
  419 
  420 #define LIST_FOREACH_SAFE(var, head, field, tvar)                       \
  421         for ((var) = LIST_FIRST((head));                                \
  422             (var) && ((tvar) = LIST_NEXT((var), field), 1);             \
  423             (var) = (tvar))
  424 
  425 #define LIST_FOREACH_FROM_SAFE(var, head, field, tvar)                  \
  426         for ((var) = ((var) ? (var) : LIST_FIRST((head)));              \
  427             (var) && ((tvar) = LIST_NEXT((var), field), 1);             \
  428             (var) = (tvar))
  429 
  430 #define LIST_INIT(head) do {                                            \
  431         LIST_FIRST((head)) = NULL;                                      \
  432 } while (0)
  433 
  434 #define LIST_INSERT_AFTER(listelm, elm, field) do {                     \
  435         QMD_LIST_CHECK_NEXT(listelm, field);                            \
  436         if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
  437                 LIST_NEXT((listelm), field)->field.le_prev =            \
  438                     &LIST_NEXT((elm), field);                           \
  439         LIST_NEXT((listelm), field) = (elm);                            \
  440         (elm)->field.le_prev = &LIST_NEXT((listelm), field);            \
  441 } while (0)
  442 
  443 #define LIST_INSERT_BEFORE(listelm, elm, field) do {                    \
  444         QMD_LIST_CHECK_PREV(listelm, field);                            \
  445         (elm)->field.le_prev = (listelm)->field.le_prev;                \
  446         LIST_NEXT((elm), field) = (listelm);                            \
  447         *(listelm)->field.le_prev = (elm);                              \
  448         (listelm)->field.le_prev = &LIST_NEXT((elm), field);            \
  449 } while (0)
  450 
  451 #define LIST_INSERT_HEAD(head, elm, field) do {                         \
  452         QMD_LIST_CHECK_HEAD((head), field);                             \
  453         if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL)     \
  454                 LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
  455         LIST_FIRST((head)) = (elm);                                     \
  456         (elm)->field.le_prev = &LIST_FIRST((head));                     \
  457 } while (0)
  458 
  459 #define LIST_NEXT(elm, field)   ((elm)->field.le_next)
  460 
  461 #define LIST_REMOVE(elm, field) do {                                    \
  462         QMD_SAVELINK(oldnext, (elm)->field.le_next);                    \
  463         QMD_SAVELINK(oldprev, (elm)->field.le_prev);                    \
  464         QMD_LIST_CHECK_NEXT(elm, field);                                \
  465         QMD_LIST_CHECK_PREV(elm, field);                                \
  466         if (LIST_NEXT((elm), field) != NULL)                            \
  467                 LIST_NEXT((elm), field)->field.le_prev =                \
  468                     (elm)->field.le_prev;                               \
  469         *(elm)->field.le_prev = LIST_NEXT((elm), field);                \
  470         TRASHIT(*oldnext);                                              \
  471         TRASHIT(*oldprev);                                              \
  472 } while (0)
  473 
  474 #define LIST_SWAP(head1, head2, type, field) do {                       \
  475         struct type *swap_tmp = LIST_FIRST((head1));                    \
  476         LIST_FIRST((head1)) = LIST_FIRST((head2));                      \
  477         LIST_FIRST((head2)) = swap_tmp;                                 \
  478         if ((swap_tmp = LIST_FIRST((head1))) != NULL)                   \
  479                 swap_tmp->field.le_prev = &LIST_FIRST((head1));         \
  480         if ((swap_tmp = LIST_FIRST((head2))) != NULL)                   \
  481                 swap_tmp->field.le_prev = &LIST_FIRST((head2));         \
  482 } while (0)
  483 
  484 /*
  485  * Tail queue declarations.
  486  */
  487 #define TAILQ_HEAD(name, type)                                          \
  488 struct name {                                                           \
  489         struct type *tqh_first; /* first element */                     \
  490         struct type **tqh_last; /* addr of last next element */         \
  491         TRACEBUF                                                        \
  492 }
  493 
  494 #define TAILQ_HEAD_INITIALIZER(head)                                    \
  495         { NULL, &(head).tqh_first }
  496 
  497 #define TAILQ_ENTRY(type)                                               \
  498 struct {                                                                \
  499         struct type *tqe_next;  /* next element */                      \
  500         struct type **tqe_prev; /* address of previous next element */  \
  501         TRACEBUF                                                        \
  502 }
  503 
  504 /*
  505  * Tail queue functions.
  506  */
  507 #if (defined(_KERNEL) && defined(INVARIANTS))
  508 #define QMD_TAILQ_CHECK_HEAD(head, field) do {                          \
  509         if (!TAILQ_EMPTY(head) &&                                       \
  510             TAILQ_FIRST((head))->field.tqe_prev !=                      \
  511              &TAILQ_FIRST((head)))                                      \
  512                 panic("Bad tailq head %p first->prev != head", (head)); \
  513 } while (0)
  514 
  515 #define QMD_TAILQ_CHECK_TAIL(head, field) do {                          \
  516         if (*(head)->tqh_last != NULL)                                  \
  517                 panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head));  \
  518 } while (0)
  519 
  520 #define QMD_TAILQ_CHECK_NEXT(elm, field) do {                           \
  521         if (TAILQ_NEXT((elm), field) != NULL &&                         \
  522             TAILQ_NEXT((elm), field)->field.tqe_prev !=                 \
  523              &((elm)->field.tqe_next))                                  \
  524                 panic("Bad link elm %p next->prev != elm", (elm));      \
  525 } while (0)
  526 
  527 #define QMD_TAILQ_CHECK_PREV(elm, field) do {                           \
  528         if (*(elm)->field.tqe_prev != (elm))                            \
  529                 panic("Bad link elm %p prev->next != elm", (elm));      \
  530 } while (0)
  531 #else
  532 #define QMD_TAILQ_CHECK_HEAD(head, field)
  533 #define QMD_TAILQ_CHECK_TAIL(head, headname)
  534 #define QMD_TAILQ_CHECK_NEXT(elm, field)
  535 #define QMD_TAILQ_CHECK_PREV(elm, field)
  536 #endif /* (_KERNEL && INVARIANTS) */
  537 
  538 #define TAILQ_CONCAT(head1, head2, field) do {                          \
  539         if (!TAILQ_EMPTY(head2)) {                                      \
  540                 *(head1)->tqh_last = (head2)->tqh_first;                \
  541                 (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
  542                 (head1)->tqh_last = (head2)->tqh_last;                  \
  543                 TAILQ_INIT((head2));                                    \
  544                 QMD_TRACE_HEAD(head1);                                  \
  545                 QMD_TRACE_HEAD(head2);                                  \
  546         }                                                               \
  547 } while (0)
  548 
  549 #define TAILQ_EMPTY(head)       ((head)->tqh_first == NULL)
  550 
  551 #define TAILQ_FIRST(head)       ((head)->tqh_first)
  552 
  553 #define TAILQ_FOREACH(var, head, field)                                 \
  554         for ((var) = TAILQ_FIRST((head));                               \
  555             (var);                                                      \
  556             (var) = TAILQ_NEXT((var), field))
  557 
  558 #define TAILQ_FOREACH_FROM(var, head, field)                            \
  559         for ((var) = ((var) ? (var) : TAILQ_FIRST((head)));             \
  560             (var);                                                      \
  561             (var) = TAILQ_NEXT((var), field))
  562 
  563 #define TAILQ_FOREACH_SAFE(var, head, field, tvar)                      \
  564         for ((var) = TAILQ_FIRST((head));                               \
  565             (var) && ((tvar) = TAILQ_NEXT((var), field), 1);            \
  566             (var) = (tvar))
  567 
  568 #define TAILQ_FOREACH_FROM_SAFE(var, head, field, tvar)                 \
  569         for ((var) = ((var) ? (var) : TAILQ_FIRST((head)));             \
  570             (var) && ((tvar) = TAILQ_NEXT((var), field), 1);            \
  571             (var) = (tvar))
  572 
  573 #define TAILQ_FOREACH_REVERSE(var, head, headname, field)               \
  574         for ((var) = TAILQ_LAST((head), headname);                      \
  575             (var);                                                      \
  576             (var) = TAILQ_PREV((var), headname, field))
  577 
  578 #define TAILQ_FOREACH_REVERSE_FROM(var, head, headname, field)          \
  579         for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname));    \
  580             (var);                                                      \
  581             (var) = TAILQ_PREV((var), headname, field))
  582 
  583 #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar)    \
  584         for ((var) = TAILQ_LAST((head), headname);                      \
  585             (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1);  \
  586             (var) = (tvar))
  587 
  588 #define TAILQ_FOREACH_REVERSE_FROM_SAFE(var, head, headname, field, tvar) \
  589         for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname));    \
  590             (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1);  \
  591             (var) = (tvar))
  592 
  593 #define TAILQ_INIT(head) do {                                           \
  594         TAILQ_FIRST((head)) = NULL;                                     \
  595         (head)->tqh_last = &TAILQ_FIRST((head));                        \
  596         QMD_TRACE_HEAD(head);                                           \
  597 } while (0)
  598 
  599 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do {              \
  600         QMD_TAILQ_CHECK_NEXT(listelm, field);                           \
  601         if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
  602                 TAILQ_NEXT((elm), field)->field.tqe_prev =              \
  603                     &TAILQ_NEXT((elm), field);                          \
  604         else {                                                          \
  605                 (head)->tqh_last = &TAILQ_NEXT((elm), field);           \
  606                 QMD_TRACE_HEAD(head);                                   \
  607         }                                                               \
  608         TAILQ_NEXT((listelm), field) = (elm);                           \
  609         (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field);          \
  610         QMD_TRACE_ELEM(&(elm)->field);                                  \
  611         QMD_TRACE_ELEM(&(listelm)->field);                              \
  612 } while (0)
  613 
  614 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do {                   \
  615         QMD_TAILQ_CHECK_PREV(listelm, field);                           \
  616         (elm)->field.tqe_prev = (listelm)->field.tqe_prev;              \
  617         TAILQ_NEXT((elm), field) = (listelm);                           \
  618         *(listelm)->field.tqe_prev = (elm);                             \
  619         (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field);          \
  620         QMD_TRACE_ELEM(&(elm)->field);                                  \
  621         QMD_TRACE_ELEM(&(listelm)->field);                              \
  622 } while (0)
  623 
  624 #define TAILQ_INSERT_HEAD(head, elm, field) do {                        \
  625         QMD_TAILQ_CHECK_HEAD(head, field);                              \
  626         if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL)   \
  627                 TAILQ_FIRST((head))->field.tqe_prev =                   \
  628                     &TAILQ_NEXT((elm), field);                          \
  629         else                                                            \
  630                 (head)->tqh_last = &TAILQ_NEXT((elm), field);           \
  631         TAILQ_FIRST((head)) = (elm);                                    \
  632         (elm)->field.tqe_prev = &TAILQ_FIRST((head));                   \
  633         QMD_TRACE_HEAD(head);                                           \
  634         QMD_TRACE_ELEM(&(elm)->field);                                  \
  635 } while (0)
  636 
  637 #define TAILQ_INSERT_TAIL(head, elm, field) do {                        \
  638         QMD_TAILQ_CHECK_TAIL(head, field);                              \
  639         TAILQ_NEXT((elm), field) = NULL;                                \
  640         (elm)->field.tqe_prev = (head)->tqh_last;                       \
  641         *(head)->tqh_last = (elm);                                      \
  642         (head)->tqh_last = &TAILQ_NEXT((elm), field);                   \
  643         QMD_TRACE_HEAD(head);                                           \
  644         QMD_TRACE_ELEM(&(elm)->field);                                  \
  645 } while (0)
  646 
  647 #define TAILQ_LAST(head, headname)                                      \
  648         (*(((struct headname *)((head)->tqh_last))->tqh_last))
  649 
  650 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  651 
  652 #define TAILQ_PREV(elm, headname, field)                                \
  653         (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  654 
  655 #define TAILQ_REMOVE(head, elm, field) do {                             \
  656         QMD_SAVELINK(oldnext, (elm)->field.tqe_next);                   \
  657         QMD_SAVELINK(oldprev, (elm)->field.tqe_prev);                   \
  658         QMD_TAILQ_CHECK_NEXT(elm, field);                               \
  659         QMD_TAILQ_CHECK_PREV(elm, field);                               \
  660         if ((TAILQ_NEXT((elm), field)) != NULL)                         \
  661                 TAILQ_NEXT((elm), field)->field.tqe_prev =              \
  662                     (elm)->field.tqe_prev;                              \
  663         else {                                                          \
  664                 (head)->tqh_last = (elm)->field.tqe_prev;               \
  665                 QMD_TRACE_HEAD(head);                                   \
  666         }                                                               \
  667         *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field);              \
  668         TRASHIT(*oldnext);                                              \
  669         TRASHIT(*oldprev);                                              \
  670         QMD_TRACE_ELEM(&(elm)->field);                                  \
  671 } while (0)
  672 
  673 #define TAILQ_SWAP(head1, head2, type, field) do {                      \
  674         struct type *swap_first = (head1)->tqh_first;                   \
  675         struct type **swap_last = (head1)->tqh_last;                    \
  676         (head1)->tqh_first = (head2)->tqh_first;                        \
  677         (head1)->tqh_last = (head2)->tqh_last;                          \
  678         (head2)->tqh_first = swap_first;                                \
  679         (head2)->tqh_last = swap_last;                                  \
  680         if ((swap_first = (head1)->tqh_first) != NULL)                  \
  681                 swap_first->field.tqe_prev = &(head1)->tqh_first;       \
  682         else                                                            \
  683                 (head1)->tqh_last = &(head1)->tqh_first;                \
  684         if ((swap_first = (head2)->tqh_first) != NULL)                  \
  685                 swap_first->field.tqe_prev = &(head2)->tqh_first;       \
  686         else                                                            \
  687                 (head2)->tqh_last = &(head2)->tqh_first;                \
  688 } while (0)
  689 
  690 #endif /* !_SYS_QUEUE_H_ */

Cache object: 4cc031704631b3898ef91efb0ff16c57


[ 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.