Browse code

- FreeBSD macros that implement linked lists

Jan Janak authored on 29/03/2007 10:00:26
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,517 @@
0
+/*-
1
+ * Copyright (c) 1991, 1993
2
+ *	The Regents of the University of California.  All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions
6
+ * are met:
7
+ * 1. Redistributions of source code must retain the above copyright
8
+ *    notice, this list of conditions and the following disclaimer.
9
+ * 2. Redistributions in binary form must reproduce the above copyright
10
+ *    notice, this list of conditions and the following disclaimer in the
11
+ *    documentation and/or other materials provided with the distribution.
12
+ * 4. Neither the name of the University nor the names of its contributors
13
+ *    may be used to endorse or promote products derived from this software
14
+ *    without specific prior written permission.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
+ * SUCH DAMAGE.
27
+ *
28
+ *	@(#)queue.h	8.5 (Berkeley) 8/20/94
29
+ * $FreeBSD: /repoman/r/ncvs/src/sys/sys/queue.h,v 1.68 2006/10/24 11:20:29 ru Exp $
30
+ */
31
+
32
+#ifndef _LIST_H
33
+#define	_LIST_H
34
+
35
+#include <sys/cdefs.h>
36
+
37
+/*
38
+ * This file defines four types of data structures: singly-linked lists,
39
+ * singly-linked tail queues, lists and tail queues.
40
+ *
41
+ * A singly-linked list is headed by a single forward pointer. The elements
42
+ * are singly linked for minimum space and pointer manipulation overhead at
43
+ * the expense of O(n) removal for arbitrary elements. New elements can be
44
+ * added to the list after an existing element or at the head of the list.
45
+ * Elements being removed from the head of the list should use the explicit
46
+ * macro for this purpose for optimum efficiency. A singly-linked list may
47
+ * only be traversed in the forward direction.  Singly-linked lists are ideal
48
+ * for applications with large datasets and few or no removals or for
49
+ * implementing a LIFO queue.
50
+ *
51
+ * A singly-linked tail queue is headed by a pair of pointers, one to the
52
+ * head of the list and the other to the tail of the list. The elements are
53
+ * singly linked for minimum space and pointer manipulation overhead at the
54
+ * expense of O(n) removal for arbitrary elements. New elements can be added
55
+ * to the list after an existing element, at the head of the list, or at the
56
+ * end of the list. Elements being removed from the head of the tail queue
57
+ * should use the explicit macro for this purpose for optimum efficiency.
58
+ * A singly-linked tail queue may only be traversed in the forward direction.
59
+ * Singly-linked tail queues are ideal for applications with large datasets
60
+ * and few or no removals or for implementing a FIFO queue.
61
+ *
62
+ * A list is headed by a single forward pointer (or an array of forward
63
+ * pointers for a hash table header). The elements are doubly linked
64
+ * so that an arbitrary element can be removed without a need to
65
+ * traverse the list. New elements can be added to the list before
66
+ * or after an existing element or at the head of the list. A list
67
+ * may only be traversed in the forward direction.
68
+ *
69
+ * A tail queue is headed by a pair of pointers, one to the head of the
70
+ * list and the other to the tail of the list. The elements are doubly
71
+ * linked so that an arbitrary element can be removed without a need to
72
+ * traverse the list. New elements can be added to the list before or
73
+ * after an existing element, at the head of the list, or at the end of
74
+ * the list. A tail queue may be traversed in either direction.
75
+ *
76
+ * For details on the use of these macros, see the queue(3) manual page.
77
+ *
78
+ *
79
+ *				SLIST	LIST	STAILQ	TAILQ
80
+ * _HEAD			+	+	+	+
81
+ * _HEAD_INITIALIZER		+	+	+	+
82
+ * _ENTRY			+	+	+	+
83
+ * _INIT			+	+	+	+
84
+ * _EMPTY			+	+	+	+
85
+ * _FIRST			+	+	+	+
86
+ * _NEXT			+	+	+	+
87
+ * _PREV			-	-	-	+
88
+ * _LAST			-	-	+	+
89
+ * _FOREACH			+	+	+	+
90
+ * _FOREACH_SAFE		+	+	+	+
91
+ * _FOREACH_REVERSE		-	-	-	+
92
+ * _FOREACH_REVERSE_SAFE	-	-	-	+
93
+ * _INSERT_HEAD			+	+	+	+
94
+ * _INSERT_BEFORE		-	+	-	+
95
+ * _INSERT_AFTER		+	+	+	+
96
+ * _INSERT_TAIL			-	-	+	+
97
+ * _CONCAT			-	-	+	+
98
+ * _REMOVE_HEAD			+	-	+	-
99
+ * _REMOVE			+	+	+	+
100
+ *
101
+ */
102
+#ifdef QUEUE_MACRO_DEBUG
103
+/* Store the last 2 places the queue element or head was altered */
104
+struct qm_trace {
105
+	char * lastfile;
106
+	int lastline;
107
+	char * prevfile;
108
+	int prevline;
109
+};
110
+
111
+#define	TRACEBUF	struct qm_trace trace;
112
+#define	TRASHIT(x)	do {(x) = (void *)-1;} while (0)
113
+
114
+#define	QMD_TRACE_HEAD(head) do {					\
115
+	(head)->trace.prevline = (head)->trace.lastline;		\
116
+	(head)->trace.prevfile = (head)->trace.lastfile;		\
117
+	(head)->trace.lastline = __LINE__;				\
118
+	(head)->trace.lastfile = __FILE__;				\
119
+} while (0)
120
+
121
+#define	QMD_TRACE_ELEM(elem) do {					\
122
+	(elem)->trace.prevline = (elem)->trace.lastline;		\
123
+	(elem)->trace.prevfile = (elem)->trace.lastfile;		\
124
+	(elem)->trace.lastline = __LINE__;				\
125
+	(elem)->trace.lastfile = __FILE__;				\
126
+} while (0)
127
+
128
+#else
129
+#define	QMD_TRACE_ELEM(elem)
130
+#define	QMD_TRACE_HEAD(head)
131
+#define	TRACEBUF
132
+#define	TRASHIT(x)
133
+#endif	/* QUEUE_MACRO_DEBUG */
134
+
135
+/*
136
+ * Singly-linked List declarations.
137
+ */
138
+#define	SLIST_HEAD(name, type)						\
139
+struct name {								\
140
+	struct type *slh_first;	/* first element */			\
141
+}
142
+
143
+#define	SLIST_HEAD_INITIALIZER(head)					\
144
+	{ NULL }
145
+
146
+#define	SLIST_ENTRY(type)						\
147
+struct {								\
148
+	struct type *sle_next;	/* next element */			\
149
+}
150
+
151
+/*
152
+ * Singly-linked List functions.
153
+ */
154
+#define	SLIST_EMPTY(head)	((head)->slh_first == NULL)
155
+
156
+#define	SLIST_FIRST(head)	((head)->slh_first)
157
+
158
+#define	SLIST_FOREACH(var, head, field)					\
159
+	for ((var) = SLIST_FIRST((head));				\
160
+	    (var);							\
161
+	    (var) = SLIST_NEXT((var), field))
162
+
163
+#define	SLIST_FOREACH_SAFE(var, head, field, tvar)			\
164
+	for ((var) = SLIST_FIRST((head));				\
165
+	    (var) && ((tvar) = SLIST_NEXT((var), field), 1);		\
166
+	    (var) = (tvar))
167
+
168
+#define	SLIST_FOREACH_PREVPTR(var, varp, head, field)			\
169
+	for ((varp) = &SLIST_FIRST((head));				\
170
+	    ((var) = *(varp)) != NULL;					\
171
+	    (varp) = &SLIST_NEXT((var), field))
172
+
173
+#define	SLIST_INIT(head) do {						\
174
+	SLIST_FIRST((head)) = NULL;					\
175
+} while (0)
176
+
177
+#define	SLIST_INSERT_AFTER(slistelm, elm, field) do {			\
178
+	SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field);	\
179
+	SLIST_NEXT((slistelm), field) = (elm);				\
180
+} while (0)
181
+
182
+#define	SLIST_INSERT_HEAD(head, elm, field) do {			\
183
+	SLIST_NEXT((elm), field) = SLIST_FIRST((head));			\
184
+	SLIST_FIRST((head)) = (elm);					\
185
+} while (0)
186
+
187
+#define	SLIST_NEXT(elm, field)	((elm)->field.sle_next)
188
+
189
+#define	SLIST_REMOVE(head, elm, type, field) do {			\
190
+	if (SLIST_FIRST((head)) == (elm)) {				\
191
+		SLIST_REMOVE_HEAD((head), field);			\
192
+	}								\
193
+	else {								\
194
+		struct type *curelm = SLIST_FIRST((head));		\
195
+		while (SLIST_NEXT(curelm, field) != (elm))		\
196
+			curelm = SLIST_NEXT(curelm, field);		\
197
+		SLIST_NEXT(curelm, field) =				\
198
+		    SLIST_NEXT(SLIST_NEXT(curelm, field), field);	\
199
+	}								\
200
+	TRASHIT((elm)->field.sle_next);					\
201
+} while (0)
202
+
203
+#define	SLIST_REMOVE_HEAD(head, field) do {				\
204
+	SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field);	\
205
+} while (0)
206
+
207
+/*
208
+ * Singly-linked Tail queue declarations.
209
+ */
210
+#define	STAILQ_HEAD(name, type)						\
211
+struct name {								\
212
+	struct type *stqh_first;/* first element */			\
213
+	struct type **stqh_last;/* addr of last next element */		\
214
+}
215
+
216
+#define	STAILQ_HEAD_INITIALIZER(head)					\
217
+	{ NULL, &(head).stqh_first }
218
+
219
+#define	STAILQ_ENTRY(type)						\
220
+struct {								\
221
+	struct type *stqe_next;	/* next element */			\
222
+}
223
+
224
+/*
225
+ * Singly-linked Tail queue functions.
226
+ */
227
+#define	STAILQ_CONCAT(head1, head2) do {				\
228
+	if (!STAILQ_EMPTY((head2))) {					\
229
+		*(head1)->stqh_last = (head2)->stqh_first;		\
230
+		(head1)->stqh_last = (head2)->stqh_last;		\
231
+		STAILQ_INIT((head2));					\
232
+	}								\
233
+} while (0)
234
+
235
+#define	STAILQ_EMPTY(head)	((head)->stqh_first == NULL)
236
+
237
+#define	STAILQ_FIRST(head)	((head)->stqh_first)
238
+
239
+#define	STAILQ_FOREACH(var, head, field)				\
240
+	for((var) = STAILQ_FIRST((head));				\
241
+	   (var);							\
242
+	   (var) = STAILQ_NEXT((var), field))
243
+
244
+
245
+#define	STAILQ_FOREACH_SAFE(var, head, field, tvar)			\
246
+	for ((var) = STAILQ_FIRST((head));				\
247
+	    (var) && ((tvar) = STAILQ_NEXT((var), field), 1);		\
248
+	    (var) = (tvar))
249
+
250
+#define	STAILQ_INIT(head) do {						\
251
+	STAILQ_FIRST((head)) = NULL;					\
252
+	(head)->stqh_last = &STAILQ_FIRST((head));			\
253
+} while (0)
254
+
255
+#define	STAILQ_INSERT_AFTER(head, tqelm, elm, field) do {		\
256
+	if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
257
+		(head)->stqh_last = &STAILQ_NEXT((elm), field);		\
258
+	STAILQ_NEXT((tqelm), field) = (elm);				\
259
+} while (0)
260
+
261
+#define	STAILQ_INSERT_HEAD(head, elm, field) do {			\
262
+	if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL)	\
263
+		(head)->stqh_last = &STAILQ_NEXT((elm), field);		\
264
+	STAILQ_FIRST((head)) = (elm);					\
265
+} while (0)
266
+
267
+#define	STAILQ_INSERT_TAIL(head, elm, field) do {			\
268
+	STAILQ_NEXT((elm), field) = NULL;				\
269
+	*(head)->stqh_last = (elm);					\
270
+	(head)->stqh_last = &STAILQ_NEXT((elm), field);			\
271
+} while (0)
272
+
273
+#define	STAILQ_LAST(head, type, field)					\
274
+	(STAILQ_EMPTY((head)) ?						\
275
+		NULL :							\
276
+	        ((struct type *)(void *)				\
277
+		((char *)((head)->stqh_last) - __offsetof(struct type, field))))
278
+
279
+#define	STAILQ_NEXT(elm, field)	((elm)->field.stqe_next)
280
+
281
+#define	STAILQ_REMOVE(head, elm, type, field) do {			\
282
+	if (STAILQ_FIRST((head)) == (elm)) {				\
283
+		STAILQ_REMOVE_HEAD((head), field);			\
284
+	}								\
285
+	else {								\
286
+		struct type *curelm = STAILQ_FIRST((head));		\
287
+		while (STAILQ_NEXT(curelm, field) != (elm))		\
288
+			curelm = STAILQ_NEXT(curelm, field);		\
289
+		if ((STAILQ_NEXT(curelm, field) =			\
290
+		     STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\
291
+			(head)->stqh_last = &STAILQ_NEXT((curelm), field);\
292
+	}								\
293
+	TRASHIT((elm)->field.stqe_next);				\
294
+} while (0)
295
+
296
+#define	STAILQ_REMOVE_HEAD(head, field) do {				\
297
+	if ((STAILQ_FIRST((head)) =					\
298
+	     STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL)		\
299
+		(head)->stqh_last = &STAILQ_FIRST((head));		\
300
+} while (0)
301
+
302
+/*
303
+ * List declarations.
304
+ */
305
+#define	LIST_HEAD(name, type)						\
306
+struct name {								\
307
+	struct type *lh_first;	/* first element */			\
308
+}
309
+
310
+#define	LIST_HEAD_INITIALIZER(head)					\
311
+	{ NULL }
312
+
313
+#define	LIST_ENTRY(type)						\
314
+struct {								\
315
+	struct type *le_next;	/* next element */			\
316
+	struct type **le_prev;	/* address of previous next element */	\
317
+}
318
+
319
+/*
320
+ * List functions.
321
+ */
322
+
323
+#define	LIST_EMPTY(head)	((head)->lh_first == NULL)
324
+
325
+#define	LIST_FIRST(head)	((head)->lh_first)
326
+
327
+#define	LIST_FOREACH(var, head, field)					\
328
+	for ((var) = LIST_FIRST((head));				\
329
+	    (var);							\
330
+	    (var) = LIST_NEXT((var), field))
331
+
332
+#define	LIST_FOREACH_SAFE(var, head, field, tvar)			\
333
+	for ((var) = LIST_FIRST((head));				\
334
+	    (var) && ((tvar) = LIST_NEXT((var), field), 1);		\
335
+	    (var) = (tvar))
336
+
337
+#define	LIST_INIT(head) do {						\
338
+	LIST_FIRST((head)) = NULL;					\
339
+} while (0)
340
+
341
+#define	LIST_INSERT_AFTER(listelm, elm, field) do {			\
342
+	QMD_LIST_CHECK_NEXT(listelm, field);				\
343
+	if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
344
+		LIST_NEXT((listelm), field)->field.le_prev =		\
345
+		    &LIST_NEXT((elm), field);				\
346
+	LIST_NEXT((listelm), field) = (elm);				\
347
+	(elm)->field.le_prev = &LIST_NEXT((listelm), field);		\
348
+} while (0)
349
+
350
+#define	LIST_INSERT_BEFORE(listelm, elm, field) do {			\
351
+	QMD_LIST_CHECK_PREV(listelm, field);				\
352
+	(elm)->field.le_prev = (listelm)->field.le_prev;		\
353
+	LIST_NEXT((elm), field) = (listelm);				\
354
+	*(listelm)->field.le_prev = (elm);				\
355
+	(listelm)->field.le_prev = &LIST_NEXT((elm), field);		\
356
+} while (0)
357
+
358
+#define	LIST_INSERT_HEAD(head, elm, field) do {				\
359
+	QMD_LIST_CHECK_HEAD((head), field);				\
360
+	if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL)	\
361
+		LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
362
+	LIST_FIRST((head)) = (elm);					\
363
+	(elm)->field.le_prev = &LIST_FIRST((head));			\
364
+} while (0)
365
+
366
+#define	LIST_NEXT(elm, field)	((elm)->field.le_next)
367
+
368
+#define	LIST_REMOVE(elm, field) do {					\
369
+	QMD_LIST_CHECK_NEXT(elm, field);				\
370
+	QMD_LIST_CHECK_PREV(elm, field);				\
371
+	if (LIST_NEXT((elm), field) != NULL)				\
372
+		LIST_NEXT((elm), field)->field.le_prev = 		\
373
+		    (elm)->field.le_prev;				\
374
+	*(elm)->field.le_prev = LIST_NEXT((elm), field);		\
375
+	TRASHIT((elm)->field.le_next);					\
376
+	TRASHIT((elm)->field.le_prev);					\
377
+} while (0)
378
+
379
+/*
380
+ * Tail queue declarations.
381
+ */
382
+#define	TAILQ_HEAD(name, type)						\
383
+struct name {								\
384
+	struct type *tqh_first;	/* first element */			\
385
+	struct type **tqh_last;	/* addr of last next element */		\
386
+	TRACEBUF							\
387
+}
388
+
389
+#define	TAILQ_HEAD_INITIALIZER(head)					\
390
+	{ NULL, &(head).tqh_first }
391
+
392
+#define	TAILQ_ENTRY(type)						\
393
+struct {								\
394
+	struct type *tqe_next;	/* next element */			\
395
+	struct type **tqe_prev;	/* address of previous next element */	\
396
+	TRACEBUF							\
397
+}
398
+
399
+/*
400
+ * Tail queue functions.
401
+ */
402
+
403
+#define	TAILQ_CONCAT(head1, head2, field) do {				\
404
+	if (!TAILQ_EMPTY(head2)) {					\
405
+		*(head1)->tqh_last = (head2)->tqh_first;		\
406
+		(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last;	\
407
+		(head1)->tqh_last = (head2)->tqh_last;			\
408
+		TAILQ_INIT((head2));					\
409
+		QMD_TRACE_HEAD(head1);					\
410
+		QMD_TRACE_HEAD(head2);					\
411
+	}								\
412
+} while (0)
413
+
414
+#define	TAILQ_EMPTY(head)	((head)->tqh_first == NULL)
415
+
416
+#define	TAILQ_FIRST(head)	((head)->tqh_first)
417
+
418
+#define	TAILQ_FOREACH(var, head, field)					\
419
+	for ((var) = TAILQ_FIRST((head));				\
420
+	    (var);							\
421
+	    (var) = TAILQ_NEXT((var), field))
422
+
423
+#define	TAILQ_FOREACH_SAFE(var, head, field, tvar)			\
424
+	for ((var) = TAILQ_FIRST((head));				\
425
+	    (var) && ((tvar) = TAILQ_NEXT((var), field), 1);		\
426
+	    (var) = (tvar))
427
+
428
+#define	TAILQ_FOREACH_REVERSE(var, head, headname, field)		\
429
+	for ((var) = TAILQ_LAST((head), headname);			\
430
+	    (var);							\
431
+	    (var) = TAILQ_PREV((var), headname, field))
432
+
433
+#define	TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar)	\
434
+	for ((var) = TAILQ_LAST((head), headname);			\
435
+	    (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1);	\
436
+	    (var) = (tvar))
437
+
438
+#define	TAILQ_INIT(head) do {						\
439
+	TAILQ_FIRST((head)) = NULL;					\
440
+	(head)->tqh_last = &TAILQ_FIRST((head));			\
441
+	QMD_TRACE_HEAD(head);						\
442
+} while (0)
443
+
444
+#define	TAILQ_INSERT_AFTER(head, listelm, elm, field) do {		\
445
+	QMD_TAILQ_CHECK_NEXT(listelm, field);				\
446
+	if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
447
+		TAILQ_NEXT((elm), field)->field.tqe_prev = 		\
448
+		    &TAILQ_NEXT((elm), field);				\
449
+	else {								\
450
+		(head)->tqh_last = &TAILQ_NEXT((elm), field);		\
451
+		QMD_TRACE_HEAD(head);					\
452
+	}								\
453
+	TAILQ_NEXT((listelm), field) = (elm);				\
454
+	(elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field);		\
455
+	QMD_TRACE_ELEM(&(elm)->field);					\
456
+	QMD_TRACE_ELEM(&listelm->field);				\
457
+} while (0)
458
+
459
+#define	TAILQ_INSERT_BEFORE(listelm, elm, field) do {			\
460
+	QMD_TAILQ_CHECK_PREV(listelm, field);				\
461
+	(elm)->field.tqe_prev = (listelm)->field.tqe_prev;		\
462
+	TAILQ_NEXT((elm), field) = (listelm);				\
463
+	*(listelm)->field.tqe_prev = (elm);				\
464
+	(listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field);		\
465
+	QMD_TRACE_ELEM(&(elm)->field);					\
466
+	QMD_TRACE_ELEM(&listelm->field);				\
467
+} while (0)
468
+
469
+#define	TAILQ_INSERT_HEAD(head, elm, field) do {			\
470
+	QMD_TAILQ_CHECK_HEAD(head, field);				\
471
+	if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL)	\
472
+		TAILQ_FIRST((head))->field.tqe_prev =			\
473
+		    &TAILQ_NEXT((elm), field);				\
474
+	else								\
475
+		(head)->tqh_last = &TAILQ_NEXT((elm), field);		\
476
+	TAILQ_FIRST((head)) = (elm);					\
477
+	(elm)->field.tqe_prev = &TAILQ_FIRST((head));			\
478
+	QMD_TRACE_HEAD(head);						\
479
+	QMD_TRACE_ELEM(&(elm)->field);					\
480
+} while (0)
481
+
482
+#define	TAILQ_INSERT_TAIL(head, elm, field) do {			\
483
+	QMD_TAILQ_CHECK_TAIL(head, field);				\
484
+	TAILQ_NEXT((elm), field) = NULL;				\
485
+	(elm)->field.tqe_prev = (head)->tqh_last;			\
486
+	*(head)->tqh_last = (elm);					\
487
+	(head)->tqh_last = &TAILQ_NEXT((elm), field);			\
488
+	QMD_TRACE_HEAD(head);						\
489
+	QMD_TRACE_ELEM(&(elm)->field);					\
490
+} while (0)
491
+
492
+#define	TAILQ_LAST(head, headname)					\
493
+	(*(((struct headname *)((head)->tqh_last))->tqh_last))
494
+
495
+#define	TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
496
+
497
+#define	TAILQ_PREV(elm, headname, field)				\
498
+	(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
499
+
500
+#define	TAILQ_REMOVE(head, elm, field) do {				\
501
+	QMD_TAILQ_CHECK_NEXT(elm, field);				\
502
+	QMD_TAILQ_CHECK_PREV(elm, field);				\
503
+	if ((TAILQ_NEXT((elm), field)) != NULL)				\
504
+		TAILQ_NEXT((elm), field)->field.tqe_prev = 		\
505
+		    (elm)->field.tqe_prev;				\
506
+	else {								\
507
+		(head)->tqh_last = (elm)->field.tqe_prev;		\
508
+		QMD_TRACE_HEAD(head);					\
509
+	}								\
510
+	*(elm)->field.tqe_prev = TAILQ_NEXT((elm), field);		\
511
+	TRASHIT((elm)->field.tqe_next);					\
512
+	TRASHIT((elm)->field.tqe_prev);					\
513
+	QMD_TRACE_ELEM(&(elm)->field);					\
514
+} while (0)
515
+
516
+#endif /* !_LIST_H */