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