circ-queue.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1991, 1993
00003  * The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  * This product includes software developed by the University of
00016  * California, Berkeley and its contributors.
00017  * 4. Neither the name of the University nor the names of its contributors
00018  *    may be used to endorse or promote products derived from this software
00019  *    without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  * @(#)queue.h 8.5 (Berkeley) 8/20/94
00034  * $FreeBSD: ports/misc/44bsd-more/files/queue.h,v 1.1 2001/01/06 03:41:36 hoek Exp $
00035  */
00036 
00037 /*
00038  * Circular queue definitions.
00039  */
00040 #define CIRCLEQ_HEAD(name, type)             \
00041 struct name {                       \
00042    struct type *cqh_first;    /* first element */     \
00043    struct type *cqh_last;     /* last element */      \
00044 }
00045 
00046 #define CIRCLEQ_ENTRY(type)                  \
00047 struct {                      \
00048    struct type *cqe_next;     /* next element */      \
00049    struct type *cqe_prev;     /* previous element */     \
00050 }
00051 
00052 /*
00053  * Circular queue functions.
00054  */
00055 #define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
00056 
00057 #define CIRCLEQ_FIRST(head) ((head)->cqh_first)
00058 
00059 #define CIRCLEQ_FOREACH(var, head, field)          \
00060    for((var) = (head)->cqh_first;               \
00061        (var) != (void *)(head);              \
00062        (var) = (var)->field.cqe_next)
00063 
00064 #define CIRCLEQ_FOREACH_REVERSE(var, head, field)        \
00065    for((var) = (head)->cqh_last;             \
00066        (var) != (void *)(head);              \
00067        (var) = (var)->field.cqe_prev)
00068 
00069 #define  CIRCLEQ_INIT(head) do {                \
00070    (head)->cqh_first = (void *)(head);          \
00071    (head)->cqh_last = (void *)(head);           \
00072 } while (0)
00073 
00074 #define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do {      \
00075    (elm)->field.cqe_next = (listelm)->field.cqe_next;    \
00076    (elm)->field.cqe_prev = (listelm);           \
00077    if ((listelm)->field.cqe_next == (void *)(head))      \
00078       (head)->cqh_last = (elm);           \
00079    else                       \
00080       (listelm)->field.cqe_next->field.cqe_prev = (elm); \
00081    (listelm)->field.cqe_next = (elm);           \
00082 } while (0)
00083 
00084 #define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do {     \
00085    (elm)->field.cqe_next = (listelm);           \
00086    (elm)->field.cqe_prev = (listelm)->field.cqe_prev;    \
00087    if ((listelm)->field.cqe_prev == (void *)(head))      \
00088       (head)->cqh_first = (elm);          \
00089    else                       \
00090       (listelm)->field.cqe_prev->field.cqe_next = (elm); \
00091    (listelm)->field.cqe_prev = (elm);           \
00092 } while (0)
00093 
00094 #define CIRCLEQ_INSERT_HEAD(head, elm, field) do {       \
00095    (elm)->field.cqe_next = (head)->cqh_first;         \
00096    (elm)->field.cqe_prev = (void *)(head);            \
00097    if ((head)->cqh_last == (void *)(head))            \
00098       (head)->cqh_last = (elm);           \
00099    else                       \
00100       (head)->cqh_first->field.cqe_prev = (elm);      \
00101    (head)->cqh_first = (elm);             \
00102 } while (0)
00103 
00104 #define CIRCLEQ_INSERT_TAIL(head, elm, field) do {       \
00105    (elm)->field.cqe_next = (void *)(head);            \
00106    (elm)->field.cqe_prev = (head)->cqh_last;       \
00107    if ((head)->cqh_first == (void *)(head))        \
00108       (head)->cqh_first = (elm);          \
00109    else                       \
00110       (head)->cqh_last->field.cqe_next = (elm);    \
00111    (head)->cqh_last = (elm);              \
00112 } while (0)
00113 
00114 #define CIRCLEQ_LAST(head) ((head)->cqh_last)
00115 
00116 #define CIRCLEQ_NEXT(elm,field) ((elm)->field.cqe_next)
00117 
00118 #define CIRCLEQ_PREV(elm,field) ((elm)->field.cqe_prev)
00119 
00120 #define  CIRCLEQ_REMOVE(head, elm, field) do {           \
00121    if ((elm)->field.cqe_next == (void *)(head))       \
00122       (head)->cqh_last = (elm)->field.cqe_prev;    \
00123    else                       \
00124       (elm)->field.cqe_next->field.cqe_prev =         \
00125           (elm)->field.cqe_prev;          \
00126    if ((elm)->field.cqe_prev == (void *)(head))       \
00127       (head)->cqh_first = (elm)->field.cqe_next;      \
00128    else                       \
00129       (elm)->field.cqe_prev->field.cqe_next =         \
00130           (elm)->field.cqe_next;          \
00131 } while (0)

Generated on Thu Apr 16 06:27:30 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6