2
* Copyright (c) 1991, 1993
3
* The Regents of the University of California. All rights reserved.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. All advertising materials mentioning features or use of this software
14
* must display the following acknowledgement:
15
* This product includes software developed by the University of
16
* California, Berkeley and its contributors.
17
* 4. Neither the name of the University nor the names of its contributors
18
* may be used to endorse or promote products derived from this software
19
* without specific prior written permission.
21
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33
* Adapted from FreeBSD sys/queue.h by James Carlson <james.d.carlson@sun.com>
35
* @(#)queue.h 8.5 (Berkeley) 8/20/94
36
* $FreeBSD: src/sys/sys/queue.h,v 1.32.2.6 2001/12/18 10:09:02 ru Exp $
40
* Tail queue declarations.
42
#define TAILQ_HEAD(name, type) \
44
struct type *tqh_first; /* first element */ \
45
struct type **tqh_last; /* addr of last next element */ \
48
#define TAILQ_ENTRY(type) \
50
struct type *tqe_next; /* next element */ \
51
struct type **tqe_prev; /* address of previous next element */ \
55
* Tail queue functions.
57
#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
59
#define TAILQ_FIRST(head) ((head)->tqh_first)
61
#define TAILQ_INIT(head) do { \
62
TAILQ_FIRST((head)) = NULL; \
63
(head)->tqh_last = &TAILQ_FIRST((head)); \
66
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
67
if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
68
TAILQ_FIRST((head))->field.tqe_prev = \
69
&TAILQ_NEXT((elm), field); \
71
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
72
TAILQ_FIRST((head)) = (elm); \
73
(elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
76
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
77
TAILQ_NEXT((elm), field) = NULL; \
78
(elm)->field.tqe_prev = (head)->tqh_last; \
79
*(head)->tqh_last = (elm); \
80
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
83
#define TAILQ_LAST(head, headname) \
84
(*(((struct headname *)((head)->tqh_last))->tqh_last))
86
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
88
#define TAILQ_REMOVE(head, elm, field) do { \
89
if ((TAILQ_NEXT((elm), field)) != NULL) \
90
TAILQ_NEXT((elm), field)->field.tqe_prev = \
91
(elm)->field.tqe_prev; \
93
(head)->tqh_last = (elm)->field.tqe_prev; \
94
*(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
100
#define LIST_HEAD(name, type) \
102
struct type *lh_first; /* first element */ \
105
#define LIST_ENTRY(type) \
107
struct type *le_next; /* next element */ \
108
struct type **le_prev; /* address of previous next element */ \
115
#define LIST_EMPTY(head) ((head)->lh_first == NULL)
117
#define LIST_FIRST(head) ((head)->lh_first)
119
#define LIST_INIT(head) do { \
120
LIST_FIRST((head)) = NULL; \
123
#define LIST_INSERT_HEAD(head, elm, field) do { \
124
if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
125
LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
126
LIST_FIRST((head)) = (elm); \
127
(elm)->field.le_prev = &LIST_FIRST((head)); \
130
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
132
#define LIST_REMOVE(elm, field) do { \
133
if (LIST_NEXT((elm), field) != NULL) \
134
LIST_NEXT((elm), field)->field.le_prev = \
135
(elm)->field.le_prev; \
136
*(elm)->field.le_prev = LIST_NEXT((elm), field); \