xref: /onnv-gate/usr/src/lib/libsmbfs/smb/queue.h (revision 6007:d57e38e8fdd1)
1*6007Sthurlow /*
2*6007Sthurlow  * Copyright (c) 1991, 1993
3*6007Sthurlow  *	The Regents of the University of California.  All rights reserved.
4*6007Sthurlow  *
5*6007Sthurlow  * Redistribution and use in source and binary forms, with or without
6*6007Sthurlow  * modification, are permitted provided that the following conditions
7*6007Sthurlow  * are met:
8*6007Sthurlow  * 1. Redistributions of source code must retain the above copyright
9*6007Sthurlow  *    notice, this list of conditions and the following disclaimer.
10*6007Sthurlow  * 2. Redistributions in binary form must reproduce the above copyright
11*6007Sthurlow  *    notice, this list of conditions and the following disclaimer in the
12*6007Sthurlow  *    documentation and/or other materials provided with the distribution.
13*6007Sthurlow  * 3. All advertising materials mentioning features or use of this software
14*6007Sthurlow  *    must display the following acknowledgement:
15*6007Sthurlow  *	This product includes software developed by the University of
16*6007Sthurlow  *	California, Berkeley and its contributors.
17*6007Sthurlow  * 4. Neither the name of the University nor the names of its contributors
18*6007Sthurlow  *    may be used to endorse or promote products derived from this software
19*6007Sthurlow  *    without specific prior written permission.
20*6007Sthurlow  *
21*6007Sthurlow  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22*6007Sthurlow  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23*6007Sthurlow  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24*6007Sthurlow  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25*6007Sthurlow  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26*6007Sthurlow  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27*6007Sthurlow  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28*6007Sthurlow  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29*6007Sthurlow  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30*6007Sthurlow  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*6007Sthurlow  * SUCH DAMAGE.
32*6007Sthurlow  *
33*6007Sthurlow  *	@(#)queue.h	8.5 (Berkeley) 8/20/94
34*6007Sthurlow  */
35*6007Sthurlow 
36*6007Sthurlow #pragma ident	"%Z%%M%	%I%	%E% SMI"
37*6007Sthurlow 
38*6007Sthurlow /*
39*6007Sthurlow  * This file [used to define] five types of data structures:
40*6007Sthurlow  *   singly-linked lists, ...
41*6007Sthurlow  * [ all other types of lists removed ]
42*6007Sthurlow  *
43*6007Sthurlow  * Using excerpts of FreeBSD 4.5 sys/queue.h here,
44*6007Sthurlow  * but only temporarily, until rcfile.c is replaced
45*6007Sthurlow  * by SMF integration code.
46*6007Sthurlow  *
47*6007Sthurlow  * Yes we also have queue.h in uts/common/fs/smbclnt
48*6007Sthurlow  * but don't want to make that part of the exported
49*6007Sthurlow  * interface to the user-level code.
50*6007Sthurlow  */
51*6007Sthurlow 
52*6007Sthurlow /*
53*6007Sthurlow  * Singly-linked List declarations.
54*6007Sthurlow  */
55*6007Sthurlow #define	SLIST_HEAD(name, type)						\
56*6007Sthurlow struct name {								\
57*6007Sthurlow 	struct type *slh_first;	/* first element */			\
58*6007Sthurlow }
59*6007Sthurlow 
60*6007Sthurlow #define	SLIST_ENTRY(type)						\
61*6007Sthurlow struct {								\
62*6007Sthurlow 	struct type *sle_next;	/* next element */			\
63*6007Sthurlow }
64*6007Sthurlow 
65*6007Sthurlow /*
66*6007Sthurlow  * Singly-linked List functions.
67*6007Sthurlow  */
68*6007Sthurlow #define	SLIST_EMPTY(head)	((head)->slh_first == NULL)
69*6007Sthurlow 
70*6007Sthurlow #define	SLIST_FIRST(head)	((head)->slh_first)
71*6007Sthurlow 
72*6007Sthurlow #define	SLIST_FOREACH(var, head, field)					\
73*6007Sthurlow 	for ((var) = SLIST_FIRST((head));				\
74*6007Sthurlow 	    (var);							\
75*6007Sthurlow 	    (var) = SLIST_NEXT((var), field))
76*6007Sthurlow 
77*6007Sthurlow #define	SLIST_INIT(head) do {						\
78*6007Sthurlow 	SLIST_FIRST((head)) = NULL;					\
79*6007Sthurlow } while (0)
80*6007Sthurlow 
81*6007Sthurlow #define	SLIST_INSERT_AFTER(slistelm, elm, field) do {			\
82*6007Sthurlow 	SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field);	\
83*6007Sthurlow 	SLIST_NEXT((slistelm), field) = (elm);				\
84*6007Sthurlow } while (0)
85*6007Sthurlow 
86*6007Sthurlow #define	SLIST_INSERT_HEAD(head, elm, field) do {			\
87*6007Sthurlow 	SLIST_NEXT((elm), field) = SLIST_FIRST((head));			\
88*6007Sthurlow 	SLIST_FIRST((head)) = (elm);					\
89*6007Sthurlow } while (0)
90*6007Sthurlow 
91*6007Sthurlow #define	SLIST_NEXT(elm, field)	((elm)->field.sle_next)
92*6007Sthurlow 
93*6007Sthurlow #define	SLIST_REMOVE(head, elm, type, field) do {			\
94*6007Sthurlow 	if (SLIST_FIRST((head)) == (elm)) {				\
95*6007Sthurlow 		SLIST_REMOVE_HEAD((head), field);			\
96*6007Sthurlow 	}								\
97*6007Sthurlow 	else {								\
98*6007Sthurlow 		struct type *curelm = SLIST_FIRST((head));		\
99*6007Sthurlow 		while (SLIST_NEXT(curelm, field) != (elm))		\
100*6007Sthurlow 			curelm = SLIST_NEXT(curelm, field);		\
101*6007Sthurlow 		SLIST_NEXT(curelm, field) =				\
102*6007Sthurlow 		    SLIST_NEXT(SLIST_NEXT(curelm, field), field);	\
103*6007Sthurlow 	}								\
104*6007Sthurlow } while (0)
105*6007Sthurlow 
106*6007Sthurlow #define	SLIST_REMOVE_HEAD(head, field) do {				\
107*6007Sthurlow 	SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field);	\
108*6007Sthurlow } while (0)
109*6007Sthurlow 
110