1 /******************************************************************************
3 * Copyright (C) 2002 Jason Evans <jasone@FreeBSD.org>.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice(s), this list of conditions and the following disclaimer
11 * unmodified other than the allowable addition of one or more
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice(s), this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 ******************************************************************************/
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
41 #define ql_head(a_type) \
46 #define ql_head_initializer(a_head) {NULL}
48 #define ql_elm(a_type) qr(a_type)
51 #define ql_new(a_head) do { \
52 (a_head)->qlh_first = NULL; \
55 #define ql_elm_new(a_elm, a_field) qr_new((a_elm), a_field)
57 #define ql_first(a_head) ((a_head)->qlh_first)
59 #define ql_last(a_head, a_field) \
60 ((ql_first(a_head) != NULL) \
61 ? qr_prev(ql_first(a_head), a_field) : NULL)
63 #define ql_next(a_head, a_elm, a_field) \
64 ((ql_last(a_head, a_field) != (a_elm)) \
65 ? qr_next((a_elm), a_field) : NULL)
67 #define ql_prev(a_head, a_elm, a_field) \
68 ((ql_first(a_head) != (a_elm)) ? qr_prev((a_elm), a_field) \
71 #define ql_before_insert(a_head, a_qlelm, a_elm, a_field) do { \
72 qr_before_insert((a_qlelm), (a_elm), a_field); \
73 if (ql_first(a_head) == (a_qlelm)) { \
74 ql_first(a_head) = (a_elm); \
78 #define ql_after_insert(a_qlelm, a_elm, a_field) \
79 qr_after_insert((a_qlelm), (a_elm), a_field)
81 #define ql_head_insert(a_head, a_elm, a_field) do { \
82 if (ql_first(a_head) != NULL) { \
83 qr_before_insert(ql_first(a_head), (a_elm), a_field); \
85 ql_first(a_head) = (a_elm); \
88 #define ql_tail_insert(a_head, a_elm, a_field) do { \
89 if (ql_first(a_head) != NULL) { \
90 qr_before_insert(ql_first(a_head), (a_elm), a_field); \
92 ql_first(a_head) = qr_next((a_elm), a_field); \
95 #define ql_remove(a_head, a_elm, a_field) do { \
96 if (ql_first(a_head) == (a_elm)) { \
97 ql_first(a_head) = qr_next(ql_first(a_head), a_field); \
99 if (ql_first(a_head) != (a_elm)) { \
100 qr_remove((a_elm), a_field); \
102 ql_first(a_head) = NULL; \
106 #define ql_head_remove(a_head, a_type, a_field) do { \
107 a_type *t = ql_first(a_head); \
108 ql_remove((a_head), t, a_field); \
111 #define ql_tail_remove(a_head, a_type, a_field) do { \
112 a_type *t = ql_last(a_head, a_field); \
113 ql_remove((a_head), t, a_field); \
116 #define ql_foreach(a_var, a_head, a_field) \
117 qr_foreach((a_var), ql_first(a_head), a_field)
119 #define ql_reverse_foreach(a_var, a_head, a_field) \
120 qr_reverse_foreach((a_var), ql_first(a_head), a_field)