Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

queue.h

00001 /*
00002  * Copyright (c) 1991, 1993
00003  *      The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  *      This product includes software developed by the University of
00016  *      California, Berkeley and its contributors.
00017  * 4. Neither the name of the University nor the names of its contributors
00018  *    may be used to endorse or promote products derived from this software
00019  *    without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  *      @(#)queue.h     8.5 (Berkeley) 8/20/94
00034  * $FreeBSD: src/sys/sys/queue.h,v 1.56 2003/08/14 14:49:26 kan Exp $
00035  */
00036 
00037 #ifndef _SYS_QUEUE_H_
00038 #define _SYS_QUEUE_H_
00039 
00040 #include <sys/cdefs.h>
00041 
00042 /*
00043  * This file defines four types of data structures: singly-linked lists,
00044  * singly-linked tail queues, lists and tail queues.
00045  *
00046  * A singly-linked list is headed by a single forward pointer. The elements
00047  * are singly linked for minimum space and pointer manipulation overhead at
00048  * the expense of O(n) removal for arbitrary elements. New elements can be
00049  * added to the list after an existing element or at the head of the list.
00050  * Elements being removed from the head of the list should use the explicit
00051  * macro for this purpose for optimum efficiency. A singly-linked list may
00052  * only be traversed in the forward direction.  Singly-linked lists are ideal
00053  * for applications with large datasets and few or no removals or for
00054  * implementing a LIFO queue.
00055  *
00056  * A singly-linked tail queue is headed by a pair of pointers, one to the
00057  * head of the list and the other to the tail of the list. The elements are
00058  * singly linked for minimum space and pointer manipulation overhead at the
00059  * expense of O(n) removal for arbitrary elements. New elements can be added
00060  * to the list after an existing element, at the head of the list, or at the
00061  * end of the list. Elements being removed from the head of the tail queue
00062  * should use the explicit macro for this purpose for optimum efficiency.
00063  * A singly-linked tail queue may only be traversed in the forward direction.
00064  * Singly-linked tail queues are ideal for applications with large datasets
00065  * and few or no removals or for implementing a FIFO queue.
00066  *
00067  * A list is headed by a single forward pointer (or an array of forward
00068  * pointers for a hash table header). The elements are doubly linked
00069  * so that an arbitrary element can be removed without a need to
00070  * traverse the list. New elements can be added to the list before
00071  * or after an existing element or at the head of the list. A list
00072  * may only be traversed in the forward direction.
00073  *
00074  * A tail queue is headed by a pair of pointers, one to the head of the
00075  * list and the other to the tail of the list. The elements are doubly
00076  * linked so that an arbitrary element can be removed without a need to
00077  * traverse the list. New elements can be added to the list before or
00078  * after an existing element, at the head of the list, or at the end of
00079  * the list. A tail queue may be traversed in either direction.
00080  *
00081  * For details on the use of these macros, see the queue(3) manual page.
00082  *
00083  *
00084  *                              SLIST   LIST    STAILQ  TAILQ
00085  * _HEAD                        +       +       +       +
00086  * _HEAD_INITIALIZER            +       +       +       +
00087  * _ENTRY                       +       +       +       +
00088  * _INIT                        +       +       +       +
00089  * _EMPTY                       +       +       +       +
00090  * _FIRST                       +       +       +       +
00091  * _NEXT                        +       +       +       +
00092  * _PREV                        -       -       -       +
00093  * _LAST                        -       -       +       +
00094  * _FOREACH                     +       +       +       +
00095  * _FOREACH_SAFE                +       +       +       +
00096  * _FOREACH_REVERSE             -       -       -       +
00097  * _FOREACH_REVERSE_SAFE        -       -       -       +
00098  * _INSERT_HEAD                 +       +       +       +
00099  * _INSERT_BEFORE               -       +       -       +
00100  * _INSERT_AFTER                +       +       +       +
00101  * _INSERT_TAIL                 -       -       +       +
00102  * _CONCAT                      -       -       +       +
00103  * _REMOVE_HEAD                 +       -       +       -
00104  * _REMOVE                      +       +       +       +
00105  *
00106  */
00107 #define QUEUE_MACRO_DEBUG 0
00108 #if QUEUE_MACRO_DEBUG
00109 /* Store the last 2 places the queue element or head was altered */
00110 struct qm_trace {
00111         char * lastfile;
00112         int lastline;
00113         char * prevfile;
00114         int prevline;
00115 };
00116 
00117 #define TRACEBUF        struct qm_trace trace;
00118 #define TRASHIT(x)      do {(x) = (void *)-1;} while (0)
00119 
00120 #define QMD_TRACE_HEAD(head) do {                                       \
00121         (head)->trace.prevline = (head)->trace.lastline;                \
00122         (head)->trace.prevfile = (head)->trace.lastfile;                \
00123         (head)->trace.lastline = __LINE__;                              \
00124         (head)->trace.lastfile = __FILE__;                              \
00125 } while (0)
00126 
00127 #define QMD_TRACE_ELEM(elem) do {                                       \
00128         (elem)->trace.prevline = (elem)->trace.lastline;                \
00129         (elem)->trace.prevfile = (elem)->trace.lastfile;                \
00130         (elem)->trace.lastline = __LINE__;                              \
00131         (elem)->trace.lastfile = __FILE__;                              \
00132 } while (0)
00133 
00134 #else
00135 #define QMD_TRACE_ELEM(elem)
00136 #define QMD_TRACE_HEAD(head)
00137 #define TRACEBUF
00138 #define TRASHIT(x)
00139 #endif  /* QUEUE_MACRO_DEBUG */
00140 
00141 /*
00142  * Singly-linked List declarations.
00143  */
00144 #define SLIST_HEAD(name, type)                                          \
00145 struct name {                                                           \
00146         struct type *slh_first; /* first element */                     \
00147 }
00148 
00149 #define SLIST_HEAD_INITIALIZER(head)                                    \
00150         { NULL }
00151 
00152 #define SLIST_ENTRY(type)                                               \
00153 struct {                                                                \
00154         struct type *sle_next;  /* next element */                      \
00155 }
00156 
00157 /*
00158  * Singly-linked List functions.
00159  */
00160 #define SLIST_EMPTY(head)       ((head)->slh_first == NULL)
00161 
00162 #define SLIST_FIRST(head)       ((head)->slh_first)
00163 
00164 #define SLIST_FOREACH(var, head, field)                                 \
00165         for ((var) = SLIST_FIRST((head));                               \
00166             (var);                                                      \
00167             (var) = SLIST_NEXT((var), field))
00168 
00169 #define SLIST_FOREACH_SAFE(var, head, field, tvar)                      \
00170         for ((var) = SLIST_FIRST((head));                               \
00171             (var) && ((tvar) = SLIST_NEXT((var), field), 1);            \
00172             (var) = (tvar))
00173 
00174 #define SLIST_FOREACH_PREVPTR(var, varp, head, field)                   \
00175         for ((varp) = &SLIST_FIRST((head));                             \
00176             ((var) = *(varp)) != NULL;                                  \
00177             (varp) = &SLIST_NEXT((var), field))
00178 
00179 #define SLIST_INIT(head) do {                                           \
00180         SLIST_FIRST((head)) = NULL;                                     \
00181 } while (0)
00182 
00183 #define SLIST_INSERT_AFTER(slistelm, elm, field) do {                   \
00184         SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field);       \
00185         SLIST_NEXT((slistelm), field) = (elm);                          \
00186 } while (0)
00187 
00188 #define SLIST_INSERT_HEAD(head, elm, field) do {                        \
00189         SLIST_NEXT((elm), field) = SLIST_FIRST((head));                 \
00190         SLIST_FIRST((head)) = (elm);                                    \
00191 } while (0)
00192 
00193 #define SLIST_NEXT(elm, field)  ((elm)->field.sle_next)
00194 
00195 #define SLIST_REMOVE(head, elm, type, field) do {                       \
00196         if (SLIST_FIRST((head)) == (elm)) {                             \
00197                 SLIST_REMOVE_HEAD((head), field);                       \
00198         }                                                               \
00199         else {                                                          \
00200                 struct type *curelm = SLIST_FIRST((head));              \
00201                 while (SLIST_NEXT(curelm, field) != (elm))              \
00202                         curelm = SLIST_NEXT(curelm, field);             \
00203                 SLIST_NEXT(curelm, field) =                             \
00204                     SLIST_NEXT(SLIST_NEXT(curelm, field), field);       \
00205         }                                                               \
00206 } while (0)
00207 
00208 #define SLIST_REMOVE_HEAD(head, field) do {                             \
00209         SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field);   \
00210 } while (0)
00211 
00212 /*
00213  * Singly-linked Tail queue declarations.
00214  */
00215 #define STAILQ_HEAD(name, type)                                         \
00216 struct name {                                                           \
00217         struct type *stqh_first;/* first element */                     \
00218         struct type **stqh_last;/* addr of last next element */         \
00219 }
00220 
00221 #define STAILQ_HEAD_INITIALIZER(head)                                   \
00222         { NULL, &(head).stqh_first }
00223 
00224 #define STAILQ_ENTRY(type)                                              \
00225 struct {                                                                \
00226         struct type *stqe_next; /* next element */                      \
00227 }
00228 
00229 /*
00230  * Singly-linked Tail queue functions.
00231  */
00232 #define STAILQ_CONCAT(head1, head2) do {                                \
00233         if (!STAILQ_EMPTY((head2))) {                                   \
00234                 *(head1)->stqh_last = (head2)->stqh_first;              \
00235                 (head1)->stqh_last = (head2)->stqh_last;                \
00236                 STAILQ_INIT((head2));                                   \
00237         }                                                               \
00238 } while (0)
00239 
00240 #define STAILQ_EMPTY(head)      ((head)->stqh_first == NULL)
00241 
00242 #define STAILQ_FIRST(head)      ((head)->stqh_first)
00243 
00244 #define STAILQ_FOREACH(var, head, field)                                \
00245         for((var) = STAILQ_FIRST((head));                               \
00246            (var);                                                       \
00247            (var) = STAILQ_NEXT((var), field))
00248 
00249 
00250 #define STAILQ_FOREACH_SAFE(var, head, field, tvar)                     \
00251         for ((var) = STAILQ_FIRST((head));                              \
00252             (var) && ((tvar) = STAILQ_NEXT((var), field), 1);           \
00253             (var) = (tvar))
00254 
00255 #define STAILQ_INIT(head) do {                                          \
00256         STAILQ_FIRST((head)) = NULL;                                    \
00257         (head)->stqh_last = &STAILQ_FIRST((head));                      \
00258 } while (0)
00259 
00260 #define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do {               \
00261         if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
00262                 (head)->stqh_last = &STAILQ_NEXT((elm), field);         \
00263         STAILQ_NEXT((tqelm), field) = (elm);                            \
00264 } while (0)
00265 
00266 #define STAILQ_INSERT_HEAD(head, elm, field) do {                       \
00267         if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
00268                 (head)->stqh_last = &STAILQ_NEXT((elm), field);         \
00269         STAILQ_FIRST((head)) = (elm);                                   \
00270 } while (0)
00271 
00272 #define STAILQ_INSERT_TAIL(head, elm, field) do {                       \
00273         STAILQ_NEXT((elm), field) = NULL;                               \
00274         *(head)->stqh_last = (elm);                                     \
00275         (head)->stqh_last = &STAILQ_NEXT((elm), field);                 \
00276 } while (0)
00277 
00278 #define STAILQ_LAST(head, type, field)                                  \
00279         (STAILQ_EMPTY((head)) ?                                         \
00280                 NULL :                                                  \
00281                 ((struct type *)                                        \
00282                 ((char *)((head)->stqh_last) - __offsetof(struct type, field))))
00283 
00284 #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
00285 
00286 #define STAILQ_REMOVE(head, elm, type, field) do {                      \
00287         if (STAILQ_FIRST((head)) == (elm)) {                            \
00288                 STAILQ_REMOVE_HEAD((head), field);                      \
00289         }                                                               \
00290         else {                                                          \
00291                 struct type *curelm = STAILQ_FIRST((head));             \
00292                 while (STAILQ_NEXT(curelm, field) != (elm))             \
00293                         curelm = STAILQ_NEXT(curelm, field);            \
00294                 if ((STAILQ_NEXT(curelm, field) =                       \
00295                      STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\
00296                         (head)->stqh_last = &STAILQ_NEXT((curelm), field);\
00297         }                                                               \
00298 } while (0)
00299 
00300 #define STAILQ_REMOVE_HEAD(head, field) do {                            \
00301         if ((STAILQ_FIRST((head)) =                                     \
00302              STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL)         \
00303                 (head)->stqh_last = &STAILQ_FIRST((head));              \
00304 } while (0)
00305 
00306 #define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do {                 \
00307         if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \
00308                 (head)->stqh_last = &STAILQ_FIRST((head));              \
00309 } while (0)
00310 
00311 /*
00312  * List declarations.
00313  */
00314 #define LIST_HEAD(name, type)                                           \
00315 struct name {                                                           \
00316         struct type *lh_first;  /* first element */                     \
00317 }
00318 
00319 #define LIST_HEAD_INITIALIZER(head)                                     \
00320         { NULL }
00321 
00322 #define LIST_ENTRY(type)                                                \
00323 struct {                                                                \
00324         struct type *le_next;   /* next element */                      \
00325         struct type **le_prev;  /* address of previous next element */  \
00326 }
00327 
00328 /*
00329  * List functions.
00330  */
00331 
00332 #define LIST_EMPTY(head)        ((head)->lh_first == NULL)
00333 
00334 #define LIST_FIRST(head)        ((head)->lh_first)
00335 
00336 #define LIST_FOREACH(var, head, field)                                  \
00337         for ((var) = LIST_FIRST((head));                                \
00338             (var);                                                      \
00339             (var) = LIST_NEXT((var), field))
00340 
00341 #define LIST_FOREACH_SAFE(var, head, field, tvar)                       \
00342         for ((var) = LIST_FIRST((head));                                \
00343             (var) && ((tvar) = LIST_NEXT((var), field), 1);             \
00344             (var) = (tvar))
00345 
00346 #define LIST_INIT(head) do {                                            \
00347         LIST_FIRST((head)) = NULL;                                      \
00348 } while (0)
00349 
00350 #define LIST_INSERT_AFTER(listelm, elm, field) do {                     \
00351         if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
00352                 LIST_NEXT((listelm), field)->field.le_prev =            \
00353                     &LIST_NEXT((elm), field);                           \
00354         LIST_NEXT((listelm), field) = (elm);                            \
00355         (elm)->field.le_prev = &LIST_NEXT((listelm), field);            \
00356 } while (0)
00357 
00358 #define LIST_INSERT_BEFORE(listelm, elm, field) do {                    \
00359         (elm)->field.le_prev = (listelm)->field.le_prev;                \
00360         LIST_NEXT((elm), field) = (listelm);                            \
00361         *(listelm)->field.le_prev = (elm);                              \
00362         (listelm)->field.le_prev = &LIST_NEXT((elm), field);            \
00363 } while (0)
00364 
00365 #define LIST_INSERT_HEAD(head, elm, field) do {                         \
00366         if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL)     \
00367                 LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
00368         LIST_FIRST((head)) = (elm);                                     \
00369         (elm)->field.le_prev = &LIST_FIRST((head));                     \
00370 } while (0)
00371 
00372 #define LIST_NEXT(elm, field)   ((elm)->field.le_next)
00373 
00374 #define LIST_REMOVE(elm, field) do {                                    \
00375         if (LIST_NEXT((elm), field) != NULL)                            \
00376                 LIST_NEXT((elm), field)->field.le_prev =                \
00377                     (elm)->field.le_prev;                               \
00378         *(elm)->field.le_prev = LIST_NEXT((elm), field);                \
00379 } while (0)
00380 
00381 /*
00382  * Tail queue declarations.
00383  */
00384 #define TAILQ_HEAD(name, type)                                          \
00385 struct name {                                                           \
00386         struct type *tqh_first; /* first element */                     \
00387         struct type **tqh_last; /* addr of last next element */         \
00388         TRACEBUF                                                        \
00389 }
00390 
00391 #define TAILQ_HEAD_INITIALIZER(head)                                    \
00392         { NULL, &(head).tqh_first }
00393 
00394 #define TAILQ_ENTRY(type)                                               \
00395 struct {                                                                \
00396         struct type *tqe_next;  /* next element */                      \
00397         struct type **tqe_prev; /* address of previous next element */  \
00398         TRACEBUF                                                        \
00399 }
00400 
00401 /*
00402  * Tail queue functions.
00403  */
00404 #define TAILQ_CONCAT(head1, head2, field) do {                          \
00405         if (!TAILQ_EMPTY(head2)) {                                      \
00406                 *(head1)->tqh_last = (head2)->tqh_first;                \
00407                 (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
00408                 (head1)->tqh_last = (head2)->tqh_last;                  \
00409                 TAILQ_INIT((head2));                                    \
00410                 QMD_TRACE_HEAD(head);                                   \
00411                 QMD_TRACE_HEAD(head2);                                  \
00412         }                                                               \
00413 } while (0)
00414 
00415 #define TAILQ_EMPTY(head)       ((head)->tqh_first == NULL)
00416 
00417 #define TAILQ_FIRST(head)       ((head)->tqh_first)
00418 
00419 #define TAILQ_FOREACH(var, head, field)                                 \
00420         for ((var) = TAILQ_FIRST((head));                               \
00421             (var);                                                      \
00422             (var) = TAILQ_NEXT((var), field))
00423 
00424 #define TAILQ_FOREACH_SAFE(var, head, field, tvar)                      \
00425         for ((var) = TAILQ_FIRST((head));                               \
00426             (var) && ((tvar) = TAILQ_NEXT((var), field), 1);            \
00427             (var) = (tvar))
00428 
00429 #define TAILQ_FOREACH_REVERSE(var, head, headname, field)               \
00430         for ((var) = TAILQ_LAST((head), headname);                      \
00431             (var);                                                      \
00432             (var) = TAILQ_PREV((var), headname, field))
00433 
00434 #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar)    \
00435         for ((var) = TAILQ_LAST((head), headname);                      \
00436             (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1);  \
00437             (var) = (tvar))
00438 
00439 #define TAILQ_INIT(head) do {                                           \
00440         TAILQ_FIRST((head)) = NULL;                                     \
00441         (head)->tqh_last = &TAILQ_FIRST((head));                        \
00442         QMD_TRACE_HEAD(head);                                           \
00443 } while (0)
00444 
00445 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do {              \
00446         if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
00447                 TAILQ_NEXT((elm), field)->field.tqe_prev =              \
00448                     &TAILQ_NEXT((elm), field);                          \
00449         else {                                                          \
00450                 (head)->tqh_last = &TAILQ_NEXT((elm), field);           \
00451                 QMD_TRACE_HEAD(head);                                   \
00452         }                                                               \
00453         TAILQ_NEXT((listelm), field) = (elm);                           \
00454         (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field);          \
00455         QMD_TRACE_ELEM(&(elm)->field);                                  \
00456         QMD_TRACE_ELEM(&listelm->field);                                \
00457 } while (0)
00458 
00459 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do {                   \
00460         (elm)->field.tqe_prev = (listelm)->field.tqe_prev;              \
00461         TAILQ_NEXT((elm), field) = (listelm);                           \
00462         *(listelm)->field.tqe_prev = (elm);                             \
00463         (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field);          \
00464         QMD_TRACE_ELEM(&(elm)->field);                                  \
00465         QMD_TRACE_ELEM(&listelm->field);                                \
00466 } while (0)
00467 
00468 #define TAILQ_INSERT_HEAD(head, elm, field) do {                        \
00469         if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL)   \
00470                 TAILQ_FIRST((head))->field.tqe_prev =                   \
00471                     &TAILQ_NEXT((elm), field);                          \
00472         else                                                            \
00473                 (head)->tqh_last = &TAILQ_NEXT((elm), field);           \
00474         TAILQ_FIRST((head)) = (elm);                                    \
00475         (elm)->field.tqe_prev = &TAILQ_FIRST((head));                   \
00476         QMD_TRACE_HEAD(head);                                           \
00477         QMD_TRACE_ELEM(&(elm)->field);                                  \
00478 } while (0)
00479 
00480 #define TAILQ_INSERT_TAIL(head, elm, field) do {                        \
00481         TAILQ_NEXT((elm), field) = NULL;                                \
00482         (elm)->field.tqe_prev = (head)->tqh_last;                       \
00483         *(head)->tqh_last = (elm);                                      \
00484         (head)->tqh_last = &TAILQ_NEXT((elm), field);                   \
00485         QMD_TRACE_HEAD(head);                                           \
00486         QMD_TRACE_ELEM(&(elm)->field);                                  \
00487 } while (0)
00488 
00489 #define TAILQ_LAST(head, headname)                                      \
00490         (*(((struct headname *)((head)->tqh_last))->tqh_last))
00491 
00492 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
00493 
00494 #define TAILQ_PREV(elm, headname, field)                                \
00495         (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
00496 
00497 #define TAILQ_REMOVE(head, elm, field) do {                             \
00498         if ((TAILQ_NEXT((elm), field)) != NULL)                         \
00499                 TAILQ_NEXT((elm), field)->field.tqe_prev =              \
00500                     (elm)->field.tqe_prev;                              \
00501         else {                                                          \
00502                 (head)->tqh_last = (elm)->field.tqe_prev;               \
00503                 QMD_TRACE_HEAD(head);                                   \
00504         }                                                               \
00505         *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field);              \
00506         TRASHIT((elm)->field.tqe_next);                                 \
00507         TRASHIT((elm)->field.tqe_prev);                                 \
00508         QMD_TRACE_ELEM(&(elm)->field);                                  \
00509 } while (0)
00510 
00511 
00512 #ifdef _KERNEL
00513 
00514 /*
00515  * XXX insque() and remque() are an old way of handling certain queues.
00516  * They bogusly assumes that all queue heads look alike.
00517  */
00518 
00519 struct quehead {
00520         struct quehead *qh_link;
00521         struct quehead *qh_rlink;
00522 };
00523 
00524 #ifdef  __GNUC__
00525 
00526 static __inline void
00527 insque(void *a, void *b)
00528 {
00529         struct quehead *element = (struct quehead *)a,
00530                  *head = (struct quehead *)b;
00531 
00532         element->qh_link = head->qh_link;
00533         element->qh_rlink = head;
00534         head->qh_link = element;
00535         element->qh_link->qh_rlink = element;
00536 }
00537 
00538 static __inline void
00539 remque(void *a)
00540 {
00541         struct quehead *element = (struct quehead *)a;
00542 
00543         element->qh_link->qh_rlink = element->qh_rlink;
00544         element->qh_rlink->qh_link = element->qh_link;
00545         element->qh_rlink = 0;
00546 }
00547 
00548 #else /* !__GNUC__ */
00549 
00550 void    insque(void *a, void *b);
00551 void    remque(void *a);
00552 
00553 #endif /* __GNUC__ */
00554 
00555 #endif /* _KERNEL */
00556 
00557 #endif /* !_SYS_QUEUE_H_ */