queue.h revision 15809
18876Srgrimes/*
21541Srgrimes * Copyright (c) 1991, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
3314492Shsu *	@(#)queue.h	8.5 (Berkeley) 8/20/94
3415809Sdyson * $Id: queue.h,v 1.9 1996/04/08 07:51:57 phk Exp $
351541Srgrimes */
361541Srgrimes
3712592Sbde#ifndef _SYS_QUEUE_H_
381541Srgrimes#define	_SYS_QUEUE_H_
391541Srgrimes
401541Srgrimes/*
4114940Sgibbs * This file defines five types of data structures: singly-linked lists,
4214940Sgibbs * slingly-linked tail queues, lists, tail queues, and circular queues.
431541Srgrimes *
4414940Sgibbs * A singly-linked list is headed by a single forward pointer. The elements
4514940Sgibbs * are singly linked for minimum space and pointer manipulation overhead at
4614940Sgibbs * the expense of O(n) removal for arbitrary elements. New elements can be
4714940Sgibbs * added to the list after an existing element or at the head of the list.
4814940Sgibbs * Elements being removed from the head of the list should use the explicit
4914940Sgibbs * macro for this purpose for optimum efficiency. A singly-linked list may
5014940Sgibbs * only be traversed in the forward direction.  Singly-linked lists are ideal
5114940Sgibbs * for applications with large datasets and few or no removals or for
5214940Sgibbs * implementing a LIFO queue.
5314940Sgibbs *
5414940Sgibbs * A singly-linked tail queue is headed by a pair of pointers, one to the
5514940Sgibbs * head of the list and the other to the tail of the list. The elements are
5614940Sgibbs * singly linked for minimum space and pointer manipulation overhead at the
5714940Sgibbs * expense of O(n) removal for arbitrary elements. New elements can be added
5814940Sgibbs * to the list after an existing element, at the head of the list, or at the
5914940Sgibbs * end of the list. Elements being removed from the head of the tail queue
6014940Sgibbs * should use the explicit macro for this purpose for optimum efficiency.
6114940Sgibbs * A singly-linked tail queue may only be traversed in the forward direction.
6214940Sgibbs * Singly-linked tail queues are ideal for applications with large datasets
6314940Sgibbs * and few or no removals or for implementing a FIFO queue.
6414940Sgibbs *
651541Srgrimes * A list is headed by a single forward pointer (or an array of forward
661541Srgrimes * pointers for a hash table header). The elements are doubly linked
671541Srgrimes * so that an arbitrary element can be removed without a need to
6814492Shsu * traverse the list. New elements can be added to the list before
6914492Shsu * or after an existing element or at the head of the list. A list
7014492Shsu * may only be traversed in the forward direction.
711541Srgrimes *
721541Srgrimes * A tail queue is headed by a pair of pointers, one to the head of the
731541Srgrimes * list and the other to the tail of the list. The elements are doubly
741541Srgrimes * linked so that an arbitrary element can be removed without a need to
7514492Shsu * traverse the list. New elements can be added to the list before or
7614492Shsu * after an existing element, at the head of the list, or at the end of
7714492Shsu * the list. A tail queue may only be traversed in the forward direction.
781541Srgrimes *
791541Srgrimes * A circle queue is headed by a pair of pointers, one to the head of the
801541Srgrimes * list and the other to the tail of the list. The elements are doubly
811541Srgrimes * linked so that an arbitrary element can be removed without a need to
821541Srgrimes * traverse the list. New elements can be added to the list before or after
831541Srgrimes * an existing element, at the head of the list, or at the end of the list.
841541Srgrimes * A circle queue may be traversed in either direction, but has a more
851541Srgrimes * complex end of list detection.
861541Srgrimes *
871541Srgrimes * For details on the use of these macros, see the queue(3) manual page.
881541Srgrimes */
891541Srgrimes
901541Srgrimes/*
9114940Sgibbs * Singly-linked List definitions.
9214940Sgibbs */
9314940Sgibbs#define SLIST_HEAD(name, type)						\
9414940Sgibbsstruct name {								\
9514940Sgibbs	struct type *slh_first;	/* first element */			\
9614940Sgibbs}
9714940Sgibbs
9814940Sgibbs#define SLIST_ENTRY(type)						\
9914940Sgibbsstruct {								\
10014940Sgibbs	struct type *sle_next;	/* next element */			\
10114940Sgibbs}
10214940Sgibbs
10314940Sgibbs/*
10414940Sgibbs * Singly-linked List functions.
10514940Sgibbs */
10614940Sgibbs#define SLIST_INIT(head) {						\
10714940Sgibbs	(head)->slh_first = NULL;					\
10814940Sgibbs}
10914940Sgibbs
11014940Sgibbs#define SLIST_INSERT_AFTER(slistelm, elm, field) {			\
11114940Sgibbs	(elm)->field.sle_next = (slistelm)->field.sle_next;		\
11214940Sgibbs	(slistelm)->field.sle_next = (elm);				\
11314940Sgibbs}
11414940Sgibbs
11514940Sgibbs#define SLIST_INSERT_HEAD(head, elm, field) {				\
11614940Sgibbs	(elm)->field.sle_next = (head)->slh_first;			\
11714940Sgibbs	(head)->slh_first = (elm);					\
11814940Sgibbs}
11914940Sgibbs
12014940Sgibbs#define SLIST_REMOVE_HEAD(head, field) {				\
12114940Sgibbs	(head)->slh_first = (head)->slh_first->field.sle_next;		\
12214940Sgibbs}
12314940Sgibbs
12414940Sgibbs#define SLIST_REMOVE(head, elm, type, field) {				\
12514940Sgibbs	if ((head)->slh_first == (elm)) {				\
12614940Sgibbs		SLIST_REMOVE_HEAD((head), field);			\
12714940Sgibbs	}								\
12814940Sgibbs	else {								\
12914940Sgibbs		struct type *curelm = (head)->slh_first;		\
13014940Sgibbs		while( curelm->field.sle_next != (elm) )		\
13114940Sgibbs			curelm = curelm->field.sle_next;		\
13214940Sgibbs		curelm->field.sle_next =				\
13314940Sgibbs		    curelm->field.sle_next->field.sle_next;		\
13414940Sgibbs	}								\
13514940Sgibbs}
13614940Sgibbs
13714940Sgibbs/*
13814940Sgibbs * Singly-linked Tail queue definitions.
13914940Sgibbs */
14014940Sgibbs#define STAILQ_HEAD(name, type)						\
14114940Sgibbsstruct name {								\
14214940Sgibbs	struct type *stqh_first;/* first element */			\
14314940Sgibbs	struct type **stqh_last;/* addr of last next element */		\
14414940Sgibbs}
14514940Sgibbs
14614940Sgibbs#define STAILQ_ENTRY(type)						\
14714940Sgibbsstruct {								\
14814940Sgibbs	struct type *stqe_next;	/* next element */			\
14914940Sgibbs}
15014940Sgibbs
15114940Sgibbs/*
15214940Sgibbs * Singly-linked Tail queue functions.
15314940Sgibbs */
15414940Sgibbs#define	STAILQ_INIT(head) {						\
15514940Sgibbs	(head)->stqh_first = NULL;					\
15614940Sgibbs	(head)->stqh_last = &(head)->stqh_first;			\
15714940Sgibbs}
15814940Sgibbs
15914940Sgibbs#define STAILQ_INSERT_HEAD(head, elm, field) {				\
16014940Sgibbs	if (((elm)->field.stqe_next = (head)->stqh_first) == NULL)	\
16114940Sgibbs		(head)->stqh_last = &(elm)->field.stqe_next;		\
16214940Sgibbs	(head)->stqh_first = (elm);					\
16314940Sgibbs}
16414940Sgibbs
16514940Sgibbs#define STAILQ_INSERT_TAIL(head, elm, field) {				\
16614940Sgibbs	(elm)->field.stqe_next = NULL;					\
16714940Sgibbs	*(head)->stqh_last = (elm);					\
16814940Sgibbs	(head)->stqh_last = &(elm)->field.stqe_next;			\
16914940Sgibbs}
17014940Sgibbs
17114940Sgibbs#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) {			\
17214940Sgibbs	if (((elm)->field.stqe_next = (tqelm)->field.stqe_next) == NULL)\
17314940Sgibbs		(head)->stqh_last = &(elm)->field.stqe_next;		\
17414940Sgibbs	(tqelm)->field.stqe_next = (elm);				\
17514940Sgibbs}
17614940Sgibbs
17714940Sgibbs#define STAILQ_REMOVE_HEAD(head, field) {				\
17814940Sgibbs	if (((head)->stqh_first =					\
17914940Sgibbs	     (head)->stqh_first->field.stqe_next) == NULL)		\
18014940Sgibbs		(head)->stqh_last = &(head)->stqh_first;		\
18114940Sgibbs}
18214940Sgibbs
18314940Sgibbs#define STAILQ_REMOVE(head, elm, type, field) {				\
18414940Sgibbs	if ((head)->stqh_first == (elm)) {				\
18514940Sgibbs		STAILQ_REMOVE_HEAD(head, field);			\
18614940Sgibbs	}								\
18714940Sgibbs	else {								\
18814940Sgibbs		struct type *curelm = (head)->stqh_first;		\
18914940Sgibbs		while( curelm->field.stqe_next != (elm) )		\
19014940Sgibbs			curelm = curelm->field.stqe_next;		\
19114940Sgibbs		if((curelm->field.stqe_next =				\
19214940Sgibbs		    curelm->field.stqe_next->field.stqe_next) == NULL)	\
19314940Sgibbs			(head)->stqh_last = &(curelm)->field.stqe_next;	\
19414940Sgibbs	}								\
19514940Sgibbs}
19614940Sgibbs
19714940Sgibbs/*
1981541Srgrimes * List definitions.
1991541Srgrimes */
2001541Srgrimes#define LIST_HEAD(name, type)						\
2011541Srgrimesstruct name {								\
2021541Srgrimes	struct type *lh_first;	/* first element */			\
2031541Srgrimes}
2041541Srgrimes
2051541Srgrimes#define LIST_ENTRY(type)						\
2061541Srgrimesstruct {								\
2071541Srgrimes	struct type *le_next;	/* next element */			\
2081541Srgrimes	struct type **le_prev;	/* address of previous next element */	\
2091541Srgrimes}
2101541Srgrimes
2111541Srgrimes/*
2121541Srgrimes * List functions.
2131541Srgrimes */
2141541Srgrimes#define	LIST_INIT(head) {						\
2151541Srgrimes	(head)->lh_first = NULL;					\
2161541Srgrimes}
2171541Srgrimes
2181541Srgrimes#define LIST_INSERT_AFTER(listelm, elm, field) {			\
2191541Srgrimes	if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)	\
2201541Srgrimes		(listelm)->field.le_next->field.le_prev =		\
2211541Srgrimes		    &(elm)->field.le_next;				\
2221541Srgrimes	(listelm)->field.le_next = (elm);				\
2231541Srgrimes	(elm)->field.le_prev = &(listelm)->field.le_next;		\
2241541Srgrimes}
2251541Srgrimes
22613697Sgibbs#define LIST_INSERT_BEFORE(listelm, elm, field) {			\
22713697Sgibbs	(elm)->field.le_prev = (listelm)->field.le_prev;		\
22813697Sgibbs	(elm)->field.le_next = (listelm);				\
22913697Sgibbs	*(listelm)->field.le_prev = (elm);				\
23013697Sgibbs	(listelm)->field.le_prev = &(elm)->field.le_next;		\
23113697Sgibbs}
23213697Sgibbs
2331541Srgrimes#define LIST_INSERT_HEAD(head, elm, field) {				\
2341541Srgrimes	if (((elm)->field.le_next = (head)->lh_first) != NULL)		\
2351541Srgrimes		(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
2361541Srgrimes	(head)->lh_first = (elm);					\
2371541Srgrimes	(elm)->field.le_prev = &(head)->lh_first;			\
2381541Srgrimes}
2391541Srgrimes
2401541Srgrimes#define LIST_REMOVE(elm, field) {					\
2411541Srgrimes	if ((elm)->field.le_next != NULL)				\
2421541Srgrimes		(elm)->field.le_next->field.le_prev = 			\
2431541Srgrimes		    (elm)->field.le_prev;				\
2441541Srgrimes	*(elm)->field.le_prev = (elm)->field.le_next;			\
2451541Srgrimes}
2461541Srgrimes
2471541Srgrimes/*
2481541Srgrimes * Tail queue definitions.
2491541Srgrimes */
2501541Srgrimes#define TAILQ_HEAD(name, type)						\
2511541Srgrimesstruct name {								\
2521541Srgrimes	struct type *tqh_first;	/* first element */			\
2531541Srgrimes	struct type **tqh_last;	/* addr of last next element */		\
2541541Srgrimes}
2551541Srgrimes
2561541Srgrimes#define TAILQ_ENTRY(type)						\
2571541Srgrimesstruct {								\
2581541Srgrimes	struct type *tqe_next;	/* next element */			\
2591541Srgrimes	struct type **tqe_prev;	/* address of previous next element */	\
2601541Srgrimes}
2611541Srgrimes
2621541Srgrimes/*
2631541Srgrimes * Tail queue functions.
2641541Srgrimes */
26515138Sphk#define	TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
26615138Sphk
26715138Sphk#define	TAILQ_FIRST(head) ((head)->tqh_first)
26815138Sphk
26915138Sphk#define	TAILQ_LAST(head) ((head)->tqh_last)
27015138Sphk
27115809Sdyson#define	TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
27215138Sphk
27315809Sdyson#define TAILQ_PREV(elm, field) ((elm)->field.tqe_prev)
27415809Sdyson
2751541Srgrimes#define	TAILQ_INIT(head) {						\
2761541Srgrimes	(head)->tqh_first = NULL;					\
2771541Srgrimes	(head)->tqh_last = &(head)->tqh_first;				\
2781541Srgrimes}
2791541Srgrimes
2801541Srgrimes#define TAILQ_INSERT_HEAD(head, elm, field) {				\
2811541Srgrimes	if (((elm)->field.tqe_next = (head)->tqh_first) != NULL)	\
28214492Shsu		(head)->tqh_first->field.tqe_prev =			\
2831541Srgrimes		    &(elm)->field.tqe_next;				\
2841541Srgrimes	else								\
2851541Srgrimes		(head)->tqh_last = &(elm)->field.tqe_next;		\
2861541Srgrimes	(head)->tqh_first = (elm);					\
2871541Srgrimes	(elm)->field.tqe_prev = &(head)->tqh_first;			\
2881541Srgrimes}
2891541Srgrimes
2901541Srgrimes#define TAILQ_INSERT_TAIL(head, elm, field) {				\
2911541Srgrimes	(elm)->field.tqe_next = NULL;					\
2921541Srgrimes	(elm)->field.tqe_prev = (head)->tqh_last;			\
2931541Srgrimes	*(head)->tqh_last = (elm);					\
2941541Srgrimes	(head)->tqh_last = &(elm)->field.tqe_next;			\
2951541Srgrimes}
2961541Srgrimes
2971541Srgrimes#define TAILQ_INSERT_AFTER(head, listelm, elm, field) {			\
2981541Srgrimes	if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
2991541Srgrimes		(elm)->field.tqe_next->field.tqe_prev = 		\
3001541Srgrimes		    &(elm)->field.tqe_next;				\
3011541Srgrimes	else								\
3021541Srgrimes		(head)->tqh_last = &(elm)->field.tqe_next;		\
3031541Srgrimes	(listelm)->field.tqe_next = (elm);				\
3041541Srgrimes	(elm)->field.tqe_prev = &(listelm)->field.tqe_next;		\
3051541Srgrimes}
3061541Srgrimes
30714055Sgibbs#define TAILQ_INSERT_BEFORE(listelm, elm, field) {			\
30813697Sgibbs	(elm)->field.tqe_prev = (listelm)->field.tqe_prev;		\
30913697Sgibbs	(elm)->field.tqe_next = (listelm);				\
31013697Sgibbs	*(listelm)->field.tqe_prev = (elm);				\
31113697Sgibbs	(listelm)->field.tqe_prev = &(elm)->field.tqe_next;		\
31213697Sgibbs}
31313697Sgibbs
3141541Srgrimes#define TAILQ_REMOVE(head, elm, field) {				\
3151541Srgrimes	if (((elm)->field.tqe_next) != NULL)				\
3161541Srgrimes		(elm)->field.tqe_next->field.tqe_prev = 		\
3171541Srgrimes		    (elm)->field.tqe_prev;				\
3181541Srgrimes	else								\
3191541Srgrimes		(head)->tqh_last = (elm)->field.tqe_prev;		\
3201541Srgrimes	*(elm)->field.tqe_prev = (elm)->field.tqe_next;			\
3211541Srgrimes}
3221541Srgrimes
3231541Srgrimes/*
3241541Srgrimes * Circular queue definitions.
3251541Srgrimes */
3261541Srgrimes#define CIRCLEQ_HEAD(name, type)					\
3271541Srgrimesstruct name {								\
3281541Srgrimes	struct type *cqh_first;		/* first element */		\
3291541Srgrimes	struct type *cqh_last;		/* last element */		\
3301541Srgrimes}
3311541Srgrimes
3321541Srgrimes#define CIRCLEQ_ENTRY(type)						\
3331541Srgrimesstruct {								\
3341541Srgrimes	struct type *cqe_next;		/* next element */		\
3351541Srgrimes	struct type *cqe_prev;		/* previous element */		\
3361541Srgrimes}
3371541Srgrimes
3381541Srgrimes/*
3391541Srgrimes * Circular queue functions.
3401541Srgrimes */
3411541Srgrimes#define	CIRCLEQ_INIT(head) {						\
3421541Srgrimes	(head)->cqh_first = (void *)(head);				\
3431541Srgrimes	(head)->cqh_last = (void *)(head);				\
3441541Srgrimes}
3451541Srgrimes
3461541Srgrimes#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) {		\
3471541Srgrimes	(elm)->field.cqe_next = (listelm)->field.cqe_next;		\
3481541Srgrimes	(elm)->field.cqe_prev = (listelm);				\
3491541Srgrimes	if ((listelm)->field.cqe_next == (void *)(head))		\
3501541Srgrimes		(head)->cqh_last = (elm);				\
3511541Srgrimes	else								\
3521541Srgrimes		(listelm)->field.cqe_next->field.cqe_prev = (elm);	\
3531541Srgrimes	(listelm)->field.cqe_next = (elm);				\
3541541Srgrimes}
3551541Srgrimes
3561541Srgrimes#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) {		\
3571541Srgrimes	(elm)->field.cqe_next = (listelm);				\
3581541Srgrimes	(elm)->field.cqe_prev = (listelm)->field.cqe_prev;		\
3591541Srgrimes	if ((listelm)->field.cqe_prev == (void *)(head))		\
3601541Srgrimes		(head)->cqh_first = (elm);				\
3611541Srgrimes	else								\
3621541Srgrimes		(listelm)->field.cqe_prev->field.cqe_next = (elm);	\
3631541Srgrimes	(listelm)->field.cqe_prev = (elm);				\
3641541Srgrimes}
3651541Srgrimes
3661541Srgrimes#define CIRCLEQ_INSERT_HEAD(head, elm, field) {				\
3671541Srgrimes	(elm)->field.cqe_next = (head)->cqh_first;			\
3681541Srgrimes	(elm)->field.cqe_prev = (void *)(head);				\
3691541Srgrimes	if ((head)->cqh_last == (void *)(head))				\
3701541Srgrimes		(head)->cqh_last = (elm);				\
3711541Srgrimes	else								\
3721541Srgrimes		(head)->cqh_first->field.cqe_prev = (elm);		\
3731541Srgrimes	(head)->cqh_first = (elm);					\
3741541Srgrimes}
3751541Srgrimes
3761541Srgrimes#define CIRCLEQ_INSERT_TAIL(head, elm, field) {				\
3771541Srgrimes	(elm)->field.cqe_next = (void *)(head);				\
3781541Srgrimes	(elm)->field.cqe_prev = (head)->cqh_last;			\
3791541Srgrimes	if ((head)->cqh_first == (void *)(head))			\
3801541Srgrimes		(head)->cqh_first = (elm);				\
3811541Srgrimes	else								\
3821541Srgrimes		(head)->cqh_last->field.cqe_next = (elm);		\
3831541Srgrimes	(head)->cqh_last = (elm);					\
3841541Srgrimes}
3851541Srgrimes
3861541Srgrimes#define	CIRCLEQ_REMOVE(head, elm, field) {				\
3871541Srgrimes	if ((elm)->field.cqe_next == (void *)(head))			\
3881541Srgrimes		(head)->cqh_last = (elm)->field.cqe_prev;		\
3891541Srgrimes	else								\
3901541Srgrimes		(elm)->field.cqe_next->field.cqe_prev =			\
3911541Srgrimes		    (elm)->field.cqe_prev;				\
3921541Srgrimes	if ((elm)->field.cqe_prev == (void *)(head))			\
3931541Srgrimes		(head)->cqh_first = (elm)->field.cqe_next;		\
3941541Srgrimes	else								\
3951541Srgrimes		(elm)->field.cqe_prev->field.cqe_next =			\
3961541Srgrimes		    (elm)->field.cqe_next;				\
3971541Srgrimes}
39812592Sbde
39912592Sbde#ifdef KERNEL
40012592Sbde
40112592Sbde/*
40212592Sbde * XXX insque() and remque() are an old way of handling certain queues.
40312592Sbde * They bogusly assumes that all queue heads look alike.
40412592Sbde */
40512592Sbde
40612592Sbdestruct quehead {
40712592Sbde	struct quehead *qh_link;
40812592Sbde	struct quehead *qh_rlink;
40912592Sbde};
41012592Sbde
41112592Sbde#ifdef	__GNUC__
41212592Sbde
41312592Sbdestatic __inline void
41412592Sbdeinsque(void *a, void *b)
41512592Sbde{
41612592Sbde	struct quehead *element = a, *head = b;
41712592Sbde
41812592Sbde	element->qh_link = head->qh_link;
41912592Sbde	element->qh_rlink = head;
42012592Sbde	head->qh_link = element;
42112592Sbde	element->qh_link->qh_rlink = element;
42212592Sbde}
42312592Sbde
42412592Sbdestatic __inline void
42512592Sbderemque(void *a)
42612592Sbde{
42712592Sbde	struct quehead *element = a;
42812592Sbde
42912592Sbde	element->qh_link->qh_rlink = element->qh_rlink;
43012592Sbde	element->qh_rlink->qh_link = element->qh_link;
43112592Sbde	element->qh_rlink = 0;
43212592Sbde}
43312592Sbde
43412592Sbde#else /* !__GNUC__ */
43512592Sbde
43612592Sbdevoid	insque __P((void *a, void *b));
43712592Sbdevoid	remque __P((void *a));
43812592Sbde
43912592Sbde#endif /* __GNUC__ */
44012592Sbde
44112592Sbde#endif /* KERNEL */
44212592Sbde
44312592Sbde#endif /* !_SYS_QUEUE_H_ */
444