Print this page
XXXX adding PID information to netstat output
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>
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 41 extern list_node_t *list_d2l(list_t *list, void *obj);
42 42 #else
43 43 #define list_d2l(a, obj) ((list_node_t *)(((char *)obj) + (a)->list_offset))
44 44 #endif
45 45 #define list_object(a, node) ((void *)(((char *)node) - (a)->list_offset))
46 46 #define list_empty(a) ((a)->list_head.list_next == &(a)->list_head)
47 47
48 48 #define list_insert_after_node(list, node, object) { \
49 49 list_node_t *lnew = list_d2l(list, object); \
50 50 lnew->list_prev = (node); \
51 51 lnew->list_next = (node)->list_next; \
52 52 (node)->list_next->list_prev = lnew; \
53 53 (node)->list_next = lnew; \
54 54 }
55 55
56 56 #define list_insert_before_node(list, node, object) { \
57 57 list_node_t *lnew = list_d2l(list, object); \
58 58 lnew->list_next = (node); \
59 59 lnew->list_prev = (node)->list_prev; \
60 60 (node)->list_prev->list_next = lnew; \
61 61 (node)->list_prev = lnew; \
62 62 }
63 63
64 64 #define list_remove_node(node) \
65 65 (node)->list_prev->list_next = (node)->list_next; \
66 66 (node)->list_next->list_prev = (node)->list_prev; \
67 67 (node)->list_next = (node)->list_prev = NULL
↓ open down ↓ |
67 lines elided |
↑ open up ↑ |
68 68
69 69 void
70 70 list_create(list_t *list, size_t size, size_t offset)
71 71 {
72 72 ASSERT(list);
73 73 ASSERT(size > 0);
74 74 ASSERT(size >= offset + sizeof (list_node_t));
75 75
76 76 list->list_size = size;
77 77 list->list_offset = offset;
78 + list->list_numnodes = 0;
78 79 list->list_head.list_next = list->list_head.list_prev =
79 80 &list->list_head;
80 81 }
81 82
82 83 void
83 84 list_destroy(list_t *list)
84 85 {
85 86 list_node_t *node = &list->list_head;
86 87
87 88 ASSERT(list);
88 89 ASSERT(list->list_head.list_next == node);
89 90 ASSERT(list->list_head.list_prev == node);
90 91
92 + list->list_numnodes = 0;
91 93 node->list_next = node->list_prev = NULL;
92 94 }
93 95
94 96 void
95 97 list_insert_after(list_t *list, void *object, void *nobject)
96 98 {
97 99 if (object == NULL) {
98 100 list_insert_head(list, nobject);
99 101 } else {
100 102 list_node_t *lold = list_d2l(list, object);
101 103 list_insert_after_node(list, lold, nobject);
102 104 }
103 105 }
104 106
105 107 void
106 108 list_insert_before(list_t *list, void *object, void *nobject)
107 109 {
108 110 if (object == NULL) {
109 111 list_insert_tail(list, nobject);
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
110 112 } else {
111 113 list_node_t *lold = list_d2l(list, object);
112 114 list_insert_before_node(list, lold, nobject);
113 115 }
114 116 }
115 117
116 118 void
117 119 list_insert_head(list_t *list, void *object)
118 120 {
119 121 list_node_t *lold = &list->list_head;
122 + list->list_numnodes++;
120 123 list_insert_after_node(list, lold, object);
121 124 }
122 125
123 126 void
124 127 list_insert_tail(list_t *list, void *object)
125 128 {
126 129 list_node_t *lold = &list->list_head;
130 + list->list_numnodes++;
127 131 list_insert_before_node(list, lold, object);
128 132 }
129 133
130 134 void
131 135 list_remove(list_t *list, void *object)
132 136 {
133 137 list_node_t *lold = list_d2l(list, object);
134 138 ASSERT(!list_empty(list));
135 139 ASSERT(lold->list_next != NULL);
140 + list->list_numnodes--;
136 141 list_remove_node(lold);
137 142 }
138 143
139 144 void *
140 145 list_remove_head(list_t *list)
141 146 {
142 147 list_node_t *head = list->list_head.list_next;
143 148 if (head == &list->list_head)
144 149 return (NULL);
150 + list->list_numnodes--;
145 151 list_remove_node(head);
146 152 return (list_object(list, head));
147 153 }
148 154
149 155 void *
150 156 list_remove_tail(list_t *list)
151 157 {
152 158 list_node_t *tail = list->list_head.list_prev;
153 159 if (tail == &list->list_head)
154 160 return (NULL);
161 + list->list_numnodes--;
155 162 list_remove_node(tail);
156 163 return (list_object(list, tail));
157 164 }
158 165
159 166 void *
160 167 list_head(list_t *list)
161 168 {
162 169 if (list_empty(list))
163 170 return (NULL);
164 171 return (list_object(list, list->list_head.list_next));
165 172 }
166 173
167 174 void *
168 175 list_tail(list_t *list)
169 176 {
170 177 if (list_empty(list))
171 178 return (NULL);
172 179 return (list_object(list, list->list_head.list_prev));
173 180 }
174 181
175 182 void *
176 183 list_next(list_t *list, void *object)
177 184 {
178 185 list_node_t *node = list_d2l(list, object);
179 186
180 187 if (node->list_next != &list->list_head)
181 188 return (list_object(list, node->list_next));
182 189
183 190 return (NULL);
184 191 }
185 192
186 193 void *
187 194 list_prev(list_t *list, void *object)
188 195 {
189 196 list_node_t *node = list_d2l(list, object);
190 197
191 198 if (node->list_prev != &list->list_head)
192 199 return (list_object(list, node->list_prev));
193 200
194 201 return (NULL);
195 202 }
196 203
197 204 /*
198 205 * Insert src list after dst list. Empty src list thereafter.
199 206 */
200 207 void
201 208 list_move_tail(list_t *dst, list_t *src)
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
202 209 {
203 210 list_node_t *dstnode = &dst->list_head;
204 211 list_node_t *srcnode = &src->list_head;
205 212
206 213 ASSERT(dst->list_size == src->list_size);
207 214 ASSERT(dst->list_offset == src->list_offset);
208 215
209 216 if (list_empty(src))
210 217 return;
211 218
219 + dst->list_numnodes += src->list_numnodes;
212 220 dstnode->list_prev->list_next = srcnode->list_next;
213 221 srcnode->list_next->list_prev = dstnode->list_prev;
214 222 dstnode->list_prev = srcnode->list_prev;
215 223 srcnode->list_prev->list_next = dstnode;
216 224
217 225 /* empty src list */
226 + src->list_numnodes = 0;
218 227 srcnode->list_next = srcnode->list_prev = srcnode;
219 228 }
220 229
221 230 void
222 231 list_link_replace(list_node_t *lold, list_node_t *lnew)
223 232 {
224 233 ASSERT(list_link_active(lold));
225 234 ASSERT(!list_link_active(lnew));
226 235
227 236 lnew->list_next = lold->list_next;
228 237 lnew->list_prev = lold->list_prev;
229 238 lold->list_prev->list_next = lnew;
230 239 lold->list_next->list_prev = lnew;
231 240 lold->list_next = lold->list_prev = NULL;
232 241 }
233 242
234 243 void
235 244 list_link_init(list_node_t *link)
236 245 {
237 246 link->list_next = NULL;
238 247 link->list_prev = NULL;
239 248 }
240 249
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
241 250 int
242 251 list_link_active(list_node_t *link)
243 252 {
244 253 return (link->list_next != NULL);
245 254 }
246 255
247 256 int
248 257 list_is_empty(list_t *list)
249 258 {
250 259 return (list_empty(list));
260 +}
261 +
262 +ulong_t
263 +list_numnodes(list_t *list)
264 +{
265 + /*
266 + size_t sz = 0;
267 + list_node_t *node;
268 +
269 + node = &list->list_head;
270 + while (node->list_next != &list->list_head) {
271 + sz++;
272 + node = node->list_next;
273 + }
274 + return (sz);
275 + */
276 + return (list->list_numnodes);
251 277 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX