1*4960Swillf /* 2*4960Swillf * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 3*4960Swillf * Use is subject to license terms. 4*4960Swillf */ 5*4960Swillf 6*4960Swillf #ifndef _KRB5_DB2_DBQUEUE_H 7*4960Swillf #define _KRB5_DB2_DBQUEUE_H 8*4960Swillf 9*4960Swillf #pragma ident "%Z%%M% %I% %E% SMI" 10*4960Swillf 11*4960Swillf #ifdef __cplusplus 12*4960Swillf extern "C" { 13*4960Swillf #endif 14*4960Swillf 15*4960Swillf /* 16*4960Swillf * Copyright (c) 1991, 1993 17*4960Swillf * The Regents of the University of California. All rights reserved. 18*4960Swillf * 19*4960Swillf * Redistribution and use in source and binary forms, with or without 20*4960Swillf * modification, are permitted provided that the following conditions 21*4960Swillf * are met: 22*4960Swillf * 1. Redistributions of source code must retain the above copyright 23*4960Swillf * notice, this list of conditions and the following disclaimer. 24*4960Swillf * 2. Redistributions in binary form must reproduce the above copyright 25*4960Swillf * notice, this list of conditions and the following disclaimer in the 26*4960Swillf * documentation and/or other materials provided with the distribution. 27*4960Swillf * 3. All advertising materials mentioning features or use of this software 28*4960Swillf * must display the following acknowledgement: 29*4960Swillf * This product includes software developed by the University of 30*4960Swillf * California, Berkeley and its contributors. 31*4960Swillf * 4. Neither the name of the University nor the names of its contributors 32*4960Swillf * may be used to endorse or promote products derived from this software 33*4960Swillf * without specific prior written permission. 34*4960Swillf * 35*4960Swillf * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 36*4960Swillf * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 37*4960Swillf * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 38*4960Swillf * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 39*4960Swillf * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 40*4960Swillf * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 41*4960Swillf * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 42*4960Swillf * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 43*4960Swillf * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 44*4960Swillf * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 45*4960Swillf * SUCH DAMAGE. 46*4960Swillf * 47*4960Swillf * @(#)queue.h 8.3 (Berkeley) 12/13/93 48*4960Swillf */ 49*4960Swillf 50*4960Swillf #ifndef _QUEUE_H_ 51*4960Swillf #define _QUEUE_H_ 52*4960Swillf 53*4960Swillf /* 54*4960Swillf * This file defines three types of data structures: lists, tail queues, 55*4960Swillf * and circular queues. 56*4960Swillf * 57*4960Swillf * A list is headed by a single forward pointer (or an array of forward 58*4960Swillf * pointers for a hash table header). The elements are doubly linked 59*4960Swillf * so that an arbitrary element can be removed without a need to 60*4960Swillf * traverse the list. New elements can be added to the list after 61*4960Swillf * an existing element or at the head of the list. A list may only be 62*4960Swillf * traversed in the forward direction. 63*4960Swillf * 64*4960Swillf * A tail queue is headed by a pair of pointers, one to the head of the 65*4960Swillf * list and the other to the tail of the list. The elements are doubly 66*4960Swillf * linked so that an arbitrary element can be removed without a need to 67*4960Swillf * traverse the list. New elements can be added to the list after 68*4960Swillf * an existing element, at the head of the list, or at the end of the 69*4960Swillf * list. A tail queue may only be traversed in the forward direction. 70*4960Swillf * 71*4960Swillf * A circle queue is headed by a pair of pointers, one to the head of the 72*4960Swillf * list and the other to the tail of the list. The elements are doubly 73*4960Swillf * linked so that an arbitrary element can be removed without a need to 74*4960Swillf * traverse the list. New elements can be added to the list before or after 75*4960Swillf * an existing element, at the head of the list, or at the end of the list. 76*4960Swillf * A circle queue may be traversed in either direction, but has a more 77*4960Swillf * complex end of list detection. 78*4960Swillf * 79*4960Swillf * For details on the use of these macros, see the queue(3) manual page. 80*4960Swillf */ 81*4960Swillf 82*4960Swillf /* 83*4960Swillf * List definitions. 84*4960Swillf */ 85*4960Swillf #define LIST_HEAD(name, type) \ 86*4960Swillf struct name { \ 87*4960Swillf struct type *lh_first; /* first element */ \ 88*4960Swillf } 89*4960Swillf 90*4960Swillf #define LIST_ENTRY(type) \ 91*4960Swillf struct { \ 92*4960Swillf struct type *le_next; /* next element */ \ 93*4960Swillf struct type **le_prev; /* address of previous next element */ \ 94*4960Swillf } 95*4960Swillf 96*4960Swillf /* 97*4960Swillf * List functions. 98*4960Swillf */ 99*4960Swillf #define LIST_INIT(head) { \ 100*4960Swillf (head)->lh_first = NULL; \ 101*4960Swillf } 102*4960Swillf 103*4960Swillf #define LIST_INSERT_AFTER(listelm, elm, field) { \ 104*4960Swillf if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ 105*4960Swillf (listelm)->field.le_next->field.le_prev = \ 106*4960Swillf &(elm)->field.le_next; \ 107*4960Swillf (listelm)->field.le_next = (elm); \ 108*4960Swillf (elm)->field.le_prev = &(listelm)->field.le_next; \ 109*4960Swillf } 110*4960Swillf 111*4960Swillf #define LIST_INSERT_HEAD(head, elm, field) { \ 112*4960Swillf if (((elm)->field.le_next = (head)->lh_first) != NULL) \ 113*4960Swillf (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ 114*4960Swillf (head)->lh_first = (elm); \ 115*4960Swillf (elm)->field.le_prev = &(head)->lh_first; \ 116*4960Swillf } 117*4960Swillf 118*4960Swillf #define LIST_REMOVE(elm, field) { \ 119*4960Swillf if ((elm)->field.le_next != NULL) \ 120*4960Swillf (elm)->field.le_next->field.le_prev = \ 121*4960Swillf (elm)->field.le_prev; \ 122*4960Swillf *(elm)->field.le_prev = (elm)->field.le_next; \ 123*4960Swillf } 124*4960Swillf 125*4960Swillf /* 126*4960Swillf * Tail queue definitions. 127*4960Swillf */ 128*4960Swillf #define TAILQ_HEAD(name, type) \ 129*4960Swillf struct name { \ 130*4960Swillf struct type *tqh_first; /* first element */ \ 131*4960Swillf struct type **tqh_last; /* addr of last next element */ \ 132*4960Swillf } 133*4960Swillf 134*4960Swillf #define TAILQ_ENTRY(type) \ 135*4960Swillf struct { \ 136*4960Swillf struct type *tqe_next; /* next element */ \ 137*4960Swillf struct type **tqe_prev; /* address of previous next element */ \ 138*4960Swillf } 139*4960Swillf 140*4960Swillf /* 141*4960Swillf * Tail queue functions. 142*4960Swillf */ 143*4960Swillf #define TAILQ_INIT(head) { \ 144*4960Swillf (head)->tqh_first = NULL; \ 145*4960Swillf (head)->tqh_last = &(head)->tqh_first; \ 146*4960Swillf } 147*4960Swillf 148*4960Swillf #define TAILQ_INSERT_HEAD(head, elm, field) { \ 149*4960Swillf if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ 150*4960Swillf (elm)->field.tqe_next->field.tqe_prev = \ 151*4960Swillf &(elm)->field.tqe_next; \ 152*4960Swillf else \ 153*4960Swillf (head)->tqh_last = &(elm)->field.tqe_next; \ 154*4960Swillf (head)->tqh_first = (elm); \ 155*4960Swillf (elm)->field.tqe_prev = &(head)->tqh_first; \ 156*4960Swillf } 157*4960Swillf 158*4960Swillf #define TAILQ_INSERT_TAIL(head, elm, field) { \ 159*4960Swillf (elm)->field.tqe_next = NULL; \ 160*4960Swillf (elm)->field.tqe_prev = (head)->tqh_last; \ 161*4960Swillf *(head)->tqh_last = (elm); \ 162*4960Swillf (head)->tqh_last = &(elm)->field.tqe_next; \ 163*4960Swillf } 164*4960Swillf 165*4960Swillf #define TAILQ_INSERT_AFTER(head, listelm, elm, field) { \ 166*4960Swillf if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ 167*4960Swillf (elm)->field.tqe_next->field.tqe_prev = \ 168*4960Swillf &(elm)->field.tqe_next; \ 169*4960Swillf else \ 170*4960Swillf (head)->tqh_last = &(elm)->field.tqe_next; \ 171*4960Swillf (listelm)->field.tqe_next = (elm); \ 172*4960Swillf (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ 173*4960Swillf } 174*4960Swillf 175*4960Swillf #define TAILQ_REMOVE(head, elm, field) { \ 176*4960Swillf if (((elm)->field.tqe_next) != NULL) \ 177*4960Swillf (elm)->field.tqe_next->field.tqe_prev = \ 178*4960Swillf (elm)->field.tqe_prev; \ 179*4960Swillf else \ 180*4960Swillf (head)->tqh_last = (elm)->field.tqe_prev; \ 181*4960Swillf *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ 182*4960Swillf } 183*4960Swillf 184*4960Swillf /* 185*4960Swillf * Circular queue definitions. 186*4960Swillf */ 187*4960Swillf #define CIRCLEQ_HEAD(name, type) \ 188*4960Swillf struct name { \ 189*4960Swillf struct type *cqh_first; /* first element */ \ 190*4960Swillf struct type *cqh_last; /* last element */ \ 191*4960Swillf } 192*4960Swillf 193*4960Swillf #define CIRCLEQ_ENTRY(type) \ 194*4960Swillf struct { \ 195*4960Swillf struct type *cqe_next; /* next element */ \ 196*4960Swillf struct type *cqe_prev; /* previous element */ \ 197*4960Swillf } 198*4960Swillf 199*4960Swillf /* 200*4960Swillf * Circular queue functions. 201*4960Swillf */ 202*4960Swillf #define CIRCLEQ_INIT(head) { \ 203*4960Swillf (head)->cqh_first = (void *)(head); \ 204*4960Swillf (head)->cqh_last = (void *)(head); \ 205*4960Swillf } 206*4960Swillf 207*4960Swillf #define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) { \ 208*4960Swillf (elm)->field.cqe_next = (listelm)->field.cqe_next; \ 209*4960Swillf (elm)->field.cqe_prev = (listelm); \ 210*4960Swillf if ((listelm)->field.cqe_next == (void *)(head)) \ 211*4960Swillf (head)->cqh_last = (elm); \ 212*4960Swillf else \ 213*4960Swillf (listelm)->field.cqe_next->field.cqe_prev = (elm); \ 214*4960Swillf (listelm)->field.cqe_next = (elm); \ 215*4960Swillf } 216*4960Swillf 217*4960Swillf #define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) { \ 218*4960Swillf (elm)->field.cqe_next = (listelm); \ 219*4960Swillf (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \ 220*4960Swillf if ((listelm)->field.cqe_prev == (void *)(head)) \ 221*4960Swillf (head)->cqh_first = (elm); \ 222*4960Swillf else \ 223*4960Swillf (listelm)->field.cqe_prev->field.cqe_next = (elm); \ 224*4960Swillf (listelm)->field.cqe_prev = (elm); \ 225*4960Swillf } 226*4960Swillf 227*4960Swillf #define CIRCLEQ_INSERT_HEAD(head, elm, field) { \ 228*4960Swillf (elm)->field.cqe_next = (head)->cqh_first; \ 229*4960Swillf (elm)->field.cqe_prev = (void *)(head); \ 230*4960Swillf if ((head)->cqh_last == (void *)(head)) \ 231*4960Swillf (head)->cqh_last = (elm); \ 232*4960Swillf else \ 233*4960Swillf (head)->cqh_first->field.cqe_prev = (elm); \ 234*4960Swillf (head)->cqh_first = (elm); \ 235*4960Swillf } 236*4960Swillf 237*4960Swillf #define CIRCLEQ_INSERT_TAIL(head, elm, field) { \ 238*4960Swillf (elm)->field.cqe_next = (void *)(head); \ 239*4960Swillf (elm)->field.cqe_prev = (head)->cqh_last; \ 240*4960Swillf if ((head)->cqh_first == (void *)(head)) \ 241*4960Swillf (head)->cqh_first = (elm); \ 242*4960Swillf else \ 243*4960Swillf (head)->cqh_last->field.cqe_next = (elm); \ 244*4960Swillf (head)->cqh_last = (elm); \ 245*4960Swillf } 246*4960Swillf 247*4960Swillf #define CIRCLEQ_REMOVE(head, elm, field) { \ 248*4960Swillf if ((elm)->field.cqe_next == (void *)(head)) \ 249*4960Swillf (head)->cqh_last = (elm)->field.cqe_prev; \ 250*4960Swillf else \ 251*4960Swillf (elm)->field.cqe_next->field.cqe_prev = \ 252*4960Swillf (elm)->field.cqe_prev; \ 253*4960Swillf if ((elm)->field.cqe_prev == (void *)(head)) \ 254*4960Swillf (head)->cqh_first = (elm)->field.cqe_next; \ 255*4960Swillf else \ 256*4960Swillf (elm)->field.cqe_prev->field.cqe_next = \ 257*4960Swillf (elm)->field.cqe_next; \ 258*4960Swillf } 259*4960Swillf #endif /* !_QUEUE_H_ */ 260*4960Swillf 261*4960Swillf #ifdef __cplusplus 262*4960Swillf } 263*4960Swillf #endif 264*4960Swillf 265*4960Swillf #endif /* !_KRB5_DB2_DBQUEUE_H */ 266