Print this page
Reduce lint
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/common/list/list.c
+++ new/usr/src/common/list/list.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 25 /*
26 26 * Generic doubly-linked list implementation
27 27 */
28 28
29 29 #include <sys/list.h>
30 30 #include <sys/list_impl.h>
|
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
31 31 #include <sys/types.h>
32 32 #include <sys/sysmacros.h>
33 33 #ifdef _KERNEL
34 34 #include <sys/debug.h>
35 35 #else
36 36 #include <assert.h>
37 37 #define ASSERT(a) assert(a)
38 38 #endif
39 39
40 40 #ifdef lint
41 -extern list_node_t *list_d2l(list_t *list, void *obj);
41 +static list_node_t *
42 +list_d2l(list_t *list, void *obj)
43 +{
44 + /* Pretty version for lint... */
45 + uint64_t *offset = (uint64_t *)obj;
46 +
47 + if (!IS_P2ALIGNED(obj, 8))
48 + return (NULL);
49 +
50 + return ((list_node_t *)(offset + (list->list_offset >> 3)));
51 +}
42 52 #else
43 53 #define list_d2l(a, obj) ((list_node_t *)(((char *)obj) + (a)->list_offset))
44 54 #endif
45 55 #define list_object(a, node) ((void *)(((char *)node) - (a)->list_offset))
46 56 #define list_empty(a) ((a)->list_head.list_next == &(a)->list_head)
47 57
48 58 #define list_insert_after_node(list, node, object) { \
49 59 list_node_t *lnew = list_d2l(list, object); \
50 60 lnew->list_prev = (node); \
51 61 lnew->list_next = (node)->list_next; \
52 62 (node)->list_next->list_prev = lnew; \
53 63 (node)->list_next = lnew; \
54 64 }
55 65
56 66 #define list_insert_before_node(list, node, object) { \
57 67 list_node_t *lnew = list_d2l(list, object); \
58 68 lnew->list_next = (node); \
59 69 lnew->list_prev = (node)->list_prev; \
60 70 (node)->list_prev->list_next = lnew; \
61 71 (node)->list_prev = lnew; \
62 72 }
63 73
64 74 #define list_remove_node(node) \
65 75 (node)->list_prev->list_next = (node)->list_next; \
66 76 (node)->list_next->list_prev = (node)->list_prev; \
67 77 (node)->list_next = (node)->list_prev = NULL
68 78
69 79 void
70 80 list_create(list_t *list, size_t size, size_t offset)
71 81 {
72 82 ASSERT(list);
73 83 ASSERT(size > 0);
74 84 ASSERT(size >= offset + sizeof (list_node_t));
75 85
76 86 list->list_size = size;
77 87 list->list_offset = offset;
78 88 list->list_head.list_next = list->list_head.list_prev =
79 89 &list->list_head;
80 90 }
81 91
82 92 void
83 93 list_destroy(list_t *list)
84 94 {
85 95 list_node_t *node = &list->list_head;
86 96
87 97 ASSERT(list);
88 98 ASSERT(list->list_head.list_next == node);
89 99 ASSERT(list->list_head.list_prev == node);
90 100
91 101 node->list_next = node->list_prev = NULL;
92 102 }
93 103
94 104 void
95 105 list_insert_after(list_t *list, void *object, void *nobject)
96 106 {
97 107 if (object == NULL) {
98 108 list_insert_head(list, nobject);
99 109 } else {
100 110 list_node_t *lold = list_d2l(list, object);
101 111 list_insert_after_node(list, lold, nobject);
102 112 }
103 113 }
104 114
105 115 void
106 116 list_insert_before(list_t *list, void *object, void *nobject)
107 117 {
108 118 if (object == NULL) {
109 119 list_insert_tail(list, nobject);
110 120 } else {
111 121 list_node_t *lold = list_d2l(list, object);
112 122 list_insert_before_node(list, lold, nobject);
113 123 }
114 124 }
115 125
116 126 void
117 127 list_insert_head(list_t *list, void *object)
118 128 {
119 129 list_node_t *lold = &list->list_head;
120 130 list_insert_after_node(list, lold, object);
121 131 }
122 132
123 133 void
124 134 list_insert_tail(list_t *list, void *object)
125 135 {
126 136 list_node_t *lold = &list->list_head;
127 137 list_insert_before_node(list, lold, object);
128 138 }
129 139
130 140 void
131 141 list_remove(list_t *list, void *object)
132 142 {
133 143 list_node_t *lold = list_d2l(list, object);
134 144 ASSERT(!list_empty(list));
135 145 ASSERT(lold->list_next != NULL);
136 146 list_remove_node(lold);
137 147 }
138 148
139 149 void *
140 150 list_remove_head(list_t *list)
141 151 {
142 152 list_node_t *head = list->list_head.list_next;
143 153 if (head == &list->list_head)
144 154 return (NULL);
145 155 list_remove_node(head);
146 156 return (list_object(list, head));
147 157 }
148 158
149 159 void *
150 160 list_remove_tail(list_t *list)
151 161 {
152 162 list_node_t *tail = list->list_head.list_prev;
153 163 if (tail == &list->list_head)
154 164 return (NULL);
155 165 list_remove_node(tail);
156 166 return (list_object(list, tail));
157 167 }
158 168
159 169 void *
160 170 list_head(list_t *list)
161 171 {
162 172 if (list_empty(list))
163 173 return (NULL);
164 174 return (list_object(list, list->list_head.list_next));
165 175 }
166 176
167 177 void *
168 178 list_tail(list_t *list)
169 179 {
170 180 if (list_empty(list))
171 181 return (NULL);
172 182 return (list_object(list, list->list_head.list_prev));
173 183 }
174 184
175 185 void *
176 186 list_next(list_t *list, void *object)
177 187 {
178 188 list_node_t *node = list_d2l(list, object);
179 189
180 190 if (node->list_next != &list->list_head)
181 191 return (list_object(list, node->list_next));
182 192
183 193 return (NULL);
184 194 }
185 195
186 196 void *
187 197 list_prev(list_t *list, void *object)
188 198 {
189 199 list_node_t *node = list_d2l(list, object);
190 200
191 201 if (node->list_prev != &list->list_head)
192 202 return (list_object(list, node->list_prev));
193 203
194 204 return (NULL);
195 205 }
196 206
197 207 /*
198 208 * Insert src list after dst list. Empty src list thereafter.
199 209 */
200 210 void
201 211 list_move_tail(list_t *dst, list_t *src)
202 212 {
203 213 list_node_t *dstnode = &dst->list_head;
204 214 list_node_t *srcnode = &src->list_head;
205 215
206 216 ASSERT(dst->list_size == src->list_size);
207 217 ASSERT(dst->list_offset == src->list_offset);
208 218
209 219 if (list_empty(src))
210 220 return;
211 221
212 222 dstnode->list_prev->list_next = srcnode->list_next;
213 223 srcnode->list_next->list_prev = dstnode->list_prev;
214 224 dstnode->list_prev = srcnode->list_prev;
215 225 srcnode->list_prev->list_next = dstnode;
216 226
217 227 /* empty src list */
218 228 srcnode->list_next = srcnode->list_prev = srcnode;
219 229 }
220 230
221 231 void
222 232 list_link_replace(list_node_t *lold, list_node_t *lnew)
223 233 {
224 234 ASSERT(list_link_active(lold));
225 235 ASSERT(!list_link_active(lnew));
226 236
227 237 lnew->list_next = lold->list_next;
228 238 lnew->list_prev = lold->list_prev;
229 239 lold->list_prev->list_next = lnew;
230 240 lold->list_next->list_prev = lnew;
231 241 lold->list_next = lold->list_prev = NULL;
232 242 }
233 243
234 244 void
235 245 list_link_init(list_node_t *link)
236 246 {
237 247 link->list_next = NULL;
238 248 link->list_prev = NULL;
239 249 }
240 250
241 251 int
242 252 list_link_active(list_node_t *link)
243 253 {
244 254 return (link->list_next != NULL);
245 255 }
246 256
247 257 int
248 258 list_is_empty(list_t *list)
249 259 {
250 260 return (list_empty(list));
251 261 }
|
↓ open down ↓ |
200 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX