1226031Sstas/*	$NetBSD: queue.h,v 1.39 2004/04/18 14:25:34 lukem Exp $	*/
2226031Sstas
3226031Sstas/*
4226031Sstas * Copyright (c) 1991, 1993
5226031Sstas *	The Regents of the University of California.  All rights reserved.
6226031Sstas *
7226031Sstas * Redistribution and use in source and binary forms, with or without
8226031Sstas * modification, are permitted provided that the following conditions
9226031Sstas * are met:
10226031Sstas * 1. Redistributions of source code must retain the above copyright
11226031Sstas *    notice, this list of conditions and the following disclaimer.
12226031Sstas * 2. Redistributions in binary form must reproduce the above copyright
13226031Sstas *    notice, this list of conditions and the following disclaimer in the
14226031Sstas *    documentation and/or other materials provided with the distribution.
15226031Sstas * 3. Neither the name of the University nor the names of its contributors
16226031Sstas *    may be used to endorse or promote products derived from this software
17226031Sstas *    without specific prior written permission.
18226031Sstas *
19226031Sstas * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20226031Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21226031Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22226031Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23226031Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24226031Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25226031Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26226031Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27226031Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28226031Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29226031Sstas * SUCH DAMAGE.
30226031Sstas *
31226031Sstas *	@(#)queue.h	8.5 (Berkeley) 8/20/94
32226031Sstas */
33226031Sstas
34226031Sstas#ifndef	_MECHQUEUE_H_
35226031Sstas#define	_MECHQUEUE_H_
36226031Sstas
37226031Sstas/*
38226031Sstas * Singly-linked List definitions.
39226031Sstas */
40226031Sstas#define	HEIM_SLIST_HEAD(name, type)						\
41226031Sstasstruct name {								\
42226031Sstas	struct type *slh_first;	/* first element */			\
43226031Sstas}
44226031Sstas
45226031Sstas#define	HEIM_SLIST_HEAD_INITIALIZER(head)					\
46226031Sstas	{ NULL }
47226031Sstas
48226031Sstas#define	HEIM_SLIST_ENTRY(type)						\
49226031Sstasstruct {								\
50226031Sstas	struct type *sle_next;	/* next element */			\
51226031Sstas}
52226031Sstas
53226031Sstas/*
54226031Sstas * Singly-linked List functions.
55226031Sstas */
56226031Sstas#define	HEIM_SLIST_INIT(head) do {						\
57226031Sstas	(head)->slh_first = NULL;					\
58226031Sstas} while (/*CONSTCOND*/0)
59226031Sstas
60226031Sstas#define	HEIM_SLIST_INSERT_AFTER(slistelm, elm, field) do {			\
61226031Sstas	(elm)->field.sle_next = (slistelm)->field.sle_next;		\
62226031Sstas	(slistelm)->field.sle_next = (elm);				\
63226031Sstas} while (/*CONSTCOND*/0)
64226031Sstas
65226031Sstas#define	HEIM_SLIST_INSERT_HEAD(head, elm, field) do {			\
66226031Sstas	(elm)->field.sle_next = (head)->slh_first;			\
67226031Sstas	(head)->slh_first = (elm);					\
68226031Sstas} while (/*CONSTCOND*/0)
69226031Sstas
70226031Sstas#define	HEIM_SLIST_REMOVE_HEAD(head, field) do {				\
71226031Sstas	(head)->slh_first = (head)->slh_first->field.sle_next;		\
72226031Sstas} while (/*CONSTCOND*/0)
73226031Sstas
74226031Sstas#define	HEIM_SLIST_REMOVE(head, elm, type, field) do {			\
75226031Sstas	if ((head)->slh_first == (elm)) {				\
76226031Sstas		HEIM_SLIST_REMOVE_HEAD((head), field);			\
77226031Sstas	}								\
78226031Sstas	else {								\
79226031Sstas		struct type *curelm = (head)->slh_first;		\
80226031Sstas		while(curelm->field.sle_next != (elm))			\
81226031Sstas			curelm = curelm->field.sle_next;		\
82226031Sstas		curelm->field.sle_next =				\
83226031Sstas		    curelm->field.sle_next->field.sle_next;		\
84226031Sstas	}								\
85226031Sstas} while (/*CONSTCOND*/0)
86226031Sstas
87226031Sstas#define	HEIM_SLIST_FOREACH(var, head, field)					\
88226031Sstas	for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
89226031Sstas
90226031Sstas/*
91226031Sstas * Singly-linked List access methods.
92226031Sstas */
93226031Sstas#define	HEIM_SLIST_EMPTY(head)	((head)->slh_first == NULL)
94226031Sstas#define	HEIM_SLIST_FIRST(head)	((head)->slh_first)
95226031Sstas#define	HEIM_SLIST_NEXT(elm, field)	((elm)->field.sle_next)
96226031Sstas
97226031Sstas#endif	/* !_MECHQUEUE_H_ */
98