1450N/A/* $NetBSD: queue.h,v 1.42 2005/07/13 15:08:24 wiz Exp $ */
1450N/A
1450N/A/*
1450N/A * Copyright (c) 1991, 1993
1450N/A * The Regents of the University of California. All rights reserved.
1450N/A *
1450N/A * Redistribution and use in source and binary forms, with or without
1450N/A * modification, are permitted provided that the following conditions
1450N/A * are met:
1450N/A * 1. Redistributions of source code must retain the above copyright
1450N/A * notice, this list of conditions and the following disclaimer.
1450N/A * 2. Redistributions in binary form must reproduce the above copyright
1450N/A * notice, this list of conditions and the following disclaimer in the
1450N/A * documentation and/or other materials provided with the distribution.
1450N/A * 3. Neither the name of the University nor the names of its contributors
1450N/A * may be used to endorse or promote products derived from this software
1450N/A * without specific prior written permission.
1450N/A *
1450N/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1450N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1450N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1450N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1450N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1450N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1450N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1450N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1450N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1450N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1450N/A * SUCH DAMAGE.
1450N/A *
1450N/A * @(#)queue.h 8.5 (Berkeley) 8/20/94
1450N/A */
1450N/A/*
1450N/A * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
1450N/A */
1450N/A
1450N/A#ifndef _SYS_QUEUE_H
1450N/A#define _SYS_QUEUE_H
1450N/A
1450N/A#include <sys/note.h>
1450N/A
1450N/A#ifdef __cplusplus
1450N/Aextern "C" {
1450N/A#endif
1450N/A
1450N/A/*
1450N/A * This file defines five types of data structures: singly-linked lists,
1450N/A * lists, simple queues, tail queues, and circular queues.
1450N/A *
1450N/A * A singly-linked list is headed by a single forward pointer. The
1450N/A * elements are singly linked for minimum space and pointer manipulation
1450N/A * overhead at the expense of O(n) removal for arbitrary elements. New
1450N/A * elements can be added to the list after an existing element or at the
1450N/A * head of the list. Elements being removed from the head of the list
1450N/A * should use the explicit macro for this purpose for optimum
1450N/A * efficiency. A singly-linked list may only be traversed in the forward
1450N/A * direction. Singly-linked lists are ideal for applications with large
1450N/A * datasets and few or no removals or for implementing a LIFO queue.
1450N/A *
1450N/A * A list is headed by a single forward pointer (or an array of forward
1450N/A * pointers for a hash table header). The elements are doubly linked
1450N/A * so that an arbitrary element can be removed without a need to
1450N/A * traverse the list. New elements can be added to the list before
1450N/A * or after an existing element or at the head of the list. A list
1450N/A * may only be traversed in the forward direction.
1450N/A *
1450N/A * A simple queue is headed by a pair of pointers, one the head of the
1450N/A * list and the other to the tail of the list. The elements are singly
1450N/A * linked to save space, so elements can only be removed from the
1450N/A * head of the list. New elements can be added to the list after
1450N/A * an existing element, at the head of the list, or at the end of the
1450N/A * list. A simple queue may only be traversed in the forward direction.
1450N/A *
1450N/A * A tail queue is headed by a pair of pointers, one to the head of the
1450N/A * list and the other to the tail of the list. The elements are doubly
1450N/A * linked so that an arbitrary element can be removed without a need to
1450N/A * traverse the list. New elements can be added to the list before or
1450N/A * after an existing element, at the head of the list, or at the end of
1450N/A * the list. A tail queue may be traversed in either direction.
1450N/A *
1450N/A * A circle queue is headed by a pair of pointers, one to the head of the
1450N/A * list and the other to the tail of the list. The elements are doubly
1450N/A * linked so that an arbitrary element can be removed without a need to
1450N/A * traverse the list. New elements can be added to the list before or after
1450N/A * an existing element, at the head of the list, or at the end of the list.
1450N/A * A circle queue may be traversed in either direction, but has a more
1450N/A * complex end of list detection.
1450N/A *
1450N/A * For details on the use of these macros, see the queue(3) manual page.
1450N/A */
1450N/A
1450N/A/*
1450N/A * List definitions.
1450N/A */
1450N/A#define LIST_HEAD(name, type) \
1450N/Astruct name { \
1450N/A struct type *lh_first; /* first element */ \
1450N/A}
1450N/A
1450N/A#define LIST_HEAD_INITIALIZER(head) \
1450N/A { NULL }
1450N/A
1450N/A#define LIST_ENTRY(type) \
1450N/Astruct { \
1450N/A struct type *le_next; /* next element */ \
1450N/A struct type **le_prev; /* address of previous next element */ \
1450N/A}
1450N/A
1450N/A/*
1450N/A * List functions.
1450N/A */
1450N/A#if defined(_KERNEL) && defined(QUEUEDEBUG)
1450N/A#define QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field) \
1450N/A if ((head)->lh_first && \
1450N/A (head)->lh_first->field.le_prev != &(head)->lh_first) \
1450N/A panic("LIST_INSERT_HEAD %p %s:%d", (void *)(head), \
1450N/A __FILE__, __LINE__);
1450N/A#define QUEUEDEBUG_LIST_OP(elm, field) \
1450N/A if ((elm)->field.le_next && \
1450N/A (elm)->field.le_next->field.le_prev != \
1450N/A &(elm)->field.le_next) \
1450N/A panic("LIST_* forw %p %s:%d", (void *)(elm), \
1450N/A __FILE__, __LINE__); \
1450N/A if (*(elm)->field.le_prev != (elm)) \
1450N/A panic("LIST_* back %p %s:%d", (void *)(elm), __FILE__, \
1450N/A __LINE__);
1450N/A#define QUEUEDEBUG_LIST_POSTREMOVE(elm, field) \
1450N/A (elm)->field.le_next = (void *)1L; \
1450N/A (elm)->field.le_prev = (void *)1L;
1450N/A#else
1450N/A#define QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field)
1450N/A#define QUEUEDEBUG_LIST_OP(elm, field)
1450N/A#define QUEUEDEBUG_LIST_POSTREMOVE(elm, field)
1450N/A#endif
1450N/A
1450N/A#define LIST_INIT(head) do { \
1450N/A (head)->lh_first = NULL; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define LIST_INSERT_AFTER(listelm, elm, field) do { \
1450N/A QUEUEDEBUG_LIST_OP((listelm), field) \
1450N/A if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
1450N/A (listelm)->field.le_next->field.le_prev = \
1450N/A &(elm)->field.le_next; \
1450N/A (listelm)->field.le_next = (elm); \
1450N/A (elm)->field.le_prev = &(listelm)->field.le_next; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
1450N/A QUEUEDEBUG_LIST_OP((listelm), field) \
1450N/A (elm)->field.le_prev = (listelm)->field.le_prev; \
1450N/A (elm)->field.le_next = (listelm); \
1450N/A *(listelm)->field.le_prev = (elm); \
1450N/A (listelm)->field.le_prev = &(elm)->field.le_next; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define LIST_INSERT_HEAD(head, elm, field) do { \
1450N/A QUEUEDEBUG_LIST_INSERT_HEAD((head), (elm), field) \
1450N/A if (((elm)->field.le_next = (head)->lh_first) != NULL) \
1450N/A (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
1450N/A (head)->lh_first = (elm); \
1450N/A (elm)->field.le_prev = &(head)->lh_first; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define LIST_REMOVE(elm, field) do { \
1450N/A QUEUEDEBUG_LIST_OP((elm), field) \
1450N/A if ((elm)->field.le_next != NULL) \
1450N/A (elm)->field.le_next->field.le_prev = \
1450N/A (elm)->field.le_prev; \
1450N/A *(elm)->field.le_prev = (elm)->field.le_next; \
1450N/A QUEUEDEBUG_LIST_POSTREMOVE((elm), field) \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define LIST_FOREACH(var, head, field) \
1450N/A for ((var) = ((head)->lh_first); \
1450N/A (var); \
1450N/A (var) = ((var)->field.le_next))
1450N/A
1450N/A#define LIST_FOREACH_SAFE(var, head, field, tvar) \
1450N/A for ((var) = LIST_FIRST((head)); \
1450N/A (var) && ((tvar) = LIST_NEXT((var), field), 1); \
1450N/A (var) = (tvar))
1450N/A
1450N/A/*
1450N/A * List access methods.
1450N/A */
1450N/A#define LIST_EMPTY(head) ((head)->lh_first == NULL)
1450N/A#define LIST_FIRST(head) ((head)->lh_first)
1450N/A#define LIST_NEXT(elm, field) ((elm)->field.le_next)
1450N/A
1450N/A
1450N/A/*
1450N/A * Singly-linked List definitions.
1450N/A */
1450N/A#define SLIST_HEAD(name, type) \
1450N/Astruct name { \
1450N/A struct type *slh_first; /* first element */ \
1450N/A}
1450N/A
1450N/A#define SLIST_HEAD_INITIALIZER(head) \
1450N/A { NULL }
1450N/A
1450N/A#define SLIST_ENTRY(type) \
1450N/Astruct { \
1450N/A struct type *sle_next; /* next element */ \
1450N/A}
1450N/A
1450N/A/*
1450N/A * Singly-linked List functions.
1450N/A */
1450N/A#define SLIST_INIT(head) do { \
1450N/A (head)->slh_first = NULL; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
1450N/A (elm)->field.sle_next = (slistelm)->field.sle_next; \
1450N/A (slistelm)->field.sle_next = (elm); \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define SLIST_INSERT_HEAD(head, elm, field) do { \
1450N/A (elm)->field.sle_next = (head)->slh_first; \
1450N/A (head)->slh_first = (elm); \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define SLIST_REMOVE_HEAD(head, field) do { \
1450N/A (head)->slh_first = (head)->slh_first->field.sle_next; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define SLIST_REMOVE(head, elm, type, field) do { \
1450N/A if ((head)->slh_first == (elm)) { \
1450N/A SLIST_REMOVE_HEAD((head), field); \
1450N/A } \
1450N/A else { \
1450N/A struct type *curelm = (head)->slh_first; \
1450N/A while (curelm->field.sle_next != (elm)) \
1450N/A curelm = curelm->field.sle_next; \
1450N/A curelm->field.sle_next = \
1450N/A curelm->field.sle_next->field.sle_next; \
1450N/A } \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define SLIST_FOREACH(var, head, field) \
1450N/A for ((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
1450N/A
1450N/A#define SLIST_FOREACH_SAFE(var, head, field, tvar) \
1450N/A for ((var) = SLIST_FIRST((head)); \
1450N/A (var) && ((tvar) = SLIST_NEXT((var), field), 1); \
1450N/A (var) = (tvar))
1450N/A
1450N/A/*
1450N/A * Singly-linked List access methods.
1450N/A */
1450N/A#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
1450N/A#define SLIST_FIRST(head) ((head)->slh_first)
1450N/A#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
1450N/A
1450N/A
1450N/A/*
1450N/A * Singly-linked Tail queue declarations.
1450N/A */
1450N/A#define STAILQ_HEAD(name, type) \
1450N/Astruct name { \
1450N/A struct type *stqh_first; /* first element */ \
1450N/A struct type **stqh_last; /* addr of last next element */ \
1450N/A}
1450N/A
1450N/A#define STAILQ_HEAD_INITIALIZER(head) \
1450N/A { NULL, &(head).stqh_first }
1450N/A
1450N/A#define STAILQ_ENTRY(type) \
1450N/Astruct { \
1450N/A struct type *stqe_next; /* next element */ \
1450N/A}
1450N/A
1450N/A/*
1450N/A * Singly-linked Tail queue functions.
1450N/A */
1450N/A#define STAILQ_INIT(head) do { \
1450N/A (head)->stqh_first = NULL; \
1450N/A (head)->stqh_last = &(head)->stqh_first; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define STAILQ_INSERT_HEAD(head, elm, field) do { \
1450N/A if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \
1450N/A (head)->stqh_last = &(elm)->field.stqe_next; \
1450N/A (head)->stqh_first = (elm); \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define STAILQ_INSERT_TAIL(head, elm, field) do { \
1450N/A (elm)->field.stqe_next = NULL; \
1450N/A *(head)->stqh_last = (elm); \
1450N/A (head)->stqh_last = &(elm)->field.stqe_next; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
1450N/A if (((elm)->field.stqe_next = (listelm)->field.stqe_next) \
1450N/A == NULL) \
1450N/A (head)->stqh_last = &(elm)->field.stqe_next; \
1450N/A (listelm)->field.stqe_next = (elm); \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define STAILQ_REMOVE_HEAD(head, field) do { \
1450N/A if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) \
1450N/A == NULL) \
1450N/A (head)->stqh_last = &(head)->stqh_first; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define STAILQ_REMOVE(head, elm, type, field) do { \
1450N/A if ((head)->stqh_first == (elm)) { \
1450N/A STAILQ_REMOVE_HEAD((head), field); \
1450N/A } else { \
1450N/A struct type *curelm = (head)->stqh_first; \
1450N/A while (curelm->field.stqe_next != (elm)) \
1450N/A curelm = curelm->field.stqe_next; \
1450N/A if ((curelm->field.stqe_next = \
1450N/A curelm->field.stqe_next->field.stqe_next) == NULL) \
1450N/A (head)->stqh_last = &(curelm)->field.stqe_next; \
1450N/A } \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define STAILQ_FOREACH(var, head, field) \
1450N/A for ((var) = ((head)->stqh_first); \
1450N/A (var); \
1450N/A (var) = ((var)->field.stqe_next))
1450N/A
1450N/A#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
1450N/A for ((var) = STAILQ_FIRST((head)); \
1450N/A (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
1450N/A (var) = (tvar))
1450N/A
1450N/A/*
1450N/A * Singly-linked Tail queue access methods.
1450N/A */
1450N/A#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
1450N/A#define STAILQ_FIRST(head) ((head)->stqh_first)
1450N/A#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
1450N/A
1450N/A
1450N/A/*
1450N/A * Simple queue definitions.
1450N/A */
1450N/A#define SIMPLEQ_HEAD(name, type) \
1450N/Astruct name { \
1450N/A struct type *sqh_first; /* first element */ \
1450N/A struct type **sqh_last; /* addr of last next element */ \
1450N/A}
1450N/A
1450N/A#define SIMPLEQ_HEAD_INITIALIZER(head) \
1450N/A { NULL, &(head).sqh_first }
1450N/A
1450N/A#define SIMPLEQ_ENTRY(type) \
1450N/Astruct { \
1450N/A struct type *sqe_next; /* next element */ \
1450N/A}
1450N/A
1450N/A/*
1450N/A * Simple queue functions.
1450N/A */
1450N/A#define SIMPLEQ_INIT(head) do { \
1450N/A (head)->sqh_first = NULL; \
1450N/A (head)->sqh_last = &(head)->sqh_first; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
1450N/A if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
1450N/A (head)->sqh_last = &(elm)->field.sqe_next; \
1450N/A (head)->sqh_first = (elm); \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
1450N/A (elm)->field.sqe_next = NULL; \
1450N/A *(head)->sqh_last = (elm); \
1450N/A (head)->sqh_last = &(elm)->field.sqe_next; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
1450N/A if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
1450N/A (head)->sqh_last = &(elm)->field.sqe_next; \
1450N/A (listelm)->field.sqe_next = (elm); \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define SIMPLEQ_REMOVE_HEAD(head, field) do { \
1450N/A if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
1450N/A (head)->sqh_last = &(head)->sqh_first; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define SIMPLEQ_REMOVE(head, elm, type, field) do { \
1450N/A if ((head)->sqh_first == (elm)) { \
1450N/A SIMPLEQ_REMOVE_HEAD((head), field); \
1450N/A } else { \
1450N/A struct type *curelm = (head)->sqh_first; \
1450N/A while (curelm->field.sqe_next != (elm)) \
1450N/A curelm = curelm->field.sqe_next; \
1450N/A if ((curelm->field.sqe_next = \
1450N/A curelm->field.sqe_next->field.sqe_next) == NULL) \
1450N/A (head)->sqh_last = &(curelm)->field.sqe_next; \
1450N/A } \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define SIMPLEQ_FOREACH(var, head, field) \
1450N/A for ((var) = ((head)->sqh_first); \
1450N/A (var); \
1450N/A (var) = ((var)->field.sqe_next))
1450N/A
1450N/A/*
1450N/A * Simple queue access methods.
1450N/A */
1450N/A#define SIMPLEQ_EMPTY(head) ((head)->sqh_first == NULL)
1450N/A#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
1450N/A#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
1450N/A
1450N/A
1450N/A/*
1450N/A * Tail queue definitions.
1450N/A */
1450N/A#define _TAILQ_HEAD(name, type) \
1450N/Astruct name { \
1450N/A type *tqh_first; /* first element */ \
1450N/A type **tqh_last; /* addr of last next element */ \
1450N/A}
1450N/A#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type)
1450N/A
1450N/A#define TAILQ_HEAD_INITIALIZER(head) \
1450N/A { NULL, &(head).tqh_first }
1450N/A
1450N/A#define _TAILQ_ENTRY(type) \
1450N/Astruct { \
1450N/A type *tqe_next; /* next element */ \
1450N/A type **tqe_prev; /* address of previous next element */\
1450N/A}
1450N/A#define TAILQ_ENTRY(type) _TAILQ_ENTRY(struct type)
1450N/A
1450N/A/*
1450N/A * Tail queue functions.
1450N/A */
1450N/A#if defined(_KERNEL) && defined(QUEUEDEBUG)
1450N/A#define QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field) \
1450N/A if ((head)->tqh_first && \
1450N/A (head)->tqh_first->field.tqe_prev != &(head)->tqh_first) \
1450N/A panic("TAILQ_INSERT_HEAD %p %s:%d", (void *)(head), \
1450N/A __FILE__, __LINE__);
1450N/A#define QUEUEDEBUG_TAILQ_INSERT_TAIL(head, elm, field) \
1450N/A if (*(head)->tqh_last != NULL) \
1450N/A panic("TAILQ_INSERT_TAIL %p %s:%d", (void *)(head), \
1450N/A __FILE__, __LINE__);
1450N/A#define QUEUEDEBUG_TAILQ_OP(elm, field) \
1450N/A if ((elm)->field.tqe_next && \
1450N/A (elm)->field.tqe_next->field.tqe_prev != \
1450N/A &(elm)->field.tqe_next) \
1450N/A panic("TAILQ_* forw %p %s:%d", (void *)(elm), \
1450N/A __FILE__, __LINE__);\
1450N/A if (*(elm)->field.tqe_prev != (elm)) \
1450N/A panic("TAILQ_* back %p %s:%d", (void *)(elm), \
1450N/A __FILE__, __LINE__);
1450N/A#define QUEUEDEBUG_TAILQ_PREREMOVE(head, elm, field) \
1450N/A if ((elm)->field.tqe_next == NULL && \
1450N/A (head)->tqh_last != &(elm)->field.tqe_next) \
1450N/A panic("TAILQ_PREREMOVE head %p elm %p %s:%d", \
1450N/A (void *)(head), (void *)(elm), __FILE__, __LINE__);
1450N/A#define QUEUEDEBUG_TAILQ_POSTREMOVE(elm, field) \
1450N/A (elm)->field.tqe_next = (void *)1L; \
1450N/A (elm)->field.tqe_prev = (void *)1L;
1450N/A#else
1450N/A#define QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field)
1450N/A#define QUEUEDEBUG_TAILQ_INSERT_TAIL(head, elm, field)
1450N/A#define QUEUEDEBUG_TAILQ_OP(elm, field)
1450N/A#define QUEUEDEBUG_TAILQ_PREREMOVE(head, elm, field)
1450N/A#define QUEUEDEBUG_TAILQ_POSTREMOVE(elm, field)
1450N/A#endif
1450N/A
1450N/A#define TAILQ_INIT(head) do { \
1450N/A (head)->tqh_first = NULL; \
1450N/A (head)->tqh_last = &(head)->tqh_first; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define TAILQ_INSERT_HEAD(head, elm, field) do { \
1450N/A QUEUEDEBUG_TAILQ_INSERT_HEAD((head), (elm), field) \
1450N/A if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
1450N/A (head)->tqh_first->field.tqe_prev = \
1450N/A &(elm)->field.tqe_next; \
1450N/A else \
1450N/A (head)->tqh_last = &(elm)->field.tqe_next; \
1450N/A (head)->tqh_first = (elm); \
1450N/A (elm)->field.tqe_prev = &(head)->tqh_first; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define TAILQ_INSERT_TAIL(head, elm, field) do { \
1450N/A QUEUEDEBUG_TAILQ_INSERT_TAIL((head), (elm), field) \
1450N/A (elm)->field.tqe_next = NULL; \
1450N/A (elm)->field.tqe_prev = (head)->tqh_last; \
1450N/A *(head)->tqh_last = (elm); \
1450N/A (head)->tqh_last = &(elm)->field.tqe_next; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
1450N/A QUEUEDEBUG_TAILQ_OP((listelm), field) \
1450N/A if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
1450N/A (elm)->field.tqe_next->field.tqe_prev = \
1450N/A &(elm)->field.tqe_next; \
1450N/A else \
1450N/A (head)->tqh_last = &(elm)->field.tqe_next; \
1450N/A (listelm)->field.tqe_next = (elm); \
1450N/A (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
1450N/A QUEUEDEBUG_TAILQ_OP((listelm), field) \
1450N/A (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
1450N/A (elm)->field.tqe_next = (listelm); \
1450N/A *(listelm)->field.tqe_prev = (elm); \
1450N/A (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define TAILQ_REMOVE(head, elm, field) do { \
1450N/A QUEUEDEBUG_TAILQ_PREREMOVE((head), (elm), field) \
1450N/A QUEUEDEBUG_TAILQ_OP((elm), field) \
1450N/A if (((elm)->field.tqe_next) != NULL) \
1450N/A (elm)->field.tqe_next->field.tqe_prev = \
1450N/A (elm)->field.tqe_prev; \
1450N/A else \
1450N/A (head)->tqh_last = (elm)->field.tqe_prev; \
1450N/A *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
1450N/A QUEUEDEBUG_TAILQ_POSTREMOVE((elm), field); \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define TAILQ_FOREACH(var, head, field) \
1450N/A for ((var) = ((head)->tqh_first); \
1450N/A (var); \
1450N/A (var) = ((var)->field.tqe_next))
1450N/A
1450N/A#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
1450N/A for ((var) = TAILQ_FIRST((head)); \
1450N/A (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
1450N/A (var) = (tvar))
1450N/A
1450N/A#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
1450N/A for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last));\
1450N/A (var); \
1450N/A (var) = \
1450N/A (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
1450N/A
1450N/A#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
1450N/A for ((var) = TAILQ_LAST((head), headname); \
1450N/A (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
1450N/A (var) = (tvar))
1450N/A
1450N/A/*
1450N/A * Tail queue access methods.
1450N/A */
1450N/A#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
1450N/A#define TAILQ_FIRST(head) ((head)->tqh_first)
1450N/A#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
1450N/A
1450N/A#define TAILQ_LAST(head, headname) \
1450N/A (*(((struct headname *)((head)->tqh_last))->tqh_last))
1450N/A#define TAILQ_PREV(elm, headname, field) \
1450N/A (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
1450N/A
1450N/A
1450N/A/*
1450N/A * Circular queue definitions.
1450N/A */
1450N/A#define CIRCLEQ_HEAD(name, type) \
1450N/Astruct name { \
1450N/A struct type *cqh_first; /* first element */ \
1450N/A struct type *cqh_last; /* last element */ \
1450N/A}
1450N/A
1450N/A#define CIRCLEQ_HEAD_INITIALIZER(head) \
1450N/A { (void *)&head, (void *)&head }
1450N/A
1450N/A#define CIRCLEQ_ENTRY(type) \
1450N/Astruct { \
1450N/A struct type *cqe_next; /* next element */ \
1450N/A struct type *cqe_prev; /* previous element */ \
1450N/A}
1450N/A
1450N/A/*
1450N/A * Circular queue functions.
1450N/A */
1450N/A#define CIRCLEQ_INIT(head) do { \
1450N/A (head)->cqh_first = (void *)(head); \
1450N/A (head)->cqh_last = (void *)(head); \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
1450N/A (elm)->field.cqe_next = (listelm)->field.cqe_next; \
1450N/A (elm)->field.cqe_prev = (listelm); \
1450N/A if ((listelm)->field.cqe_next == (void *)(head)) \
1450N/A (head)->cqh_last = (elm); \
1450N/A else \
1450N/A (listelm)->field.cqe_next->field.cqe_prev = (elm); \
1450N/A (listelm)->field.cqe_next = (elm); \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
1450N/A (elm)->field.cqe_next = (listelm); \
1450N/A (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
1450N/A if ((listelm)->field.cqe_prev == (void *)(head)) \
1450N/A (head)->cqh_first = (elm); \
1450N/A else \
1450N/A (listelm)->field.cqe_prev->field.cqe_next = (elm); \
1450N/A (listelm)->field.cqe_prev = (elm); \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
1450N/A (elm)->field.cqe_next = (head)->cqh_first; \
1450N/A (elm)->field.cqe_prev = (void *)(head); \
1450N/A if ((head)->cqh_last == (void *)(head)) \
1450N/A (head)->cqh_last = (elm); \
1450N/A else \
1450N/A (head)->cqh_first->field.cqe_prev = (elm); \
1450N/A (head)->cqh_first = (elm); \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
1450N/A (elm)->field.cqe_next = (void *)(head); \
1450N/A (elm)->field.cqe_prev = (head)->cqh_last; \
1450N/A if ((head)->cqh_first == (void *)(head)) \
1450N/A (head)->cqh_first = (elm); \
1450N/A else \
1450N/A (head)->cqh_last->field.cqe_next = (elm); \
1450N/A (head)->cqh_last = (elm); \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define CIRCLEQ_REMOVE(head, elm, field) do { \
1450N/A if ((elm)->field.cqe_next == (void *)(head)) \
1450N/A (head)->cqh_last = (elm)->field.cqe_prev; \
1450N/A else \
1450N/A (elm)->field.cqe_next->field.cqe_prev = \
1450N/A (elm)->field.cqe_prev; \
1450N/A if ((elm)->field.cqe_prev == (void *)(head)) \
1450N/A (head)->cqh_first = (elm)->field.cqe_next; \
1450N/A else \
1450N/A (elm)->field.cqe_prev->field.cqe_next = \
1450N/A (elm)->field.cqe_next; \
1450N/A _NOTE(CONSTCOND) \
1450N/A} while (0)
1450N/A
1450N/A#define CIRCLEQ_FOREACH(var, head, field) \
1450N/A for ((var) = ((head)->cqh_first); \
1450N/A (var) != (void *)(head); \
1450N/A (var) = ((var)->field.cqe_next))
1450N/A
1450N/A#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
1450N/A for ((var) = ((head)->cqh_last); \
1450N/A (var) != (void *)(head); \
1450N/A (var) = ((var)->field.cqe_prev))
1450N/A
1450N/A/*
1450N/A * Circular queue access methods.
1450N/A */
1450N/A#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
1450N/A#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
1450N/A#define CIRCLEQ_LAST(head) ((head)->cqh_last)
1450N/A#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
1450N/A#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
1450N/A
1450N/A#define CIRCLEQ_LOOP_NEXT(head, elm, field) \
1450N/A (((elm)->field.cqe_next == (void *)(head)) \
1450N/A ? ((head)->cqh_first) \
1450N/A : (elm->field.cqe_next))
1450N/A#define CIRCLEQ_LOOP_PREV(head, elm, field) \
1450N/A (((elm)->field.cqe_prev == (void *)(head)) \
1450N/A ? ((head)->cqh_last) \
1450N/A : (elm->field.cqe_prev))
1450N/A
1450N/A#ifdef __cplusplus
1450N/A}
1450N/A#endif
1450N/A
1450N/A#endif /* !_SYS_QUEUE_H */