1*ebfedea0SLionel Sambuc /* $NetBSD: asn1_queue.h,v 1.1.1.2 2011/04/14 14:08:19 elric Exp $ */ 2*ebfedea0SLionel Sambuc 3*ebfedea0SLionel Sambuc /* NetBSD: queue.h,v 1.38 2004/04/18 14:12:05 lukem Exp */ 4*ebfedea0SLionel Sambuc /* Id */ 5*ebfedea0SLionel Sambuc 6*ebfedea0SLionel Sambuc /* 7*ebfedea0SLionel Sambuc * Copyright (c) 1991, 1993 8*ebfedea0SLionel Sambuc * The Regents of the University of California. All rights reserved. 9*ebfedea0SLionel Sambuc * 10*ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without 11*ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions 12*ebfedea0SLionel Sambuc * are met: 13*ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the above copyright 14*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer. 15*ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 16*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in the 17*ebfedea0SLionel Sambuc * documentation and/or other materials provided with the distribution. 18*ebfedea0SLionel Sambuc * 3. Neither the name of the University nor the names of its contributors 19*ebfedea0SLionel Sambuc * may be used to endorse or promote products derived from this software 20*ebfedea0SLionel Sambuc * without specific prior written permission. 21*ebfedea0SLionel Sambuc * 22*ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*ebfedea0SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*ebfedea0SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*ebfedea0SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*ebfedea0SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*ebfedea0SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*ebfedea0SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*ebfedea0SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*ebfedea0SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*ebfedea0SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*ebfedea0SLionel Sambuc * SUCH DAMAGE. 33*ebfedea0SLionel Sambuc * 34*ebfedea0SLionel Sambuc * @(#)queue.h 8.5 (Berkeley) 8/20/94 35*ebfedea0SLionel Sambuc */ 36*ebfedea0SLionel Sambuc 37*ebfedea0SLionel Sambuc #ifndef _ASN1_QUEUE_H_ 38*ebfedea0SLionel Sambuc #define _ASN1_QUEUE_H_ 39*ebfedea0SLionel Sambuc 40*ebfedea0SLionel Sambuc /* 41*ebfedea0SLionel Sambuc * Tail queue definitions. 42*ebfedea0SLionel Sambuc */ 43*ebfedea0SLionel Sambuc #define ASN1_TAILQ_HEAD(name, type) \ 44*ebfedea0SLionel Sambuc struct name { \ 45*ebfedea0SLionel Sambuc struct type *tqh_first; /* first element */ \ 46*ebfedea0SLionel Sambuc struct type **tqh_last; /* addr of last next element */ \ 47*ebfedea0SLionel Sambuc } 48*ebfedea0SLionel Sambuc 49*ebfedea0SLionel Sambuc #define ASN1_TAILQ_HEAD_INITIALIZER(head) \ 50*ebfedea0SLionel Sambuc { NULL, &(head).tqh_first } 51*ebfedea0SLionel Sambuc #define ASN1_TAILQ_ENTRY(type) \ 52*ebfedea0SLionel Sambuc struct { \ 53*ebfedea0SLionel Sambuc struct type *tqe_next; /* next element */ \ 54*ebfedea0SLionel Sambuc struct type **tqe_prev; /* address of previous next element */ \ 55*ebfedea0SLionel Sambuc } 56*ebfedea0SLionel Sambuc 57*ebfedea0SLionel Sambuc /* 58*ebfedea0SLionel Sambuc * Tail queue functions. 59*ebfedea0SLionel Sambuc */ 60*ebfedea0SLionel Sambuc #if defined(_KERNEL) && defined(QUEUEDEBUG) 61*ebfedea0SLionel Sambuc #define QUEUEDEBUG_ASN1_TAILQ_INSERT_HEAD(head, elm, field) \ 62*ebfedea0SLionel Sambuc if ((head)->tqh_first && \ 63*ebfedea0SLionel Sambuc (head)->tqh_first->field.tqe_prev != &(head)->tqh_first) \ 64*ebfedea0SLionel Sambuc panic("ASN1_TAILQ_INSERT_HEAD %p %s:%d", (head), __FILE__, __LINE__); 65*ebfedea0SLionel Sambuc #define QUEUEDEBUG_ASN1_TAILQ_INSERT_TAIL(head, elm, field) \ 66*ebfedea0SLionel Sambuc if (*(head)->tqh_last != NULL) \ 67*ebfedea0SLionel Sambuc panic("ASN1_TAILQ_INSERT_TAIL %p %s:%d", (head), __FILE__, __LINE__); 68*ebfedea0SLionel Sambuc #define QUEUEDEBUG_ASN1_TAILQ_OP(elm, field) \ 69*ebfedea0SLionel Sambuc if ((elm)->field.tqe_next && \ 70*ebfedea0SLionel Sambuc (elm)->field.tqe_next->field.tqe_prev != \ 71*ebfedea0SLionel Sambuc &(elm)->field.tqe_next) \ 72*ebfedea0SLionel Sambuc panic("ASN1_TAILQ_* forw %p %s:%d", (elm), __FILE__, __LINE__);\ 73*ebfedea0SLionel Sambuc if (*(elm)->field.tqe_prev != (elm)) \ 74*ebfedea0SLionel Sambuc panic("ASN1_TAILQ_* back %p %s:%d", (elm), __FILE__, __LINE__); 75*ebfedea0SLionel Sambuc #define QUEUEDEBUG_ASN1_TAILQ_PREREMOVE(head, elm, field) \ 76*ebfedea0SLionel Sambuc if ((elm)->field.tqe_next == NULL && \ 77*ebfedea0SLionel Sambuc (head)->tqh_last != &(elm)->field.tqe_next) \ 78*ebfedea0SLionel Sambuc panic("ASN1_TAILQ_PREREMOVE head %p elm %p %s:%d", \ 79*ebfedea0SLionel Sambuc (head), (elm), __FILE__, __LINE__); 80*ebfedea0SLionel Sambuc #define QUEUEDEBUG_ASN1_TAILQ_POSTREMOVE(elm, field) \ 81*ebfedea0SLionel Sambuc (elm)->field.tqe_next = (void *)1L; \ 82*ebfedea0SLionel Sambuc (elm)->field.tqe_prev = (void *)1L; 83*ebfedea0SLionel Sambuc #else 84*ebfedea0SLionel Sambuc #define QUEUEDEBUG_ASN1_TAILQ_INSERT_HEAD(head, elm, field) 85*ebfedea0SLionel Sambuc #define QUEUEDEBUG_ASN1_TAILQ_INSERT_TAIL(head, elm, field) 86*ebfedea0SLionel Sambuc #define QUEUEDEBUG_ASN1_TAILQ_OP(elm, field) 87*ebfedea0SLionel Sambuc #define QUEUEDEBUG_ASN1_TAILQ_PREREMOVE(head, elm, field) 88*ebfedea0SLionel Sambuc #define QUEUEDEBUG_ASN1_TAILQ_POSTREMOVE(elm, field) 89*ebfedea0SLionel Sambuc #endif 90*ebfedea0SLionel Sambuc 91*ebfedea0SLionel Sambuc #define ASN1_TAILQ_INIT(head) do { \ 92*ebfedea0SLionel Sambuc (head)->tqh_first = NULL; \ 93*ebfedea0SLionel Sambuc (head)->tqh_last = &(head)->tqh_first; \ 94*ebfedea0SLionel Sambuc } while (/*CONSTCOND*/0) 95*ebfedea0SLionel Sambuc 96*ebfedea0SLionel Sambuc #define ASN1_TAILQ_INSERT_HEAD(head, elm, field) do { \ 97*ebfedea0SLionel Sambuc QUEUEDEBUG_ASN1_TAILQ_INSERT_HEAD((head), (elm), field) \ 98*ebfedea0SLionel Sambuc if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ 99*ebfedea0SLionel Sambuc (head)->tqh_first->field.tqe_prev = \ 100*ebfedea0SLionel Sambuc &(elm)->field.tqe_next; \ 101*ebfedea0SLionel Sambuc else \ 102*ebfedea0SLionel Sambuc (head)->tqh_last = &(elm)->field.tqe_next; \ 103*ebfedea0SLionel Sambuc (head)->tqh_first = (elm); \ 104*ebfedea0SLionel Sambuc (elm)->field.tqe_prev = &(head)->tqh_first; \ 105*ebfedea0SLionel Sambuc } while (/*CONSTCOND*/0) 106*ebfedea0SLionel Sambuc 107*ebfedea0SLionel Sambuc #define ASN1_TAILQ_INSERT_TAIL(head, elm, field) do { \ 108*ebfedea0SLionel Sambuc QUEUEDEBUG_ASN1_TAILQ_INSERT_TAIL((head), (elm), field) \ 109*ebfedea0SLionel Sambuc (elm)->field.tqe_next = NULL; \ 110*ebfedea0SLionel Sambuc (elm)->field.tqe_prev = (head)->tqh_last; \ 111*ebfedea0SLionel Sambuc *(head)->tqh_last = (elm); \ 112*ebfedea0SLionel Sambuc (head)->tqh_last = &(elm)->field.tqe_next; \ 113*ebfedea0SLionel Sambuc } while (/*CONSTCOND*/0) 114*ebfedea0SLionel Sambuc 115*ebfedea0SLionel Sambuc #define ASN1_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ 116*ebfedea0SLionel Sambuc QUEUEDEBUG_ASN1_TAILQ_OP((listelm), field) \ 117*ebfedea0SLionel Sambuc if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ 118*ebfedea0SLionel Sambuc (elm)->field.tqe_next->field.tqe_prev = \ 119*ebfedea0SLionel Sambuc &(elm)->field.tqe_next; \ 120*ebfedea0SLionel Sambuc else \ 121*ebfedea0SLionel Sambuc (head)->tqh_last = &(elm)->field.tqe_next; \ 122*ebfedea0SLionel Sambuc (listelm)->field.tqe_next = (elm); \ 123*ebfedea0SLionel Sambuc (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ 124*ebfedea0SLionel Sambuc } while (/*CONSTCOND*/0) 125*ebfedea0SLionel Sambuc 126*ebfedea0SLionel Sambuc #define ASN1_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ 127*ebfedea0SLionel Sambuc QUEUEDEBUG_ASN1_TAILQ_OP((listelm), field) \ 128*ebfedea0SLionel Sambuc (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ 129*ebfedea0SLionel Sambuc (elm)->field.tqe_next = (listelm); \ 130*ebfedea0SLionel Sambuc *(listelm)->field.tqe_prev = (elm); \ 131*ebfedea0SLionel Sambuc (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ 132*ebfedea0SLionel Sambuc } while (/*CONSTCOND*/0) 133*ebfedea0SLionel Sambuc 134*ebfedea0SLionel Sambuc #define ASN1_TAILQ_REMOVE(head, elm, field) do { \ 135*ebfedea0SLionel Sambuc QUEUEDEBUG_ASN1_TAILQ_PREREMOVE((head), (elm), field) \ 136*ebfedea0SLionel Sambuc QUEUEDEBUG_ASN1_TAILQ_OP((elm), field) \ 137*ebfedea0SLionel Sambuc if (((elm)->field.tqe_next) != NULL) \ 138*ebfedea0SLionel Sambuc (elm)->field.tqe_next->field.tqe_prev = \ 139*ebfedea0SLionel Sambuc (elm)->field.tqe_prev; \ 140*ebfedea0SLionel Sambuc else \ 141*ebfedea0SLionel Sambuc (head)->tqh_last = (elm)->field.tqe_prev; \ 142*ebfedea0SLionel Sambuc *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ 143*ebfedea0SLionel Sambuc QUEUEDEBUG_ASN1_TAILQ_POSTREMOVE((elm), field); \ 144*ebfedea0SLionel Sambuc } while (/*CONSTCOND*/0) 145*ebfedea0SLionel Sambuc 146*ebfedea0SLionel Sambuc #define ASN1_TAILQ_FOREACH(var, head, field) \ 147*ebfedea0SLionel Sambuc for ((var) = ((head)->tqh_first); \ 148*ebfedea0SLionel Sambuc (var); \ 149*ebfedea0SLionel Sambuc (var) = ((var)->field.tqe_next)) 150*ebfedea0SLionel Sambuc 151*ebfedea0SLionel Sambuc #define ASN1_TAILQ_FOREACH_REVERSE(var, head, headname, field) \ 152*ebfedea0SLionel Sambuc for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \ 153*ebfedea0SLionel Sambuc (var); \ 154*ebfedea0SLionel Sambuc (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last))) 155*ebfedea0SLionel Sambuc 156*ebfedea0SLionel Sambuc /* 157*ebfedea0SLionel Sambuc * Tail queue access methods. 158*ebfedea0SLionel Sambuc */ 159*ebfedea0SLionel Sambuc #define ASN1_TAILQ_EMPTY(head) ((head)->tqh_first == NULL) 160*ebfedea0SLionel Sambuc #define ASN1_TAILQ_FIRST(head) ((head)->tqh_first) 161*ebfedea0SLionel Sambuc #define ASN1_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) 162*ebfedea0SLionel Sambuc 163*ebfedea0SLionel Sambuc #define ASN1_TAILQ_LAST(head, headname) \ 164*ebfedea0SLionel Sambuc (*(((struct headname *)((head)->tqh_last))->tqh_last)) 165*ebfedea0SLionel Sambuc #define ASN1_TAILQ_PREV(elm, headname, field) \ 166*ebfedea0SLionel Sambuc (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) 167*ebfedea0SLionel Sambuc 168*ebfedea0SLionel Sambuc 169*ebfedea0SLionel Sambuc #endif /* !_ASN1_QUEUE_H_ */ 170