queue.h

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

Copyright © Nokia Corporation 2001-2008
Back to top