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/9.2/sys/sys/queue.h 252365 2013-06-29 04:25:40Z lstewart $
   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 be traversed in either 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)) ? NULL :                                  \
  314             __containerof((head)->stqh_last, struct type, field.stqe_next))
  315 
  316 #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
  317 
  318 #define STAILQ_REMOVE(head, elm, type, field) do {                      \
  319         QMD_SAVELINK(oldnext, (elm)->field.stqe_next);                  \
  320         if (STAILQ_FIRST((head)) == (elm)) {                            \
  321                 STAILQ_REMOVE_HEAD((head), field);                      \
  322         }                                                               \
  323         else {                                                          \
  324                 struct type *curelm = STAILQ_FIRST((head));             \
  325                 while (STAILQ_NEXT(curelm, field) != (elm))             \
  326                         curelm = STAILQ_NEXT(curelm, field);            \
  327                 STAILQ_REMOVE_AFTER(head, curelm, field);               \
  328         }                                                               \
  329         TRASHIT(*oldnext);                                              \
  330 } while (0)
  331 
  332 #define STAILQ_REMOVE_AFTER(head, elm, field) do {                      \
  333         if ((STAILQ_NEXT(elm, field) =                                  \
  334              STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL)      \
  335                 (head)->stqh_last = &STAILQ_NEXT((elm), field);         \
  336 } while (0)
  337 
  338 #define STAILQ_REMOVE_HEAD(head, field) do {                            \
  339         if ((STAILQ_FIRST((head)) =                                     \
  340              STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL)         \
  341                 (head)->stqh_last = &STAILQ_FIRST((head));              \
  342 } while (0)
  343 
  344 #define STAILQ_SWAP(head1, head2, type) do {                            \
  345         struct type *swap_first = STAILQ_FIRST(head1);                  \
  346         struct type **swap_last = (head1)->stqh_last;                   \
  347         STAILQ_FIRST(head1) = STAILQ_FIRST(head2);                      \
  348         (head1)->stqh_last = (head2)->stqh_last;                        \
  349         STAILQ_FIRST(head2) = swap_first;                               \
  350         (head2)->stqh_last = swap_last;                                 \
  351         if (STAILQ_EMPTY(head1))                                        \
  352                 (head1)->stqh_last = &STAILQ_FIRST(head1);              \
  353         if (STAILQ_EMPTY(head2))                                        \
  354                 (head2)->stqh_last = &STAILQ_FIRST(head2);              \
  355 } while (0)
  356 
  357 
  358 /*
  359  * List declarations.
  360  */
  361 #define LIST_HEAD(name, type)                                           \
  362 struct name {                                                           \
  363         struct type *lh_first;  /* first element */                     \
  364 }
  365 
  366 #define LIST_HEAD_INITIALIZER(head)                                     \
  367         { NULL }
  368 
  369 #define LIST_ENTRY(type)                                                \
  370 struct {                                                                \
  371         struct type *le_next;   /* next element */                      \
  372         struct type **le_prev;  /* address of previous next element */  \
  373 }
  374 
  375 /*
  376  * List functions.
  377  */
  378 
  379 #if (defined(_KERNEL) && defined(INVARIANTS))
  380 #define QMD_LIST_CHECK_HEAD(head, field) do {                           \
  381         if (LIST_FIRST((head)) != NULL &&                               \
  382             LIST_FIRST((head))->field.le_prev !=                        \
  383              &LIST_FIRST((head)))                                       \
  384                 panic("Bad list head %p first->prev != head", (head));  \
  385 } while (0)
  386 
  387 #define QMD_LIST_CHECK_NEXT(elm, field) do {                            \
  388         if (LIST_NEXT((elm), field) != NULL &&                          \
  389             LIST_NEXT((elm), field)->field.le_prev !=                   \
  390              &((elm)->field.le_next))                                   \
  391                 panic("Bad link elm %p next->prev != elm", (elm));      \
  392 } while (0)
  393 
  394 #define QMD_LIST_CHECK_PREV(elm, field) do {                            \
  395         if (*(elm)->field.le_prev != (elm))                             \
  396                 panic("Bad link elm %p prev->next != elm", (elm));      \
  397 } while (0)
  398 #else
  399 #define QMD_LIST_CHECK_HEAD(head, field)
  400 #define QMD_LIST_CHECK_NEXT(elm, field)
  401 #define QMD_LIST_CHECK_PREV(elm, field)
  402 #endif /* (_KERNEL && INVARIANTS) */
  403 
  404 #define LIST_EMPTY(head)        ((head)->lh_first == NULL)
  405 
  406 #define LIST_FIRST(head)        ((head)->lh_first)
  407 
  408 #define LIST_FOREACH(var, head, field)                                  \
  409         for ((var) = LIST_FIRST((head));                                \
  410             (var);                                                      \
  411             (var) = LIST_NEXT((var), field))
  412 
  413 #define LIST_FOREACH_FROM(var, head, field)                             \
  414         for ((var) = ((var) ? (var) : LIST_FIRST((head)));              \
  415             (var);                                                      \
  416             (var) = LIST_NEXT((var), field))
  417 
  418 #define LIST_FOREACH_SAFE(var, head, field, tvar)                       \
  419         for ((var) = LIST_FIRST((head));                                \
  420             (var) && ((tvar) = LIST_NEXT((var), field), 1);             \
  421             (var) = (tvar))
  422 
  423 #define LIST_FOREACH_FROM_SAFE(var, head, field, tvar)                  \
  424         for ((var) = ((var) ? (var) : LIST_FIRST((head)));              \
  425             (var) && ((tvar) = LIST_NEXT((var), field), 1);             \
  426             (var) = (tvar))
  427 
  428 #define LIST_INIT(head) do {                                            \
  429         LIST_FIRST((head)) = NULL;                                      \
  430 } while (0)
  431 
  432 #define LIST_INSERT_AFTER(listelm, elm, field) do {                     \
  433         QMD_LIST_CHECK_NEXT(listelm, field);                            \
  434         if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
  435                 LIST_NEXT((listelm), field)->field.le_prev =            \
  436                     &LIST_NEXT((elm), field);                           \
  437         LIST_NEXT((listelm), field) = (elm);                            \
  438         (elm)->field.le_prev = &LIST_NEXT((listelm), field);            \
  439 } while (0)
  440 
  441 #define LIST_INSERT_BEFORE(listelm, elm, field) do {                    \
  442         QMD_LIST_CHECK_PREV(listelm, field);                            \
  443         (elm)->field.le_prev = (listelm)->field.le_prev;                \
  444         LIST_NEXT((elm), field) = (listelm);                            \
  445         *(listelm)->field.le_prev = (elm);                              \
  446         (listelm)->field.le_prev = &LIST_NEXT((elm), field);            \
  447 } while (0)
  448 
  449 #define LIST_INSERT_HEAD(head, elm, field) do {                         \
  450         QMD_LIST_CHECK_HEAD((head), field);                             \
  451         if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL)     \
  452                 LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
  453         LIST_FIRST((head)) = (elm);                                     \
  454         (elm)->field.le_prev = &LIST_FIRST((head));                     \
  455 } while (0)
  456 
  457 #define LIST_NEXT(elm, field)   ((elm)->field.le_next)
  458 
  459 #define LIST_PREV(elm, head, type, field)                               \
  460         ((elm)->field.le_prev == &LIST_FIRST((head)) ? NULL :           \
  461             __containerof((elm)->field.le_prev, struct type, field.le_next))
  462 
  463 #define LIST_REMOVE(elm, field) do {                                    \
  464         QMD_SAVELINK(oldnext, (elm)->field.le_next);                    \
  465         QMD_SAVELINK(oldprev, (elm)->field.le_prev);                    \
  466         QMD_LIST_CHECK_NEXT(elm, field);                                \
  467         QMD_LIST_CHECK_PREV(elm, field);                                \
  468         if (LIST_NEXT((elm), field) != NULL)                            \
  469                 LIST_NEXT((elm), field)->field.le_prev =                \
  470                     (elm)->field.le_prev;                               \
  471         *(elm)->field.le_prev = LIST_NEXT((elm), field);                \
  472         TRASHIT(*oldnext);                                              \
  473         TRASHIT(*oldprev);                                              \
  474 } while (0)
  475 
  476 #define LIST_SWAP(head1, head2, type, field) do {                       \
  477         struct type *swap_tmp = LIST_FIRST((head1));                    \
  478         LIST_FIRST((head1)) = LIST_FIRST((head2));                      \
  479         LIST_FIRST((head2)) = swap_tmp;                                 \
  480         if ((swap_tmp = LIST_FIRST((head1))) != NULL)                   \
  481                 swap_tmp->field.le_prev = &LIST_FIRST((head1));         \
  482         if ((swap_tmp = LIST_FIRST((head2))) != NULL)                   \
  483                 swap_tmp->field.le_prev = &LIST_FIRST((head2));         \
  484 } while (0)
  485 
  486 /*
  487  * Tail queue declarations.
  488  */
  489 #define TAILQ_HEAD(name, type)                                          \
  490 struct name {                                                           \
  491         struct type *tqh_first; /* first element */                     \
  492         struct type **tqh_last; /* addr of last next element */         \
  493         TRACEBUF                                                        \
  494 }
  495 
  496 #define TAILQ_HEAD_INITIALIZER(head)                                    \
  497         { NULL, &(head).tqh_first }
  498 
  499 #define TAILQ_ENTRY(type)                                               \
  500 struct {                                                                \
  501         struct type *tqe_next;  /* next element */                      \
  502         struct type **tqe_prev; /* address of previous next element */  \
  503         TRACEBUF                                                        \
  504 }
  505 
  506 /*
  507  * Tail queue functions.
  508  */
  509 #if (defined(_KERNEL) && defined(INVARIANTS))
  510 #define QMD_TAILQ_CHECK_HEAD(head, field) do {                          \
  511         if (!TAILQ_EMPTY(head) &&                                       \
  512             TAILQ_FIRST((head))->field.tqe_prev !=                      \
  513              &TAILQ_FIRST((head)))                                      \
  514                 panic("Bad tailq head %p first->prev != head", (head)); \
  515 } while (0)
  516 
  517 #define QMD_TAILQ_CHECK_TAIL(head, field) do {                          \
  518         if (*(head)->tqh_last != NULL)                                  \
  519                 panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head));  \
  520 } while (0)
  521 
  522 #define QMD_TAILQ_CHECK_NEXT(elm, field) do {                           \
  523         if (TAILQ_NEXT((elm), field) != NULL &&                         \
  524             TAILQ_NEXT((elm), field)->field.tqe_prev !=                 \
  525              &((elm)->field.tqe_next))                                  \
  526                 panic("Bad link elm %p next->prev != elm", (elm));      \
  527 } while (0)
  528 
  529 #define QMD_TAILQ_CHECK_PREV(elm, field) do {                           \
  530         if (*(elm)->field.tqe_prev != (elm))                            \
  531                 panic("Bad link elm %p prev->next != elm", (elm));      \
  532 } while (0)
  533 #else
  534 #define QMD_TAILQ_CHECK_HEAD(head, field)
  535 #define QMD_TAILQ_CHECK_TAIL(head, headname)
  536 #define QMD_TAILQ_CHECK_NEXT(elm, field)
  537 #define QMD_TAILQ_CHECK_PREV(elm, field)
  538 #endif /* (_KERNEL && INVARIANTS) */
  539 
  540 #define TAILQ_CONCAT(head1, head2, field) do {                          \
  541         if (!TAILQ_EMPTY(head2)) {                                      \
  542                 *(head1)->tqh_last = (head2)->tqh_first;                \
  543                 (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
  544                 (head1)->tqh_last = (head2)->tqh_last;                  \
  545                 TAILQ_INIT((head2));                                    \
  546                 QMD_TRACE_HEAD(head1);                                  \
  547                 QMD_TRACE_HEAD(head2);                                  \
  548         }                                                               \
  549 } while (0)
  550 
  551 #define TAILQ_EMPTY(head)       ((head)->tqh_first == NULL)
  552 
  553 #define TAILQ_FIRST(head)       ((head)->tqh_first)
  554 
  555 #define TAILQ_FOREACH(var, head, field)                                 \
  556         for ((var) = TAILQ_FIRST((head));                               \
  557             (var);                                                      \
  558             (var) = TAILQ_NEXT((var), field))
  559 
  560 #define TAILQ_FOREACH_FROM(var, head, field)                            \
  561         for ((var) = ((var) ? (var) : TAILQ_FIRST((head)));             \
  562             (var);                                                      \
  563             (var) = TAILQ_NEXT((var), field))
  564 
  565 #define TAILQ_FOREACH_SAFE(var, head, field, tvar)                      \
  566         for ((var) = TAILQ_FIRST((head));                               \
  567             (var) && ((tvar) = TAILQ_NEXT((var), field), 1);            \
  568             (var) = (tvar))
  569 
  570 #define TAILQ_FOREACH_FROM_SAFE(var, head, field, tvar)                 \
  571         for ((var) = ((var) ? (var) : TAILQ_FIRST((head)));             \
  572             (var) && ((tvar) = TAILQ_NEXT((var), field), 1);            \
  573             (var) = (tvar))
  574 
  575 #define TAILQ_FOREACH_REVERSE(var, head, headname, field)               \
  576         for ((var) = TAILQ_LAST((head), headname);                      \
  577             (var);                                                      \
  578             (var) = TAILQ_PREV((var), headname, field))
  579 
  580 #define TAILQ_FOREACH_REVERSE_FROM(var, head, headname, field)          \
  581         for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname));    \
  582             (var);                                                      \
  583             (var) = TAILQ_PREV((var), headname, field))
  584 
  585 #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar)    \
  586         for ((var) = TAILQ_LAST((head), headname);                      \
  587             (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1);  \
  588             (var) = (tvar))
  589 
  590 #define TAILQ_FOREACH_REVERSE_FROM_SAFE(var, head, headname, field, tvar) \
  591         for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname));    \
  592             (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1);  \
  593             (var) = (tvar))
  594 
  595 #define TAILQ_INIT(head) do {                                           \
  596         TAILQ_FIRST((head)) = NULL;                                     \
  597         (head)->tqh_last = &TAILQ_FIRST((head));                        \
  598         QMD_TRACE_HEAD(head);                                           \
  599 } while (0)
  600 
  601 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do {              \
  602         QMD_TAILQ_CHECK_NEXT(listelm, field);                           \
  603         if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
  604                 TAILQ_NEXT((elm), field)->field.tqe_prev =              \
  605                     &TAILQ_NEXT((elm), field);                          \
  606         else {                                                          \
  607                 (head)->tqh_last = &TAILQ_NEXT((elm), field);           \
  608                 QMD_TRACE_HEAD(head);                                   \
  609         }                                                               \
  610         TAILQ_NEXT((listelm), field) = (elm);                           \
  611         (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field);          \
  612         QMD_TRACE_ELEM(&(elm)->field);                                  \
  613         QMD_TRACE_ELEM(&listelm->field);                                \
  614 } while (0)
  615 
  616 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do {                   \
  617         QMD_TAILQ_CHECK_PREV(listelm, field);                           \
  618         (elm)->field.tqe_prev = (listelm)->field.tqe_prev;              \
  619         TAILQ_NEXT((elm), field) = (listelm);                           \
  620         *(listelm)->field.tqe_prev = (elm);                             \
  621         (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field);          \
  622         QMD_TRACE_ELEM(&(elm)->field);                                  \
  623         QMD_TRACE_ELEM(&listelm->field);                                \
  624 } while (0)
  625 
  626 #define TAILQ_INSERT_HEAD(head, elm, field) do {                        \
  627         QMD_TAILQ_CHECK_HEAD(head, field);                              \
  628         if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL)   \
  629                 TAILQ_FIRST((head))->field.tqe_prev =                   \
  630                     &TAILQ_NEXT((elm), field);                          \
  631         else                                                            \
  632                 (head)->tqh_last = &TAILQ_NEXT((elm), field);           \
  633         TAILQ_FIRST((head)) = (elm);                                    \
  634         (elm)->field.tqe_prev = &TAILQ_FIRST((head));                   \
  635         QMD_TRACE_HEAD(head);                                           \
  636         QMD_TRACE_ELEM(&(elm)->field);                                  \
  637 } while (0)
  638 
  639 #define TAILQ_INSERT_TAIL(head, elm, field) do {                        \
  640         QMD_TAILQ_CHECK_TAIL(head, field);                              \
  641         TAILQ_NEXT((elm), field) = NULL;                                \
  642         (elm)->field.tqe_prev = (head)->tqh_last;                       \
  643         *(head)->tqh_last = (elm);                                      \
  644         (head)->tqh_last = &TAILQ_NEXT((elm), field);                   \
  645         QMD_TRACE_HEAD(head);                                           \
  646         QMD_TRACE_ELEM(&(elm)->field);                                  \
  647 } while (0)
  648 
  649 #define TAILQ_LAST(head, headname)                                      \
  650         (*(((struct headname *)((head)->tqh_last))->tqh_last))
  651 
  652 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  653 
  654 #define TAILQ_PREV(elm, headname, field)                                \
  655         (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  656 
  657 #define TAILQ_REMOVE(head, elm, field) do {                             \
  658         QMD_SAVELINK(oldnext, (elm)->field.tqe_next);                   \
  659         QMD_SAVELINK(oldprev, (elm)->field.tqe_prev);                   \
  660         QMD_TAILQ_CHECK_NEXT(elm, field);                               \
  661         QMD_TAILQ_CHECK_PREV(elm, field);                               \
  662         if ((TAILQ_NEXT((elm), field)) != NULL)                         \
  663                 TAILQ_NEXT((elm), field)->field.tqe_prev =              \
  664                     (elm)->field.tqe_prev;                              \
  665         else {                                                          \
  666                 (head)->tqh_last = (elm)->field.tqe_prev;               \
  667                 QMD_TRACE_HEAD(head);                                   \
  668         }                                                               \
  669         *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field);              \
  670         TRASHIT(*oldnext);                                              \
  671         TRASHIT(*oldprev);                                              \
  672         QMD_TRACE_ELEM(&(elm)->field);                                  \
  673 } while (0)
  674 
  675 #define TAILQ_SWAP(head1, head2, type, field) do {                      \
  676         struct type *swap_first = (head1)->tqh_first;                   \
  677         struct type **swap_last = (head1)->tqh_last;                    \
  678         (head1)->tqh_first = (head2)->tqh_first;                        \
  679         (head1)->tqh_last = (head2)->tqh_last;                          \
  680         (head2)->tqh_first = swap_first;                                \
  681         (head2)->tqh_last = swap_last;                                  \
  682         if ((swap_first = (head1)->tqh_first) != NULL)                  \
  683                 swap_first->field.tqe_prev = &(head1)->tqh_first;       \
  684         else                                                            \
  685                 (head1)->tqh_last = &(head1)->tqh_first;                \
  686         if ((swap_first = (head2)->tqh_first) != NULL)                  \
  687                 swap_first->field.tqe_prev = &(head2)->tqh_first;       \
  688         else                                                            \
  689                 (head2)->tqh_last = &(head2)->tqh_first;                \
  690 } while (0)
  691 
  692 #endif /* !_SYS_QUEUE_H_ */

Cache object: 0051420034ba4dc7f8299026917c325e


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