Asterisk - The Open Source Telephony Project
18.5.0
utils
db1-ast
include
circ-queue.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 1991, 1993
3
* The Regents of the University of California. All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. All advertising materials mentioning features or use of this software
14
* must display the following acknowledgement:
15
* This product includes software developed by the University of
16
* California, Berkeley and its contributors.
17
* 4. Neither the name of the University nor the names of its contributors
18
* may be used to endorse or promote products derived from this software
19
* without specific prior written permission.
20
*
21
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31
* SUCH DAMAGE.
32
*
33
* @(#)queue.h 8.5 (Berkeley) 8/20/94
34
* $FreeBSD: ports/misc/44bsd-more/files/queue.h,v 1.1 2001/01/06 03:41:36 hoek Exp $
35
*/
36
37
/*
38
* Circular queue definitions.
39
*/
40
#define CIRCLEQ_HEAD(name, type) \
41
struct name { \
42
struct type *cqh_first;
/* first element */
\
43
struct type *cqh_last;
/* last element */
\
44
}
45
46
#define CIRCLEQ_ENTRY(type) \
47
struct { \
48
struct type *cqe_next;
/* next element */
\
49
struct type *cqe_prev;
/* previous element */
\
50
}
51
52
/*
53
* Circular queue functions.
54
*/
55
#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
56
57
#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
58
59
#define CIRCLEQ_FOREACH(var, head, field) \
60
for((var) = (head)->cqh_first; \
61
(var) != (void *)(head); \
62
(var) = (var)->field.cqe_next)
63
64
#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
65
for((var) = (head)->cqh_last; \
66
(var) != (void *)(head); \
67
(var) = (var)->field.cqe_prev)
68
69
#define CIRCLEQ_INIT(head) do { \
70
(head)->cqh_first = (void *)(head); \
71
(head)->cqh_last = (void *)(head); \
72
} while (0)
73
74
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
75
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
76
(elm)->field.cqe_prev = (listelm); \
77
if ((listelm)->field.cqe_next == (void *)(head)) \
78
(head)->cqh_last = (elm); \
79
else \
80
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
81
(listelm)->field.cqe_next = (elm); \
82
} while (0)
83
84
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
85
(elm)->field.cqe_next = (listelm); \
86
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
87
if ((listelm)->field.cqe_prev == (void *)(head)) \
88
(head)->cqh_first = (elm); \
89
else \
90
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
91
(listelm)->field.cqe_prev = (elm); \
92
} while (0)
93
94
#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
95
(elm)->field.cqe_next = (head)->cqh_first; \
96
(elm)->field.cqe_prev = (void *)(head); \
97
if ((head)->cqh_last == (void *)(head)) \
98
(head)->cqh_last = (elm); \
99
else \
100
(head)->cqh_first->field.cqe_prev = (elm); \
101
(head)->cqh_first = (elm); \
102
} while (0)
103
104
#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
105
(elm)->field.cqe_next = (void *)(head); \
106
(elm)->field.cqe_prev = (head)->cqh_last; \
107
if ((head)->cqh_first == (void *)(head)) \
108
(head)->cqh_first = (elm); \
109
else \
110
(head)->cqh_last->field.cqe_next = (elm); \
111
(head)->cqh_last = (elm); \
112
} while (0)
113
114
#define CIRCLEQ_LAST(head) ((head)->cqh_last)
115
116
#define CIRCLEQ_NEXT(elm,field) ((elm)->field.cqe_next)
117
118
#define CIRCLEQ_PREV(elm,field) ((elm)->field.cqe_prev)
119
120
#define CIRCLEQ_REMOVE(head, elm, field) do { \
121
if ((elm)->field.cqe_next == (void *)(head)) \
122
(head)->cqh_last = (elm)->field.cqe_prev; \
123
else \
124
(elm)->field.cqe_next->field.cqe_prev = \
125
(elm)->field.cqe_prev; \
126
if ((elm)->field.cqe_prev == (void *)(head)) \
127
(head)->cqh_first = (elm)->field.cqe_next; \
128
else \
129
(elm)->field.cqe_prev->field.cqe_next = \
130
(elm)->field.cqe_next; \
131
} while (0)
Generated on Sun Aug 8 2021 19:43:38 for Asterisk - The Open Source Telephony Project by
1.8.13