60405de4d8688d96dd05157c28db3ade5c9bc234kz/* BEGIN CSTYLED */
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Copyright (c) 1991, 1993
60405de4d8688d96dd05157c28db3ade5c9bc234kz * The Regents of the University of California. All rights reserved.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Redistribution and use in source and binary forms, with or without
60405de4d8688d96dd05157c28db3ade5c9bc234kz * modification, are permitted provided that the following conditions
60405de4d8688d96dd05157c28db3ade5c9bc234kz * are met:
60405de4d8688d96dd05157c28db3ade5c9bc234kz * 1. Redistributions of source code must retain the above copyright
60405de4d8688d96dd05157c28db3ade5c9bc234kz * notice, this list of conditions and the following disclaimer.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * 2. Redistributions in binary form must reproduce the above copyright
60405de4d8688d96dd05157c28db3ade5c9bc234kz * notice, this list of conditions and the following disclaimer in the
60405de4d8688d96dd05157c28db3ade5c9bc234kz * documentation and/or other materials provided with the distribution.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * 4. Neither the name of the University nor the names of its contributors
60405de4d8688d96dd05157c28db3ade5c9bc234kz * may be used to endorse or promote products derived from this software
60405de4d8688d96dd05157c28db3ade5c9bc234kz * without specific prior written permission.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60405de4d8688d96dd05157c28db3ade5c9bc234kz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60405de4d8688d96dd05157c28db3ade5c9bc234kz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60405de4d8688d96dd05157c28db3ade5c9bc234kz * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60405de4d8688d96dd05157c28db3ade5c9bc234kz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60405de4d8688d96dd05157c28db3ade5c9bc234kz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60405de4d8688d96dd05157c28db3ade5c9bc234kz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60405de4d8688d96dd05157c28db3ade5c9bc234kz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60405de4d8688d96dd05157c28db3ade5c9bc234kz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60405de4d8688d96dd05157c28db3ade5c9bc234kz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60405de4d8688d96dd05157c28db3ade5c9bc234kz * SUCH DAMAGE.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * @(#)queue.h 8.5 (Berkeley) 8/20/94
60405de4d8688d96dd05157c28db3ade5c9bc234kz * $FreeBSD: /repoman/r/ncvs/src/sys/sys/queue.h,v 1.66 2006/05/26 18:17:53 emaste Exp $
60405de4d8688d96dd05157c28db3ade5c9bc234kz#pragma ident "%Z%%M% %I% %E% SMI"
60405de4d8688d96dd05157c28db3ade5c9bc234kz * This file defines four types of data structures: singly-linked lists,
60405de4d8688d96dd05157c28db3ade5c9bc234kz * singly-linked tail queues, lists and tail queues.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * A singly-linked list is headed by a single forward pointer. The elements
60405de4d8688d96dd05157c28db3ade5c9bc234kz * are singly linked for minimum space and pointer manipulation overhead at
60405de4d8688d96dd05157c28db3ade5c9bc234kz * the expense of O(n) removal for arbitrary elements. New elements can be
60405de4d8688d96dd05157c28db3ade5c9bc234kz * added to the list after an existing element or at the head of the list.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Elements being removed from the head of the list should use the explicit
60405de4d8688d96dd05157c28db3ade5c9bc234kz * macro for this purpose for optimum efficiency. A singly-linked list may
60405de4d8688d96dd05157c28db3ade5c9bc234kz * only be traversed in the forward direction. Singly-linked lists are ideal
60405de4d8688d96dd05157c28db3ade5c9bc234kz * for applications with large datasets and few or no removals or for
60405de4d8688d96dd05157c28db3ade5c9bc234kz * implementing a LIFO queue.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * A singly-linked tail queue is headed by a pair of pointers, one to the
60405de4d8688d96dd05157c28db3ade5c9bc234kz * head of the list and the other to the tail of the list. The elements are
60405de4d8688d96dd05157c28db3ade5c9bc234kz * singly linked for minimum space and pointer manipulation overhead at the
60405de4d8688d96dd05157c28db3ade5c9bc234kz * expense of O(n) removal for arbitrary elements. New elements can be added
60405de4d8688d96dd05157c28db3ade5c9bc234kz * to the list after an existing element, at the head of the list, or at the
60405de4d8688d96dd05157c28db3ade5c9bc234kz * end of the list. Elements being removed from the head of the tail queue
60405de4d8688d96dd05157c28db3ade5c9bc234kz * should use the explicit macro for this purpose for optimum efficiency.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * A singly-linked tail queue may only be traversed in the forward direction.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Singly-linked tail queues are ideal for applications with large datasets
60405de4d8688d96dd05157c28db3ade5c9bc234kz * and few or no removals or for implementing a FIFO queue.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * A list is headed by a single forward pointer (or an array of forward
60405de4d8688d96dd05157c28db3ade5c9bc234kz * pointers for a hash table header). The elements are doubly linked
60405de4d8688d96dd05157c28db3ade5c9bc234kz * so that an arbitrary element can be removed without a need to
60405de4d8688d96dd05157c28db3ade5c9bc234kz * traverse the list. New elements can be added to the list before
60405de4d8688d96dd05157c28db3ade5c9bc234kz * or after an existing element or at the head of the list. A list
60405de4d8688d96dd05157c28db3ade5c9bc234kz * may only be traversed in the forward direction.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * A tail queue is headed by a pair of pointers, one to the head of the
60405de4d8688d96dd05157c28db3ade5c9bc234kz * list and the other to the tail of the list. The elements are doubly
60405de4d8688d96dd05157c28db3ade5c9bc234kz * linked so that an arbitrary element can be removed without a need to
60405de4d8688d96dd05157c28db3ade5c9bc234kz * traverse the list. New elements can be added to the list before or
60405de4d8688d96dd05157c28db3ade5c9bc234kz * after an existing element, at the head of the list, or at the end of
60405de4d8688d96dd05157c28db3ade5c9bc234kz * the list. A tail queue may be traversed in either direction.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * For details on the use of these macros, see the queue(3) manual page.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * SLIST LIST STAILQ TAILQ
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _HEAD + + + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _HEAD_INITIALIZER + + + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _ENTRY + + + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _INIT + + + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _EMPTY + + + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _FIRST + + + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _NEXT + + + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _PREV - - - +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _LAST - - + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _FOREACH + + + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _FOREACH_SAFE + + + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _FOREACH_REVERSE - - - +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _FOREACH_REVERSE_SAFE - - - +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _INSERT_HEAD + + + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _INSERT_BEFORE - + - +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _INSERT_AFTER + + + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _INSERT_TAIL - - + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _CONCAT - - + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _REMOVE_HEAD + - + -
60405de4d8688d96dd05157c28db3ade5c9bc234kz * _REMOVE + + + +
60405de4d8688d96dd05157c28db3ade5c9bc234kz/* Store the last 2 places the queue element or head was altered */
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz#endif /* QUEUE_MACRO_DEBUG */
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Singly-linked List declarations.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Singly-linked List functions.
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Singly-linked Tail queue declarations.
60405de4d8688d96dd05157c28db3ade5c9bc234kz struct type **stqh_last;/* addr of last next element */ \
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Singly-linked Tail queue functions.
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \
60405de4d8688d96dd05157c28db3ade5c9bc234kz if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz ((struct type *)(void *) \
60405de4d8688d96dd05157c28db3ade5c9bc234kz ((char *)((head)->stqh_last) - __offsetof(struct type, field))))
60405de4d8688d96dd05157c28db3ade5c9bc234kz STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz * List declarations.
60405de4d8688d96dd05157c28db3ade5c9bc234kz struct type **le_prev; /* address of previous next element */ \
60405de4d8688d96dd05157c28db3ade5c9bc234kz * List functions.
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz#endif /* (_KERNEL && INVARIANTS) */
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
60405de4d8688d96dd05157c28db3ade5c9bc234kz LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Tail queue declarations.
60405de4d8688d96dd05157c28db3ade5c9bc234kz struct type **tqh_last; /* addr of last next element */ \
60405de4d8688d96dd05157c28db3ade5c9bc234kz struct type **tqe_prev; /* address of previous next element */ \
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Tail queue functions.
60405de4d8688d96dd05157c28db3ade5c9bc234kz panic("Bad tailq head %p first->prev != head", (head)); \
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz#endif /* (_KERNEL && INVARIANTS) */
60405de4d8688d96dd05157c28db3ade5c9bc234kz (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
60405de4d8688d96dd05157c28db3ade5c9bc234kz#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
60405de4d8688d96dd05157c28db3ade5c9bc234kz (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
60405de4d8688d96dd05157c28db3ade5c9bc234kz if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
60405de4d8688d96dd05157c28db3ade5c9bc234kz} while (*"\0")
60405de4d8688d96dd05157c28db3ade5c9bc234kz#endif /* _KERNEL */
60405de4d8688d96dd05157c28db3ade5c9bc234kz#endif /* !_SYS_QUEUE_H_ */
60405de4d8688d96dd05157c28db3ade5c9bc234kz/* END CSTYLED */