i3

include/queue.h

Go to the documentation of this file.
00001 /*      $OpenBSD: queue.h,v 1.1 2007/10/26 03:14:08 niallo Exp $        */
00002 /*      $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $       */
00003 
00004 /*
00005  * Copyright (c) 1991, 1993
00006  *      The Regents of the University of California.  All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. Neither the name of the University nor the names of its contributors
00017  *    may be used to endorse or promote products derived from this software
00018  *    without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00021  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00024  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00025  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00026  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00027  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00028  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00029  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00030  * SUCH DAMAGE.
00031  *
00032  *      @(#)queue.h     8.5 (Berkeley) 8/20/94
00033  */
00034 
00035 #ifndef _SYS_QUEUE_H_
00036 #define _SYS_QUEUE_H_
00037 
00038 /*
00039  * This file defines five types of data structures: singly-linked lists,
00040  * lists, simple queues, tail queues, and circular queues.
00041  *
00042  *
00043  * A singly-linked list is headed by a single forward pointer. The elements
00044  * are singly linked for minimum space and pointer manipulation overhead at
00045  * the expense of O(n) removal for arbitrary elements. New elements can be
00046  * added to the list after an existing element or at the head of the list.
00047  * Elements being removed from the head of the list should use the explicit
00048  * macro for this purpose for optimum efficiency. A singly-linked list may
00049  * only be traversed in the forward direction.  Singly-linked lists are ideal
00050  * for applications with large datasets and few or no removals or for
00051  * implementing a LIFO queue.
00052  *
00053  * A list is headed by a single forward pointer (or an array of forward
00054  * pointers for a hash table header). The elements are doubly linked
00055  * so that an arbitrary element can be removed without a need to
00056  * traverse the list. New elements can be added to the list before
00057  * or after an existing element or at the head of the list. A list
00058  * may only be traversed in the forward direction.
00059  *
00060  * A simple queue is headed by a pair of pointers, one the head of the
00061  * list and the other to the tail of the list. The elements are singly
00062  * linked to save space, so elements can only be removed from the
00063  * head of the list. New elements can be added to the list before or after
00064  * an existing element, at the head of the list, or at the end of the
00065  * list. A simple queue may only be traversed in the forward direction.
00066  *
00067  * A tail queue is headed by a pair of pointers, one to the head of the
00068  * list and the other to the tail of the list. The elements are doubly
00069  * linked 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 or
00071  * after an existing element, at the head of the list, or at the end of
00072  * the list. A tail queue may be traversed in either direction.
00073  *
00074  * A circle 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 after
00078  * an existing element, at the head of the list, or at the end of the list.
00079  * A circle queue may be traversed in either direction, but has a more
00080  * complex end of list detection.
00081  *
00082  * For details on the use of these macros, see the queue(3) manual page.
00083  */
00084 
00085 #if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC))
00086 #define _Q_INVALIDATE(a) (a) = ((void *)-1)
00087 #else
00088 #define _Q_INVALIDATE(a)
00089 #endif
00090 
00091 /*
00092  * Singly-linked List definitions.
00093  */
00094 #define SLIST_HEAD(name, type)                                          \
00095 struct name {                                                           \
00096         struct type *slh_first; /* first element */                     \
00097 }
00098 
00099 #define SLIST_HEAD_INITIALIZER(head)                                    \
00100         { NULL }
00101 
00102 #define SLIST_ENTRY(type)                                               \
00103 struct {                                                                \
00104         struct type *sle_next;  /* next element */                      \
00105 }
00106 
00107 /*
00108  * Singly-linked List access methods.
00109  */
00110 #define SLIST_FIRST(head)       ((head)->slh_first)
00111 #define SLIST_END(head)         NULL
00112 #define SLIST_EMPTY(head)       (SLIST_FIRST(head) == SLIST_END(head))
00113 #define SLIST_NEXT(elm, field)  ((elm)->field.sle_next)
00114 
00115 #define SLIST_FOREACH(var, head, field)                                 \
00116         for((var) = SLIST_FIRST(head);                                  \
00117             (var) != SLIST_END(head);                                   \
00118             (var) = SLIST_NEXT(var, field))
00119 
00120 #define SLIST_FOREACH_PREVPTR(var, varp, head, field)                   \
00121         for ((varp) = &SLIST_FIRST((head));                             \
00122             ((var) = *(varp)) != SLIST_END(head);                       \
00123             (varp) = &SLIST_NEXT((var), field))
00124 
00125 /*
00126  * Singly-linked List functions.
00127  */
00128 #define SLIST_INIT(head) {                                              \
00129         SLIST_FIRST(head) = SLIST_END(head);                            \
00130 }
00131 
00132 #define SLIST_INSERT_AFTER(slistelm, elm, field) do {                   \
00133         (elm)->field.sle_next = (slistelm)->field.sle_next;             \
00134         (slistelm)->field.sle_next = (elm);                             \
00135 } while (0)
00136 
00137 #define SLIST_INSERT_HEAD(head, elm, field) do {                        \
00138         (elm)->field.sle_next = (head)->slh_first;                      \
00139         (head)->slh_first = (elm);                                      \
00140 } while (0)
00141 
00142 #define SLIST_REMOVE_NEXT(head, elm, field) do {                        \
00143         (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next;  \
00144 } while (0)
00145 
00146 #define SLIST_REMOVE_HEAD(head, field) do {                             \
00147         (head)->slh_first = (head)->slh_first->field.sle_next;          \
00148 } while (0)
00149 
00150 #define SLIST_REMOVE(head, elm, type, field) do {                       \
00151         if ((head)->slh_first == (elm)) {                               \
00152                 SLIST_REMOVE_HEAD((head), field);                       \
00153         } else {                                                        \
00154                 struct type *curelm = (head)->slh_first;                \
00155                                                                         \
00156                 while (curelm->field.sle_next != (elm))                 \
00157                         curelm = curelm->field.sle_next;                \
00158                 curelm->field.sle_next =                                \
00159                     curelm->field.sle_next->field.sle_next;             \
00160                 _Q_INVALIDATE((elm)->field.sle_next);                   \
00161         }                                                               \
00162 } while (0)
00163 
00164 /*
00165  * List definitions.
00166  */
00167 #define LIST_HEAD(name, type)                                           \
00168 struct name {                                                           \
00169         struct type *lh_first;  /* first element */                     \
00170 }
00171 
00172 #define LIST_HEAD_INITIALIZER(head)                                     \
00173         { NULL }
00174 
00175 #define LIST_ENTRY(type)                                                \
00176 struct {                                                                \
00177         struct type *le_next;   /* next element */                      \
00178         struct type **le_prev;  /* address of previous next element */  \
00179 }
00180 
00181 /*
00182  * List access methods
00183  */
00184 #define LIST_FIRST(head)                ((head)->lh_first)
00185 #define LIST_END(head)                  NULL
00186 #define LIST_EMPTY(head)                (LIST_FIRST(head) == LIST_END(head))
00187 #define LIST_NEXT(elm, field)           ((elm)->field.le_next)
00188 
00189 #define LIST_FOREACH(var, head, field)                                  \
00190         for((var) = LIST_FIRST(head);                                   \
00191             (var)!= LIST_END(head);                                     \
00192             (var) = LIST_NEXT(var, field))
00193 
00194 /*
00195  * List functions.
00196  */
00197 #define LIST_INIT(head) do {                                            \
00198         LIST_FIRST(head) = LIST_END(head);                              \
00199 } while (0)
00200 
00201 #define LIST_INSERT_AFTER(listelm, elm, field) do {                     \
00202         if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)  \
00203                 (listelm)->field.le_next->field.le_prev =               \
00204                     &(elm)->field.le_next;                              \
00205         (listelm)->field.le_next = (elm);                               \
00206         (elm)->field.le_prev = &(listelm)->field.le_next;               \
00207 } while (0)
00208 
00209 #define LIST_INSERT_BEFORE(listelm, elm, field) do {                    \
00210         (elm)->field.le_prev = (listelm)->field.le_prev;                \
00211         (elm)->field.le_next = (listelm);                               \
00212         *(listelm)->field.le_prev = (elm);                              \
00213         (listelm)->field.le_prev = &(elm)->field.le_next;               \
00214 } while (0)
00215 
00216 #define LIST_INSERT_HEAD(head, elm, field) do {                         \
00217         if (((elm)->field.le_next = (head)->lh_first) != NULL)          \
00218                 (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
00219         (head)->lh_first = (elm);                                       \
00220         (elm)->field.le_prev = &(head)->lh_first;                       \
00221 } while (0)
00222 
00223 #define LIST_REMOVE(elm, field) do {                                    \
00224         if ((elm)->field.le_next != NULL)                               \
00225                 (elm)->field.le_next->field.le_prev =                   \
00226                     (elm)->field.le_prev;                               \
00227         *(elm)->field.le_prev = (elm)->field.le_next;                   \
00228         _Q_INVALIDATE((elm)->field.le_prev);                            \
00229         _Q_INVALIDATE((elm)->field.le_next);                            \
00230 } while (0)
00231 
00232 #define LIST_REPLACE(elm, elm2, field) do {                             \
00233         if (((elm2)->field.le_next = (elm)->field.le_next) != NULL)     \
00234                 (elm2)->field.le_next->field.le_prev =                  \
00235                     &(elm2)->field.le_next;                             \
00236         (elm2)->field.le_prev = (elm)->field.le_prev;                   \
00237         *(elm2)->field.le_prev = (elm2);                                \
00238         _Q_INVALIDATE((elm)->field.le_prev);                            \
00239         _Q_INVALIDATE((elm)->field.le_next);                            \
00240 } while (0)
00241 
00242 /*
00243  * Simple queue definitions.
00244  */
00245 #define SIMPLEQ_HEAD(name, type)                                        \
00246 struct name {                                                           \
00247         struct type *sqh_first; /* first element */                     \
00248         struct type **sqh_last; /* addr of last next element */         \
00249 }
00250 
00251 #define SIMPLEQ_HEAD_INITIALIZER(head)                                  \
00252         { NULL, &(head).sqh_first }
00253 
00254 #define SIMPLEQ_ENTRY(type)                                             \
00255 struct {                                                                \
00256         struct type *sqe_next;  /* next element */                      \
00257 }
00258 
00259 /*
00260  * Simple queue access methods.
00261  */
00262 #define SIMPLEQ_FIRST(head)         ((head)->sqh_first)
00263 #define SIMPLEQ_END(head)           NULL
00264 #define SIMPLEQ_EMPTY(head)         (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
00265 #define SIMPLEQ_NEXT(elm, field)    ((elm)->field.sqe_next)
00266 
00267 #define SIMPLEQ_FOREACH(var, head, field)                               \
00268         for((var) = SIMPLEQ_FIRST(head);                                \
00269             (var) != SIMPLEQ_END(head);                                 \
00270             (var) = SIMPLEQ_NEXT(var, field))
00271 
00272 /*
00273  * Simple queue functions.
00274  */
00275 #define SIMPLEQ_INIT(head) do {                                         \
00276         (head)->sqh_first = NULL;                                       \
00277         (head)->sqh_last = &(head)->sqh_first;                          \
00278 } while (0)
00279 
00280 #define SIMPLEQ_INSERT_HEAD(head, elm, field) do {                      \
00281         if (((elm)->field.sqe_next = (head)->sqh_first) == NULL)        \
00282                 (head)->sqh_last = &(elm)->field.sqe_next;              \
00283         (head)->sqh_first = (elm);                                      \
00284 } while (0)
00285 
00286 #define SIMPLEQ_INSERT_TAIL(head, elm, field) do {                      \
00287         (elm)->field.sqe_next = NULL;                                   \
00288         *(head)->sqh_last = (elm);                                      \
00289         (head)->sqh_last = &(elm)->field.sqe_next;                      \
00290 } while (0)
00291 
00292 #define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do {            \
00293         if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
00294                 (head)->sqh_last = &(elm)->field.sqe_next;              \
00295         (listelm)->field.sqe_next = (elm);                              \
00296 } while (0)
00297 
00298 #define SIMPLEQ_REMOVE_HEAD(head, field) do {                   \
00299         if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
00300                 (head)->sqh_last = &(head)->sqh_first;                  \
00301 } while (0)
00302 
00303 /*
00304  * Tail queue definitions.
00305  */
00306 #define TAILQ_HEAD(name, type)                                          \
00307 struct name {                                                           \
00308         struct type *tqh_first; /* first element */                     \
00309         struct type **tqh_last; /* addr of last next element */         \
00310 }
00311 
00312 #define TAILQ_HEAD_INITIALIZER(head)                                    \
00313         { NULL, &(head).tqh_first }
00314 
00315 #define TAILQ_ENTRY(type)                                               \
00316 struct {                                                                \
00317         struct type *tqe_next;  /* next element */                      \
00318         struct type **tqe_prev; /* address of previous next element */  \
00319 }
00320 
00321 /*
00322  * tail queue access methods
00323  */
00324 #define TAILQ_FIRST(head)               ((head)->tqh_first)
00325 #define TAILQ_END(head)                 NULL
00326 #define TAILQ_NEXT(elm, field)          ((elm)->field.tqe_next)
00327 #define TAILQ_LAST(head, headname)                                      \
00328         (*(((struct headname *)((head)->tqh_last))->tqh_last))
00329 /* XXX */
00330 #define TAILQ_PREV(elm, headname, field)                                \
00331         (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
00332 #define TAILQ_EMPTY(head)                                               \
00333         (TAILQ_FIRST(head) == TAILQ_END(head))
00334 
00335 #define TAILQ_FOREACH(var, head, field)                                 \
00336         for((var) = TAILQ_FIRST(head);                                  \
00337             (var) != TAILQ_END(head);                                   \
00338             (var) = TAILQ_NEXT(var, field))
00339 
00340 #define TAILQ_FOREACH_REVERSE(var, head, headname, field)               \
00341         for((var) = TAILQ_LAST(head, headname);                         \
00342             (var) != TAILQ_END(head);                                   \
00343             (var) = TAILQ_PREV(var, headname, field))
00344 
00345 /*
00346  * Tail queue functions.
00347  */
00348 #define TAILQ_INIT(head) do {                                           \
00349         (head)->tqh_first = NULL;                                       \
00350         (head)->tqh_last = &(head)->tqh_first;                          \
00351 } while (0)
00352 
00353 #define TAILQ_INSERT_HEAD(head, elm, field) do {                        \
00354         if (((elm)->field.tqe_next = (head)->tqh_first) != NULL)        \
00355                 (head)->tqh_first->field.tqe_prev =                     \
00356                     &(elm)->field.tqe_next;                             \
00357         else                                                            \
00358                 (head)->tqh_last = &(elm)->field.tqe_next;              \
00359         (head)->tqh_first = (elm);                                      \
00360         (elm)->field.tqe_prev = &(head)->tqh_first;                     \
00361 } while (0)
00362 
00363 #define TAILQ_INSERT_TAIL(head, elm, field) do {                        \
00364         (elm)->field.tqe_next = NULL;                                   \
00365         (elm)->field.tqe_prev = (head)->tqh_last;                       \
00366         *(head)->tqh_last = (elm);                                      \
00367         (head)->tqh_last = &(elm)->field.tqe_next;                      \
00368 } while (0)
00369 
00370 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do {              \
00371         if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
00372                 (elm)->field.tqe_next->field.tqe_prev =                 \
00373                     &(elm)->field.tqe_next;                             \
00374         else                                                            \
00375                 (head)->tqh_last = &(elm)->field.tqe_next;              \
00376         (listelm)->field.tqe_next = (elm);                              \
00377         (elm)->field.tqe_prev = &(listelm)->field.tqe_next;             \
00378 } while (0)
00379 
00380 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do {                   \
00381         (elm)->field.tqe_prev = (listelm)->field.tqe_prev;              \
00382         (elm)->field.tqe_next = (listelm);                              \
00383         *(listelm)->field.tqe_prev = (elm);                             \
00384         (listelm)->field.tqe_prev = &(elm)->field.tqe_next;             \
00385 } while (0)
00386 
00387 #define TAILQ_REMOVE(head, elm, field) do {                             \
00388         if (((elm)->field.tqe_next) != NULL)                            \
00389                 (elm)->field.tqe_next->field.tqe_prev =                 \
00390                     (elm)->field.tqe_prev;                              \
00391         else                                                            \
00392                 (head)->tqh_last = (elm)->field.tqe_prev;               \
00393         *(elm)->field.tqe_prev = (elm)->field.tqe_next;                 \
00394         _Q_INVALIDATE((elm)->field.tqe_prev);                           \
00395         _Q_INVALIDATE((elm)->field.tqe_next);                           \
00396 } while (0)
00397 
00398 #define TAILQ_REPLACE(head, elm, elm2, field) do {                      \
00399         if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL)   \
00400                 (elm2)->field.tqe_next->field.tqe_prev =                \
00401                     &(elm2)->field.tqe_next;                            \
00402         else                                                            \
00403                 (head)->tqh_last = &(elm2)->field.tqe_next;             \
00404         (elm2)->field.tqe_prev = (elm)->field.tqe_prev;                 \
00405         *(elm2)->field.tqe_prev = (elm2);                               \
00406         _Q_INVALIDATE((elm)->field.tqe_prev);                           \
00407         _Q_INVALIDATE((elm)->field.tqe_next);                           \
00408 } while (0)
00409 
00410 /*
00411  * Circular queue definitions.
00412  */
00413 #define CIRCLEQ_HEAD(name, type)                                        \
00414 struct name {                                                           \
00415         struct type *cqh_first;         /* first element */             \
00416         struct type *cqh_last;          /* last element */              \
00417 }
00418 
00419 #define CIRCLEQ_HEAD_INITIALIZER(head)                                  \
00420         { CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
00421 
00422 #define CIRCLEQ_ENTRY(type)                                             \
00423 struct {                                                                \
00424         struct type *cqe_next;          /* next element */              \
00425         struct type *cqe_prev;          /* previous element */          \
00426 }
00427 
00428 /*
00429  * Circular queue access methods
00430  */
00431 #define CIRCLEQ_FIRST(head)             ((head)->cqh_first)
00432 #define CIRCLEQ_LAST(head)              ((head)->cqh_last)
00433 #define CIRCLEQ_END(head)               ((void *)(head))
00434 #define CIRCLEQ_NEXT(elm, field)        ((elm)->field.cqe_next)
00435 #define CIRCLEQ_PREV(elm, field)        ((elm)->field.cqe_prev)
00436 #define CIRCLEQ_EMPTY(head)                                             \
00437         (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))
00438 
00439 #define CIRCLEQ_FOREACH(var, head, field)                               \
00440         for((var) = CIRCLEQ_FIRST(head);                                \
00441             (var) != CIRCLEQ_END(head);                                 \
00442             (var) = CIRCLEQ_NEXT(var, field))
00443 
00444 #define CIRCLEQ_FOREACH_REVERSE(var, head, field)                       \
00445         for((var) = CIRCLEQ_LAST(head);                                 \
00446             (var) != CIRCLEQ_END(head);                                 \
00447             (var) = CIRCLEQ_PREV(var, field))
00448 
00449 /*
00450  * Circular queue functions.
00451  */
00452 #define CIRCLEQ_INIT(head) do {                                         \
00453         (head)->cqh_first = CIRCLEQ_END(head);                          \
00454         (head)->cqh_last = CIRCLEQ_END(head);                           \
00455 } while (0)
00456 
00457 #define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do {            \
00458         (elm)->field.cqe_next = (listelm)->field.cqe_next;              \
00459         (elm)->field.cqe_prev = (listelm);                              \
00460         if ((listelm)->field.cqe_next == CIRCLEQ_END(head))             \
00461                 (head)->cqh_last = (elm);                               \
00462         else                                                            \
00463                 (listelm)->field.cqe_next->field.cqe_prev = (elm);      \
00464         (listelm)->field.cqe_next = (elm);                              \
00465 } while (0)
00466 
00467 #define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do {           \
00468         (elm)->field.cqe_next = (listelm);                              \
00469         (elm)->field.cqe_prev = (listelm)->field.cqe_prev;              \
00470         if ((listelm)->field.cqe_prev == CIRCLEQ_END(head))             \
00471                 (head)->cqh_first = (elm);                              \
00472         else                                                            \
00473                 (listelm)->field.cqe_prev->field.cqe_next = (elm);      \
00474         (listelm)->field.cqe_prev = (elm);                              \
00475 } while (0)
00476 
00477 #define CIRCLEQ_INSERT_HEAD(head, elm, field) do {                      \
00478         (elm)->field.cqe_next = (head)->cqh_first;                      \
00479         (elm)->field.cqe_prev = CIRCLEQ_END(head);                      \
00480         if ((head)->cqh_last == CIRCLEQ_END(head))                      \
00481                 (head)->cqh_last = (elm);                               \
00482         else                                                            \
00483                 (head)->cqh_first->field.cqe_prev = (elm);              \
00484         (head)->cqh_first = (elm);                                      \
00485 } while (0)
00486 
00487 #define CIRCLEQ_INSERT_TAIL(head, elm, field) do {                      \
00488         (elm)->field.cqe_next = CIRCLEQ_END(head);                      \
00489         (elm)->field.cqe_prev = (head)->cqh_last;                       \
00490         if ((head)->cqh_first == CIRCLEQ_END(head))                     \
00491                 (head)->cqh_first = (elm);                              \
00492         else                                                            \
00493                 (head)->cqh_last->field.cqe_next = (elm);               \
00494         (head)->cqh_last = (elm);                                       \
00495 } while (0)
00496 
00497 #define CIRCLEQ_REMOVE(head, elm, field) do {                           \
00498         if ((elm)->field.cqe_next == CIRCLEQ_END(head))                 \
00499                 (head)->cqh_last = (elm)->field.cqe_prev;               \
00500         else                                                            \
00501                 (elm)->field.cqe_next->field.cqe_prev =                 \
00502                     (elm)->field.cqe_prev;                              \
00503         if ((elm)->field.cqe_prev == CIRCLEQ_END(head))                 \
00504                 (head)->cqh_first = (elm)->field.cqe_next;              \
00505         else                                                            \
00506                 (elm)->field.cqe_prev->field.cqe_next =                 \
00507                     (elm)->field.cqe_next;                              \
00508         _Q_INVALIDATE((elm)->field.cqe_prev);                           \
00509         _Q_INVALIDATE((elm)->field.cqe_next);                           \
00510 } while (0)
00511 
00512 #define CIRCLEQ_REPLACE(head, elm, elm2, field) do {                    \
00513         if (((elm2)->field.cqe_next = (elm)->field.cqe_next) ==         \
00514             CIRCLEQ_END(head))                                          \
00515                 (head)->cqh_last = (elm2);                              \
00516         else                                                            \
00517                 (elm2)->field.cqe_next->field.cqe_prev = (elm2);        \
00518         if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) ==         \
00519             CIRCLEQ_END(head))                                          \
00520                 (head)->cqh_first = (elm2);                             \
00521         else                                                            \
00522                 (elm2)->field.cqe_prev->field.cqe_next = (elm2);        \
00523         _Q_INVALIDATE((elm)->field.cqe_prev);                           \
00524         _Q_INVALIDATE((elm)->field.cqe_next);                           \
00525 } while (0)
00526 
00527 #endif  /* !_SYS_QUEUE_H_ */