os/ossrv/genericopenlibs/openenvcore/include/sys/queue.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/include/sys/queue.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,548 @@
     1.4 +/*-
     1.5 + * Copyright (c) 1991, 1993
     1.6 + *	The Regents of the University of California.  All rights reserved.
     1.7 + *
     1.8 + * Redistribution and use in source and binary forms, with or without
     1.9 + * modification, are permitted provided that the following conditions
    1.10 + * are met:
    1.11 + * 1. Redistributions of source code must retain the above copyright
    1.12 + *    notice, this list of conditions and the following disclaimer.
    1.13 + * 2. Redistributions in binary form must reproduce the above copyright
    1.14 + *    notice, this list of conditions and the following disclaimer in the
    1.15 + *    documentation and/or other materials provided with the distribution.
    1.16 + * 4. Neither the name of the University nor the names of its contributors
    1.17 + *    may be used to endorse or promote products derived from this software
    1.18 + *    without specific prior written permission.
    1.19 + *
    1.20 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    1.21 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.22 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.23 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    1.24 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    1.25 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    1.26 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.27 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    1.28 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    1.29 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.30 + * SUCH DAMAGE.
    1.31 + * © * © * Portions Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
    1.32 + *	@(#)queue.h	8.5 (Berkeley) 8/20/94
    1.33 + * $FreeBSD: src/sys/sys/queue.h,v 1.60.2.1 2005/08/16 22:41:39 phk Exp $
    1.34 + */
    1.35 +
    1.36 +#ifndef _SYS_QUEUE_H_
    1.37 +#define	_SYS_QUEUE_H_
    1.38 +
    1.39 +#include <sys/cdefs.h>
    1.40 +
    1.41 +/*
    1.42 + * This file defines four types of data structures: singly-linked lists,
    1.43 + * singly-linked tail queues, lists and tail queues.
    1.44 + *
    1.45 + * A singly-linked list is headed by a single forward pointer. The elements
    1.46 + * are singly linked for minimum space and pointer manipulation overhead at
    1.47 + * the expense of O(n) removal for arbitrary elements. New elements can be
    1.48 + * added to the list after an existing element or at the head of the list.
    1.49 + * Elements being removed from the head of the list should use the explicit
    1.50 + * macro for this purpose for optimum efficiency. A singly-linked list may
    1.51 + * only be traversed in the forward direction.  Singly-linked lists are ideal
    1.52 + * for applications with large datasets and few or no removals or for
    1.53 + * implementing a LIFO queue.
    1.54 + *
    1.55 + * A singly-linked tail queue is headed by a pair of pointers, one to the
    1.56 + * head of the list and the other to the tail of the list. The elements are
    1.57 + * singly linked for minimum space and pointer manipulation overhead at the
    1.58 + * expense of O(n) removal for arbitrary elements. New elements can be added
    1.59 + * to the list after an existing element, at the head of the list, or at the
    1.60 + * end of the list. Elements being removed from the head of the tail queue
    1.61 + * should use the explicit macro for this purpose for optimum efficiency.
    1.62 + * A singly-linked tail queue may only be traversed in the forward direction.
    1.63 + * Singly-linked tail queues are ideal for applications with large datasets
    1.64 + * and few or no removals or for implementing a FIFO queue.
    1.65 + *
    1.66 + * A list is headed by a single forward pointer (or an array of forward
    1.67 + * pointers for a hash table header). The elements are doubly linked
    1.68 + * so that an arbitrary element can be removed without a need to
    1.69 + * traverse the list. New elements can be added to the list before
    1.70 + * or after an existing element or at the head of the list. A list
    1.71 + * may only be traversed in the forward direction.
    1.72 + *
    1.73 + * A tail queue is headed by a pair of pointers, one to the head of the
    1.74 + * list and the other to the tail of the list. The elements are doubly
    1.75 + * linked so that an arbitrary element can be removed without a need to
    1.76 + * traverse the list. New elements can be added to the list before or
    1.77 + * after an existing element, at the head of the list, or at the end of
    1.78 + * the list. A tail queue may be traversed in either direction.
    1.79 + *
    1.80 + * For details on the use of these macros, see the queue(3) manual page.
    1.81 + *
    1.82 + *
    1.83 + *				SLIST	LIST	STAILQ	TAILQ
    1.84 + * _HEAD			+	+	+	+
    1.85 + * _HEAD_INITIALIZER		+	+	+	+
    1.86 + * _ENTRY			+	+	+	+
    1.87 + * _INIT			+	+	+	+
    1.88 + * _EMPTY			+	+	+	+
    1.89 + * _FIRST			+	+	+	+
    1.90 + * _NEXT			+	+	+	+
    1.91 + * _PREV			-	-	-	+
    1.92 + * _LAST			-	-	+	+
    1.93 + * _FOREACH			+	+	+	+
    1.94 + * _FOREACH_SAFE		+	+	+	+
    1.95 + * _FOREACH_REVERSE		-	-	-	+
    1.96 + * _FOREACH_REVERSE_SAFE	-	-	-	+
    1.97 + * _INSERT_HEAD			+	+	+	+
    1.98 + * _INSERT_BEFORE		-	+	-	+
    1.99 + * _INSERT_AFTER		+	+	+	+
   1.100 + * _INSERT_TAIL			-	-	+	+
   1.101 + * _CONCAT			-	-	+	+
   1.102 + * _REMOVE_HEAD			+	-	+	-
   1.103 + * _REMOVE			+	+	+	+
   1.104 + *
   1.105 + */
   1.106 +#define	QUEUE_MACRO_DEBUG 0
   1.107 +#if QUEUE_MACRO_DEBUG
   1.108 +/* Store the last 2 places the queue element or head was altered */
   1.109 +struct qm_trace {
   1.110 +	char * lastfile;
   1.111 +	int lastline;
   1.112 +	char * prevfile;
   1.113 +	int prevline;
   1.114 +};
   1.115 +
   1.116 +#define	TRACEBUF	struct qm_trace trace;
   1.117 +#define	TRASHIT(x)	do {(x) = (void *)-1;} while (0)
   1.118 +
   1.119 +#define	QMD_TRACE_HEAD(head) do {					\
   1.120 +	(head)->trace.prevline = (head)->trace.lastline;		\
   1.121 +	(head)->trace.prevfile = (head)->trace.lastfile;		\
   1.122 +	(head)->trace.lastline = __LINE__;				\
   1.123 +	(head)->trace.lastfile = __FILE__;				\
   1.124 +} while (0)
   1.125 +
   1.126 +#define	QMD_TRACE_ELEM(elem) do {					\
   1.127 +	(elem)->trace.prevline = (elem)->trace.lastline;		\
   1.128 +	(elem)->trace.prevfile = (elem)->trace.lastfile;		\
   1.129 +	(elem)->trace.lastline = __LINE__;				\
   1.130 +	(elem)->trace.lastfile = __FILE__;				\
   1.131 +} while (0)
   1.132 +
   1.133 +#else
   1.134 +#define	QMD_TRACE_ELEM(elem)
   1.135 +#define	QMD_TRACE_HEAD(head)
   1.136 +#define	TRACEBUF
   1.137 +#define	TRASHIT(x)
   1.138 +#endif	/* QUEUE_MACRO_DEBUG */
   1.139 +
   1.140 +/*
   1.141 + * Singly-linked List declarations.
   1.142 + */
   1.143 +#define	SLIST_HEAD(name, type)						\
   1.144 +struct name {								\
   1.145 +	struct type *slh_first;	/* first element */			\
   1.146 +}
   1.147 +
   1.148 +#define	SLIST_HEAD_INITIALIZER(head)					\
   1.149 +	{ NULL }
   1.150 +
   1.151 +#define	SLIST_ENTRY(type)						\
   1.152 +struct {								\
   1.153 +	struct type *sle_next;	/* next element */			\
   1.154 +}
   1.155 +
   1.156 +/*
   1.157 + * Singly-linked List functions.
   1.158 + */
   1.159 +#define	SLIST_EMPTY(head)	((head)->slh_first == NULL)
   1.160 +
   1.161 +#define	SLIST_FIRST(head)	((head)->slh_first)
   1.162 +
   1.163 +#define	SLIST_FOREACH(var, head, field)					\
   1.164 +	for ((var) = SLIST_FIRST((head));				\
   1.165 +	    (var);							\
   1.166 +	    (var) = SLIST_NEXT((var), field))
   1.167 +
   1.168 +#define	SLIST_FOREACH_SAFE(var, head, field, tvar)			\
   1.169 +	for ((var) = SLIST_FIRST((head));				\
   1.170 +	    (var) && ((tvar) = SLIST_NEXT((var), field), 1);		\
   1.171 +	    (var) = (tvar))
   1.172 +
   1.173 +#define	SLIST_FOREACH_PREVPTR(var, varp, head, field)			\
   1.174 +	for ((varp) = &SLIST_FIRST((head));				\
   1.175 +	    ((var) = *(varp)) != NULL;					\
   1.176 +	    (varp) = &SLIST_NEXT((var), field))
   1.177 +
   1.178 +#define	SLIST_INIT(head) do {						\
   1.179 +	SLIST_FIRST((head)) = NULL;					\
   1.180 +} while (0)
   1.181 +
   1.182 +#define	SLIST_INSERT_AFTER(slistelm, elm, field) do {			\
   1.183 +	SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field);	\
   1.184 +	SLIST_NEXT((slistelm), field) = (elm);				\
   1.185 +} while (0)
   1.186 +
   1.187 +#define	SLIST_INSERT_HEAD(head, elm, field) do {			\
   1.188 +	SLIST_NEXT((elm), field) = SLIST_FIRST((head));			\
   1.189 +	SLIST_FIRST((head)) = (elm);					\
   1.190 +} while (0)
   1.191 +
   1.192 +#define	SLIST_NEXT(elm, field)	((elm)->field.sle_next)
   1.193 +
   1.194 +#define	SLIST_REMOVE(head, elm, type, field) do {			\
   1.195 +	if (SLIST_FIRST((head)) == (elm)) {				\
   1.196 +		SLIST_REMOVE_HEAD((head), field);			\
   1.197 +	}								\
   1.198 +	else {								\
   1.199 +		struct type *curelm = SLIST_FIRST((head));		\
   1.200 +		while (SLIST_NEXT(curelm, field) != (elm))		\
   1.201 +			curelm = SLIST_NEXT(curelm, field);		\
   1.202 +		SLIST_NEXT(curelm, field) =				\
   1.203 +		    SLIST_NEXT(SLIST_NEXT(curelm, field), field);	\
   1.204 +	}								\
   1.205 +} while (0)
   1.206 +
   1.207 +#define	SLIST_REMOVE_HEAD(head, field) do {				\
   1.208 +	SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field);	\
   1.209 +} while (0)
   1.210 +
   1.211 +/*
   1.212 + * Singly-linked Tail queue declarations.
   1.213 + */
   1.214 +#define	STAILQ_HEAD(name, type)						\
   1.215 +struct name {								\
   1.216 +	struct type *stqh_first;/* first element */			\
   1.217 +	struct type **stqh_last;/* addr of last next element */		\
   1.218 +}
   1.219 +
   1.220 +#define	STAILQ_HEAD_INITIALIZER(head)					\
   1.221 +	{ NULL, &(head).stqh_first }
   1.222 +
   1.223 +#define	STAILQ_ENTRY(type)						\
   1.224 +struct {								\
   1.225 +	struct type *stqe_next;	/* next element */			\
   1.226 +}
   1.227 +
   1.228 +/*
   1.229 + * Singly-linked Tail queue functions.
   1.230 + */
   1.231 +#define	STAILQ_CONCAT(head1, head2) do {				\
   1.232 +	if (!STAILQ_EMPTY((head2))) {					\
   1.233 +		*(head1)->stqh_last = (head2)->stqh_first;		\
   1.234 +		(head1)->stqh_last = (head2)->stqh_last;		\
   1.235 +		STAILQ_INIT((head2));					\
   1.236 +	}								\
   1.237 +} while (0)
   1.238 +
   1.239 +#define	STAILQ_EMPTY(head)	((head)->stqh_first == NULL)
   1.240 +
   1.241 +#define	STAILQ_FIRST(head)	((head)->stqh_first)
   1.242 +
   1.243 +#define	STAILQ_FOREACH(var, head, field)				\
   1.244 +	for((var) = STAILQ_FIRST((head));				\
   1.245 +	   (var);							\
   1.246 +	   (var) = STAILQ_NEXT((var), field))
   1.247 +
   1.248 +
   1.249 +#define	STAILQ_FOREACH_SAFE(var, head, field, tvar)			\
   1.250 +	for ((var) = STAILQ_FIRST((head));				\
   1.251 +	    (var) && ((tvar) = STAILQ_NEXT((var), field), 1);		\
   1.252 +	    (var) = (tvar))
   1.253 +
   1.254 +#define	STAILQ_INIT(head) do {						\
   1.255 +	STAILQ_FIRST((head)) = NULL;					\
   1.256 +	(head)->stqh_last = &STAILQ_FIRST((head));			\
   1.257 +} while (0)
   1.258 +
   1.259 +#define	STAILQ_INSERT_AFTER(head, tqelm, elm, field) do {		\
   1.260 +	if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
   1.261 +		(head)->stqh_last = &STAILQ_NEXT((elm), field);		\
   1.262 +	STAILQ_NEXT((tqelm), field) = (elm);				\
   1.263 +} while (0)
   1.264 +
   1.265 +#define	STAILQ_INSERT_HEAD(head, elm, field) do {			\
   1.266 +	if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL)	\
   1.267 +		(head)->stqh_last = &STAILQ_NEXT((elm), field);		\
   1.268 +	STAILQ_FIRST((head)) = (elm);					\
   1.269 +} while (0)
   1.270 +
   1.271 +#define	STAILQ_INSERT_TAIL(head, elm, field) do {			\
   1.272 +	STAILQ_NEXT((elm), field) = NULL;				\
   1.273 +	*(head)->stqh_last = (elm);					\
   1.274 +	(head)->stqh_last = &STAILQ_NEXT((elm), field);			\
   1.275 +} while (0)
   1.276 +
   1.277 +#define	STAILQ_LAST(head, type, field)					\
   1.278 +	(STAILQ_EMPTY((head)) ?						\
   1.279 +		NULL :							\
   1.280 +	        ((struct type *)					\
   1.281 +		((char *)((head)->stqh_last) - __offsetof(struct type, field))))
   1.282 +
   1.283 +#define	STAILQ_NEXT(elm, field)	((elm)->field.stqe_next)
   1.284 +
   1.285 +#define	STAILQ_REMOVE(head, elm, type, field) do {			\
   1.286 +	if (STAILQ_FIRST((head)) == (elm)) {				\
   1.287 +		STAILQ_REMOVE_HEAD((head), field);			\
   1.288 +	}								\
   1.289 +	else {								\
   1.290 +		struct type *curelm = STAILQ_FIRST((head));		\
   1.291 +		while (STAILQ_NEXT(curelm, field) != (elm))		\
   1.292 +			curelm = STAILQ_NEXT(curelm, field);		\
   1.293 +		if ((STAILQ_NEXT(curelm, field) =			\
   1.294 +		     STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\
   1.295 +			(head)->stqh_last = &STAILQ_NEXT((curelm), field);\
   1.296 +	}								\
   1.297 +} while (0)
   1.298 +
   1.299 +#define	STAILQ_REMOVE_HEAD(head, field) do {				\
   1.300 +	if ((STAILQ_FIRST((head)) =					\
   1.301 +	     STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL)		\
   1.302 +		(head)->stqh_last = &STAILQ_FIRST((head));		\
   1.303 +} while (0)
   1.304 +
   1.305 +#define	STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do {			\
   1.306 +	if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL)	\
   1.307 +		(head)->stqh_last = &STAILQ_FIRST((head));		\
   1.308 +} while (0)
   1.309 +
   1.310 +/*
   1.311 + * List declarations.
   1.312 + */
   1.313 +#define	LIST_HEAD(name, type)						\
   1.314 +struct name {								\
   1.315 +	struct type *lh_first;	/* first element */			\
   1.316 +}
   1.317 +
   1.318 +#define	LIST_HEAD_INITIALIZER(head)					\
   1.319 +	{ NULL }
   1.320 +
   1.321 +#define	LIST_ENTRY(type)						\
   1.322 +struct {								\
   1.323 +	struct type *le_next;	/* next element */			\
   1.324 +	struct type **le_prev;	/* address of previous next element */	\
   1.325 +}
   1.326 +
   1.327 +/*
   1.328 + * List functions.
   1.329 + */
   1.330 +
   1.331 +#define	LIST_EMPTY(head)	((head)->lh_first == NULL)
   1.332 +
   1.333 +#define	LIST_FIRST(head)	((head)->lh_first)
   1.334 +
   1.335 +#define	LIST_FOREACH(var, head, field)					\
   1.336 +	for ((var) = LIST_FIRST((head));				\
   1.337 +	    (var);							\
   1.338 +	    (var) = LIST_NEXT((var), field))
   1.339 +
   1.340 +#define	LIST_FOREACH_SAFE(var, head, field, tvar)			\
   1.341 +	for ((var) = LIST_FIRST((head));				\
   1.342 +	    (var) && ((tvar) = LIST_NEXT((var), field), 1);		\
   1.343 +	    (var) = (tvar))
   1.344 +
   1.345 +#define	LIST_INIT(head) do {						\
   1.346 +	LIST_FIRST((head)) = NULL;					\
   1.347 +} while (0)
   1.348 +
   1.349 +#define	LIST_INSERT_AFTER(listelm, elm, field) do {			\
   1.350 +	if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
   1.351 +		LIST_NEXT((listelm), field)->field.le_prev =		\
   1.352 +		    &LIST_NEXT((elm), field);				\
   1.353 +	LIST_NEXT((listelm), field) = (elm);				\
   1.354 +	(elm)->field.le_prev = &LIST_NEXT((listelm), field);		\
   1.355 +} while (0)
   1.356 +
   1.357 +#define	LIST_INSERT_BEFORE(listelm, elm, field) do {			\
   1.358 +	(elm)->field.le_prev = (listelm)->field.le_prev;		\
   1.359 +	LIST_NEXT((elm), field) = (listelm);				\
   1.360 +	*(listelm)->field.le_prev = (elm);				\
   1.361 +	(listelm)->field.le_prev = &LIST_NEXT((elm), field);		\
   1.362 +} while (0)
   1.363 +
   1.364 +#define	LIST_INSERT_HEAD(head, elm, field) do {				\
   1.365 +	if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL)	\
   1.366 +		LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
   1.367 +	LIST_FIRST((head)) = (elm);					\
   1.368 +	(elm)->field.le_prev = &LIST_FIRST((head));			\
   1.369 +} while (0)
   1.370 +
   1.371 +#define	LIST_NEXT(elm, field)	((elm)->field.le_next)
   1.372 +
   1.373 +#define	LIST_REMOVE(elm, field) do {					\
   1.374 +	if (LIST_NEXT((elm), field) != NULL)				\
   1.375 +		LIST_NEXT((elm), field)->field.le_prev = 		\
   1.376 +		    (elm)->field.le_prev;				\
   1.377 +	*(elm)->field.le_prev = LIST_NEXT((elm), field);		\
   1.378 +} while (0)
   1.379 +
   1.380 +/*
   1.381 + * Tail queue declarations.
   1.382 + */
   1.383 +#define	TAILQ_HEAD(name, type)						\
   1.384 +struct name {								\
   1.385 +	struct type *tqh_first;	/* first element */			\
   1.386 +	struct type **tqh_last;	/* addr of last next element */		\
   1.387 +	TRACEBUF							\
   1.388 +}
   1.389 +
   1.390 +#define	TAILQ_HEAD_INITIALIZER(head)					\
   1.391 +	{ NULL, &(head).tqh_first }
   1.392 +
   1.393 +#define	TAILQ_ENTRY(type)						\
   1.394 +struct {								\
   1.395 +	struct type *tqe_next;	/* next element */			\
   1.396 +	struct type **tqe_prev;	/* address of previous next element */	\
   1.397 +	TRACEBUF							\
   1.398 +}
   1.399 +
   1.400 +/*
   1.401 + * Tail queue functions.
   1.402 + */
   1.403 +#define	TAILQ_CONCAT(head1, head2, field) do {				\
   1.404 +	if (!TAILQ_EMPTY(head2)) {					\
   1.405 +		*(head1)->tqh_last = (head2)->tqh_first;		\
   1.406 +		(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last;	\
   1.407 +		(head1)->tqh_last = (head2)->tqh_last;			\
   1.408 +		TAILQ_INIT((head2));					\
   1.409 +		QMD_TRACE_HEAD(head1);					\
   1.410 +		QMD_TRACE_HEAD(head2);					\
   1.411 +	}								\
   1.412 +} while (0)
   1.413 +
   1.414 +#define	TAILQ_EMPTY(head)	((head)->tqh_first == NULL)
   1.415 +
   1.416 +#define	TAILQ_FIRST(head)	((head)->tqh_first)
   1.417 +
   1.418 +#define	TAILQ_FOREACH(var, head, field)					\
   1.419 +	for ((var) = TAILQ_FIRST((head));				\
   1.420 +	    (var);							\
   1.421 +	    (var) = TAILQ_NEXT((var), field))
   1.422 +
   1.423 +#define	TAILQ_FOREACH_SAFE(var, head, field, tvar)			\
   1.424 +	for ((var) = TAILQ_FIRST((head));				\
   1.425 +	    (var) && ((tvar) = TAILQ_NEXT((var), field), 1);		\
   1.426 +	    (var) = (tvar))
   1.427 +
   1.428 +#define	TAILQ_FOREACH_REVERSE(var, head, headname, field)		\
   1.429 +	for ((var) = TAILQ_LAST((head), headname);			\
   1.430 +	    (var);							\
   1.431 +	    (var) = TAILQ_PREV((var), headname, field))
   1.432 +
   1.433 +#define	TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar)	\
   1.434 +	for ((var) = TAILQ_LAST((head), headname);			\
   1.435 +	    (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1);	\
   1.436 +	    (var) = (tvar))
   1.437 +
   1.438 +#define	TAILQ_INIT(head) do {						\
   1.439 +	TAILQ_FIRST((head)) = NULL;					\
   1.440 +	(head)->tqh_last = &TAILQ_FIRST((head));			\
   1.441 +	QMD_TRACE_HEAD(head);						\
   1.442 +} while (0)
   1.443 +
   1.444 +#define	TAILQ_INSERT_AFTER(head, listelm, elm, field) do {		\
   1.445 +	if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
   1.446 +		TAILQ_NEXT((elm), field)->field.tqe_prev = 		\
   1.447 +		    &TAILQ_NEXT((elm), field);				\
   1.448 +	else {								\
   1.449 +		(head)->tqh_last = &TAILQ_NEXT((elm), field);		\
   1.450 +		QMD_TRACE_HEAD(head);					\
   1.451 +	}								\
   1.452 +	TAILQ_NEXT((listelm), field) = (elm);				\
   1.453 +	(elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field);		\
   1.454 +	QMD_TRACE_ELEM(&(elm)->field);					\
   1.455 +	QMD_TRACE_ELEM(&listelm->field);				\
   1.456 +} while (0)
   1.457 +
   1.458 +#define	TAILQ_INSERT_BEFORE(listelm, elm, field) do {			\
   1.459 +	(elm)->field.tqe_prev = (listelm)->field.tqe_prev;		\
   1.460 +	TAILQ_NEXT((elm), field) = (listelm);				\
   1.461 +	*(listelm)->field.tqe_prev = (elm);				\
   1.462 +	(listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field);		\
   1.463 +	QMD_TRACE_ELEM(&(elm)->field);					\
   1.464 +	QMD_TRACE_ELEM(&listelm->field);				\
   1.465 +} while (0)
   1.466 +
   1.467 +#define	TAILQ_INSERT_HEAD(head, elm, field) do {			\
   1.468 +	if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL)	\
   1.469 +		TAILQ_FIRST((head))->field.tqe_prev =			\
   1.470 +		    &TAILQ_NEXT((elm), field);				\
   1.471 +	else								\
   1.472 +		(head)->tqh_last = &TAILQ_NEXT((elm), field);		\
   1.473 +	TAILQ_FIRST((head)) = (elm);					\
   1.474 +	(elm)->field.tqe_prev = &TAILQ_FIRST((head));			\
   1.475 +	QMD_TRACE_HEAD(head);						\
   1.476 +	QMD_TRACE_ELEM(&(elm)->field);					\
   1.477 +} while (0)
   1.478 +
   1.479 +#define	TAILQ_INSERT_TAIL(head, elm, field) do {			\
   1.480 +	TAILQ_NEXT((elm), field) = NULL;				\
   1.481 +	(elm)->field.tqe_prev = (head)->tqh_last;			\
   1.482 +	*(head)->tqh_last = (elm);					\
   1.483 +	(head)->tqh_last = &TAILQ_NEXT((elm), field);			\
   1.484 +	QMD_TRACE_HEAD(head);						\
   1.485 +	QMD_TRACE_ELEM(&(elm)->field);					\
   1.486 +} while (0)
   1.487 +
   1.488 +#define	TAILQ_LAST(head, headname)					\
   1.489 +	(*(((struct headname *)((head)->tqh_last))->tqh_last))
   1.490 +
   1.491 +#define	TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
   1.492 +
   1.493 +#define	TAILQ_PREV(elm, headname, field)				\
   1.494 +	(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
   1.495 +
   1.496 +#define	TAILQ_REMOVE(head, elm, field) do {				\
   1.497 +	if ((TAILQ_NEXT((elm), field)) != NULL)				\
   1.498 +		TAILQ_NEXT((elm), field)->field.tqe_prev = 		\
   1.499 +		    (elm)->field.tqe_prev;				\
   1.500 +	else {								\
   1.501 +		(head)->tqh_last = (elm)->field.tqe_prev;		\
   1.502 +		QMD_TRACE_HEAD(head);					\
   1.503 +	}								\
   1.504 +	*(elm)->field.tqe_prev = TAILQ_NEXT((elm), field);		\
   1.505 +	TRASHIT((elm)->field.tqe_next);					\
   1.506 +	TRASHIT((elm)->field.tqe_prev);					\
   1.507 +	QMD_TRACE_ELEM(&(elm)->field);					\
   1.508 +} while (0)
   1.509 +
   1.510 +
   1.511 +#ifdef _KERNEL
   1.512 +
   1.513 +/*
   1.514 + * XXX insque() and remque() are an old way of handling certain queues.
   1.515 + * They bogusly assumes that all queue heads look alike.
   1.516 + */
   1.517 +
   1.518 +struct quehead {
   1.519 +	struct quehead *qh_link;
   1.520 +	struct quehead *qh_rlink;
   1.521 +};
   1.522 +
   1.523 +#ifdef __CC_SUPPORTS___INLINE
   1.524 +
   1.525 +static __inline void
   1.526 +insque(void *a, void *b)
   1.527 +{
   1.528 +	struct quehead *element = (struct quehead *)a,
   1.529 +		 *head = (struct quehead *)b;
   1.530 +
   1.531 +	element->qh_link = head->qh_link;
   1.532 +	element->qh_rlink = head;
   1.533 +	head->qh_link = element;
   1.534 +	element->qh_link->qh_rlink = element;
   1.535 +}
   1.536 +
   1.537 +static __inline void
   1.538 +remque(void *a)
   1.539 +{
   1.540 +	struct quehead *element = (struct quehead *)a;
   1.541 +
   1.542 +	element->qh_link->qh_rlink = element->qh_rlink;
   1.543 +	element->qh_rlink->qh_link = element->qh_link;
   1.544 +	element->qh_rlink = 0;
   1.545 +}
   1.546 +
   1.547 +#endif /* __CC_SUPPORTS___INLINE */
   1.548 +
   1.549 +#endif /* _KERNEL */
   1.550 +
   1.551 +#endif /* !_SYS_QUEUE_H_ */