17c478bd9Sstevel@tonic-gate /*
256a424ccSmp  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
356a424ccSmp  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate #ifndef _KRB5_DB2_DBQUEUE_H
77c478bd9Sstevel@tonic-gate #define	_KRB5_DB2_DBQUEUE_H
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
107c478bd9Sstevel@tonic-gate extern "C" {
117c478bd9Sstevel@tonic-gate #endif
127c478bd9Sstevel@tonic-gate 
13*1da57d55SToomas Soome /*
147c478bd9Sstevel@tonic-gate  * Copyright (c) 1991, 1993
157c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
167c478bd9Sstevel@tonic-gate  *
177c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
187c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
197c478bd9Sstevel@tonic-gate  * are met:
207c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
217c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
227c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
237c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
247c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
257c478bd9Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this software
267c478bd9Sstevel@tonic-gate  *    must display the following acknowledgement:
277c478bd9Sstevel@tonic-gate  *	This product includes software developed by the University of
287c478bd9Sstevel@tonic-gate  *	California, Berkeley and its contributors.
297c478bd9Sstevel@tonic-gate  * 4. Neither the name of the University nor the names of its contributors
307c478bd9Sstevel@tonic-gate  *    may be used to endorse or promote products derived from this software
317c478bd9Sstevel@tonic-gate  *    without specific prior written permission.
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
347c478bd9Sstevel@tonic-gate  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
357c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
367c478bd9Sstevel@tonic-gate  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
377c478bd9Sstevel@tonic-gate  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
387c478bd9Sstevel@tonic-gate  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
397c478bd9Sstevel@tonic-gate  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
407c478bd9Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
417c478bd9Sstevel@tonic-gate  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
427c478bd9Sstevel@tonic-gate  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
437c478bd9Sstevel@tonic-gate  * SUCH DAMAGE.
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  *	@(#)queue.h	8.3 (Berkeley) 12/13/93
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate 
4856a424ccSmp #ifndef	_QUEUE_H_
4956a424ccSmp #define	_QUEUE_H_
5056a424ccSmp 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * This file defines three types of data structures: lists, tail queues,
537c478bd9Sstevel@tonic-gate  * and circular queues.
547c478bd9Sstevel@tonic-gate  *
557c478bd9Sstevel@tonic-gate  * A list is headed by a single forward pointer (or an array of forward
567c478bd9Sstevel@tonic-gate  * pointers for a hash table header). The elements are doubly linked
577c478bd9Sstevel@tonic-gate  * so that an arbitrary element can be removed without a need to
587c478bd9Sstevel@tonic-gate  * traverse the list. New elements can be added to the list after
597c478bd9Sstevel@tonic-gate  * an existing element or at the head of the list. A list may only be
607c478bd9Sstevel@tonic-gate  * traversed in the forward direction.
617c478bd9Sstevel@tonic-gate  *
627c478bd9Sstevel@tonic-gate  * A tail queue is headed by a pair of pointers, one to the head of the
637c478bd9Sstevel@tonic-gate  * list and the other to the tail of the list. The elements are doubly
647c478bd9Sstevel@tonic-gate  * linked so that an arbitrary element can be removed without a need to
657c478bd9Sstevel@tonic-gate  * traverse the list. New elements can be added to the list after
667c478bd9Sstevel@tonic-gate  * an existing element, at the head of the list, or at the end of the
677c478bd9Sstevel@tonic-gate  * list. A tail queue may only be traversed in the forward direction.
687c478bd9Sstevel@tonic-gate  *
697c478bd9Sstevel@tonic-gate  * A circle queue is headed by a pair of pointers, one to the head of the
707c478bd9Sstevel@tonic-gate  * list and the other to the tail of the list. The elements are doubly
717c478bd9Sstevel@tonic-gate  * linked so that an arbitrary element can be removed without a need to
727c478bd9Sstevel@tonic-gate  * traverse the list. New elements can be added to the list before or after
737c478bd9Sstevel@tonic-gate  * an existing element, at the head of the list, or at the end of the list.
747c478bd9Sstevel@tonic-gate  * A circle queue may be traversed in either direction, but has a more
757c478bd9Sstevel@tonic-gate  * complex end of list detection.
767c478bd9Sstevel@tonic-gate  *
777c478bd9Sstevel@tonic-gate  * For details on the use of these macros, see the queue(3) manual page.
787c478bd9Sstevel@tonic-gate  */
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate  * List definitions.
827c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate #define LIST_HEAD(name, type)						\
847c478bd9Sstevel@tonic-gate struct name {								\
857c478bd9Sstevel@tonic-gate 	struct type *lh_first;	/* first element */			\
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #define LIST_ENTRY(type)						\
897c478bd9Sstevel@tonic-gate struct {								\
907c478bd9Sstevel@tonic-gate 	struct type *le_next;	/* next element */			\
917c478bd9Sstevel@tonic-gate 	struct type **le_prev;	/* address of previous next element */	\
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * List functions.
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate #define	LIST_INIT(head) {						\
987c478bd9Sstevel@tonic-gate 	(head)->lh_first = NULL;					\
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate #define LIST_INSERT_AFTER(listelm, elm, field) {			\
1027c478bd9Sstevel@tonic-gate 	if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)	\
1037c478bd9Sstevel@tonic-gate 		(listelm)->field.le_next->field.le_prev =		\
1047c478bd9Sstevel@tonic-gate 		    &(elm)->field.le_next;				\
1057c478bd9Sstevel@tonic-gate 	(listelm)->field.le_next = (elm);				\
1067c478bd9Sstevel@tonic-gate 	(elm)->field.le_prev = &(listelm)->field.le_next;		\
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate #define LIST_INSERT_HEAD(head, elm, field) {				\
1107c478bd9Sstevel@tonic-gate 	if (((elm)->field.le_next = (head)->lh_first) != NULL)		\
1117c478bd9Sstevel@tonic-gate 		(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
1127c478bd9Sstevel@tonic-gate 	(head)->lh_first = (elm);					\
1137c478bd9Sstevel@tonic-gate 	(elm)->field.le_prev = &(head)->lh_first;			\
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate #define LIST_REMOVE(elm, field) {					\
1177c478bd9Sstevel@tonic-gate 	if ((elm)->field.le_next != NULL)				\
1187c478bd9Sstevel@tonic-gate 		(elm)->field.le_next->field.le_prev = 			\
1197c478bd9Sstevel@tonic-gate 		    (elm)->field.le_prev;				\
1207c478bd9Sstevel@tonic-gate 	*(elm)->field.le_prev = (elm)->field.le_next;			\
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * Tail queue definitions.
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate #define TAILQ_HEAD(name, type)						\
1277c478bd9Sstevel@tonic-gate struct name {								\
1287c478bd9Sstevel@tonic-gate 	struct type *tqh_first;	/* first element */			\
1297c478bd9Sstevel@tonic-gate 	struct type **tqh_last;	/* addr of last next element */		\
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #define TAILQ_ENTRY(type)						\
1337c478bd9Sstevel@tonic-gate struct {								\
1347c478bd9Sstevel@tonic-gate 	struct type *tqe_next;	/* next element */			\
1357c478bd9Sstevel@tonic-gate 	struct type **tqe_prev;	/* address of previous next element */	\
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate  * Tail queue functions.
1407c478bd9Sstevel@tonic-gate  */
1417c478bd9Sstevel@tonic-gate #define	TAILQ_INIT(head) {						\
1427c478bd9Sstevel@tonic-gate 	(head)->tqh_first = NULL;					\
1437c478bd9Sstevel@tonic-gate 	(head)->tqh_last = &(head)->tqh_first;				\
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #define TAILQ_INSERT_HEAD(head, elm, field) {				\
1477c478bd9Sstevel@tonic-gate 	if (((elm)->field.tqe_next = (head)->tqh_first) != NULL)	\
1487c478bd9Sstevel@tonic-gate 		(elm)->field.tqe_next->field.tqe_prev =			\
1497c478bd9Sstevel@tonic-gate 		    &(elm)->field.tqe_next;				\
1507c478bd9Sstevel@tonic-gate 	else								\
1517c478bd9Sstevel@tonic-gate 		(head)->tqh_last = &(elm)->field.tqe_next;		\
1527c478bd9Sstevel@tonic-gate 	(head)->tqh_first = (elm);					\
1537c478bd9Sstevel@tonic-gate 	(elm)->field.tqe_prev = &(head)->tqh_first;			\
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate #define TAILQ_INSERT_TAIL(head, elm, field) {				\
1577c478bd9Sstevel@tonic-gate 	(elm)->field.tqe_next = NULL;					\
1587c478bd9Sstevel@tonic-gate 	(elm)->field.tqe_prev = (head)->tqh_last;			\
1597c478bd9Sstevel@tonic-gate 	*(head)->tqh_last = (elm);					\
1607c478bd9Sstevel@tonic-gate 	(head)->tqh_last = &(elm)->field.tqe_next;			\
1617c478bd9Sstevel@tonic-gate }
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate #define TAILQ_INSERT_AFTER(head, listelm, elm, field) {			\
1647c478bd9Sstevel@tonic-gate 	if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
1657c478bd9Sstevel@tonic-gate 		(elm)->field.tqe_next->field.tqe_prev = 		\
1667c478bd9Sstevel@tonic-gate 		    &(elm)->field.tqe_next;				\
1677c478bd9Sstevel@tonic-gate 	else								\
1687c478bd9Sstevel@tonic-gate 		(head)->tqh_last = &(elm)->field.tqe_next;		\
1697c478bd9Sstevel@tonic-gate 	(listelm)->field.tqe_next = (elm);				\
1707c478bd9Sstevel@tonic-gate 	(elm)->field.tqe_prev = &(listelm)->field.tqe_next;		\
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate #define TAILQ_REMOVE(head, elm, field) {				\
1747c478bd9Sstevel@tonic-gate 	if (((elm)->field.tqe_next) != NULL)				\
1757c478bd9Sstevel@tonic-gate 		(elm)->field.tqe_next->field.tqe_prev = 		\
1767c478bd9Sstevel@tonic-gate 		    (elm)->field.tqe_prev;				\
1777c478bd9Sstevel@tonic-gate 	else								\
1787c478bd9Sstevel@tonic-gate 		(head)->tqh_last = (elm)->field.tqe_prev;		\
1797c478bd9Sstevel@tonic-gate 	*(elm)->field.tqe_prev = (elm)->field.tqe_next;			\
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate /*
1837c478bd9Sstevel@tonic-gate  * Circular queue definitions.
1847c478bd9Sstevel@tonic-gate  */
1857c478bd9Sstevel@tonic-gate #define CIRCLEQ_HEAD(name, type)					\
1867c478bd9Sstevel@tonic-gate struct name {								\
1877c478bd9Sstevel@tonic-gate 	struct type *cqh_first;		/* first element */		\
1887c478bd9Sstevel@tonic-gate 	struct type *cqh_last;		/* last element */		\
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate #define CIRCLEQ_ENTRY(type)						\
1927c478bd9Sstevel@tonic-gate struct {								\
1937c478bd9Sstevel@tonic-gate 	struct type *cqe_next;		/* next element */		\
1947c478bd9Sstevel@tonic-gate 	struct type *cqe_prev;		/* previous element */		\
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  * Circular queue functions.
1997c478bd9Sstevel@tonic-gate  */
2007c478bd9Sstevel@tonic-gate #define	CIRCLEQ_INIT(head) {						\
2017c478bd9Sstevel@tonic-gate 	(head)->cqh_first = (void *)(head);				\
2027c478bd9Sstevel@tonic-gate 	(head)->cqh_last = (void *)(head);				\
2037c478bd9Sstevel@tonic-gate }
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate #define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) {		\
2067c478bd9Sstevel@tonic-gate 	(elm)->field.cqe_next = (listelm)->field.cqe_next;		\
2077c478bd9Sstevel@tonic-gate 	(elm)->field.cqe_prev = (listelm);				\
2087c478bd9Sstevel@tonic-gate 	if ((listelm)->field.cqe_next == (void *)(head))		\
2097c478bd9Sstevel@tonic-gate 		(head)->cqh_last = (elm);				\
2107c478bd9Sstevel@tonic-gate 	else								\
2117c478bd9Sstevel@tonic-gate 		(listelm)->field.cqe_next->field.cqe_prev = (elm);	\
2127c478bd9Sstevel@tonic-gate 	(listelm)->field.cqe_next = (elm);				\
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate #define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) {		\
2167c478bd9Sstevel@tonic-gate 	(elm)->field.cqe_next = (listelm);				\
2177c478bd9Sstevel@tonic-gate 	(elm)->field.cqe_prev = (listelm)->field.cqe_prev;		\
2187c478bd9Sstevel@tonic-gate 	if ((listelm)->field.cqe_prev == (void *)(head))		\
2197c478bd9Sstevel@tonic-gate 		(head)->cqh_first = (elm);				\
2207c478bd9Sstevel@tonic-gate 	else								\
2217c478bd9Sstevel@tonic-gate 		(listelm)->field.cqe_prev->field.cqe_next = (elm);	\
2227c478bd9Sstevel@tonic-gate 	(listelm)->field.cqe_prev = (elm);				\
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #define CIRCLEQ_INSERT_HEAD(head, elm, field) {				\
2267c478bd9Sstevel@tonic-gate 	(elm)->field.cqe_next = (head)->cqh_first;			\
2277c478bd9Sstevel@tonic-gate 	(elm)->field.cqe_prev = (void *)(head);				\
2287c478bd9Sstevel@tonic-gate 	if ((head)->cqh_last == (void *)(head))				\
2297c478bd9Sstevel@tonic-gate 		(head)->cqh_last = (elm);				\
2307c478bd9Sstevel@tonic-gate 	else								\
2317c478bd9Sstevel@tonic-gate 		(head)->cqh_first->field.cqe_prev = (elm);		\
2327c478bd9Sstevel@tonic-gate 	(head)->cqh_first = (elm);					\
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate #define CIRCLEQ_INSERT_TAIL(head, elm, field) {				\
2367c478bd9Sstevel@tonic-gate 	(elm)->field.cqe_next = (void *)(head);				\
2377c478bd9Sstevel@tonic-gate 	(elm)->field.cqe_prev = (head)->cqh_last;			\
2387c478bd9Sstevel@tonic-gate 	if ((head)->cqh_first == (void *)(head))			\
2397c478bd9Sstevel@tonic-gate 		(head)->cqh_first = (elm);				\
2407c478bd9Sstevel@tonic-gate 	else								\
2417c478bd9Sstevel@tonic-gate 		(head)->cqh_last->field.cqe_next = (elm);		\
2427c478bd9Sstevel@tonic-gate 	(head)->cqh_last = (elm);					\
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate #define	CIRCLEQ_REMOVE(head, elm, field) {				\
2467c478bd9Sstevel@tonic-gate 	if ((elm)->field.cqe_next == (void *)(head))			\
2477c478bd9Sstevel@tonic-gate 		(head)->cqh_last = (elm)->field.cqe_prev;		\
2487c478bd9Sstevel@tonic-gate 	else								\
2497c478bd9Sstevel@tonic-gate 		(elm)->field.cqe_next->field.cqe_prev =			\
2507c478bd9Sstevel@tonic-gate 		    (elm)->field.cqe_prev;				\
2517c478bd9Sstevel@tonic-gate 	if ((elm)->field.cqe_prev == (void *)(head))			\
2527c478bd9Sstevel@tonic-gate 		(head)->cqh_first = (elm)->field.cqe_next;		\
2537c478bd9Sstevel@tonic-gate 	else								\
2547c478bd9Sstevel@tonic-gate 		(elm)->field.cqe_prev->field.cqe_next =			\
2557c478bd9Sstevel@tonic-gate 		    (elm)->field.cqe_next;				\
2567c478bd9Sstevel@tonic-gate }
25756a424ccSmp #endif	/* !_QUEUE_H_ */
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate #endif
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate #endif	/* !_KRB5_DB2_DBQUEUE_H */
264