Loading...
Searching...
No Matches
118#define CIRCLEQ_HEAD(name, type) \
120 struct type *cqh_first; \
121 struct type *cqh_last; \
124#define CIRCLEQ_HEAD_INITIALIZER(head) \
125 { (void *)&(head), (void *)&(head) }
127#define CIRCLEQ_ENTRY(type) \
129 struct type *cqe_next; \
130 struct type *cqe_prev; \
136#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
138#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
140#define CIRCLEQ_FOREACH(var, head, field) \
141 for ((var) = CIRCLEQ_FIRST((head)); \
142 (var) != (void *)(head) || ((var) = NULL); \
143 (var) = CIRCLEQ_NEXT((var), field))
145#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
146 for ((var) = CIRCLEQ_LAST((head)); \
147 (var) != (void *)(head) || ((var) = NULL); \
148 (var) = CIRCLEQ_PREV((var), field))
150#define CIRCLEQ_INIT(head) do { \
151 CIRCLEQ_FIRST((head)) = (void *)(head); \
152 CIRCLEQ_LAST((head)) = (void *)(head); \
155#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
156 CIRCLEQ_NEXT((elm), field) = CIRCLEQ_NEXT((listelm), field); \
157 CIRCLEQ_PREV((elm), field) = (listelm); \
158 if (CIRCLEQ_NEXT((listelm), field) == (void *)(head)) \
159 CIRCLEQ_LAST((head)) = (elm); \
161 CIRCLEQ_PREV(CIRCLEQ_NEXT((listelm), field), field) = (elm);\
162 CIRCLEQ_NEXT((listelm), field) = (elm); \
165#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
166 CIRCLEQ_NEXT((elm), field) = (listelm); \
167 CIRCLEQ_PREV((elm), field) = CIRCLEQ_PREV((listelm), field); \
168 if (CIRCLEQ_PREV((listelm), field) == (void *)(head)) \
169 CIRCLEQ_FIRST((head)) = (elm); \
171 CIRCLEQ_NEXT(CIRCLEQ_PREV((listelm), field), field) = (elm);\
172 CIRCLEQ_PREV((listelm), field) = (elm); \
175#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
176 CIRCLEQ_NEXT((elm), field) = CIRCLEQ_FIRST((head)); \
177 CIRCLEQ_PREV((elm), field) = (void *)(head); \
178 if (CIRCLEQ_LAST((head)) == (void *)(head)) \
179 CIRCLEQ_LAST((head)) = (elm); \
181 CIRCLEQ_PREV(CIRCLEQ_FIRST((head)), field) = (elm); \
182 CIRCLEQ_FIRST((head)) = (elm); \
185#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
186 CIRCLEQ_NEXT((elm), field) = (void *)(head); \
187 CIRCLEQ_PREV((elm), field) = CIRCLEQ_LAST((head)); \
188 if (CIRCLEQ_FIRST((head)) == (void *)(head)) \
189 CIRCLEQ_FIRST((head)) = (elm); \
191 CIRCLEQ_NEXT(CIRCLEQ_LAST((head)), field) = (elm); \
192 CIRCLEQ_LAST((head)) = (elm); \
195#define CIRCLEQ_LAST(head) ((head)->cqh_last)
197#define CIRCLEQ_NEXT(elm,field) ((elm)->field.cqe_next)
199#define CIRCLEQ_PREV(elm,field) ((elm)->field.cqe_prev)
201#define CIRCLEQ_REMOVE(head, elm, field) do { \
202 if (CIRCLEQ_NEXT((elm), field) == (void *)(head)) \
203 CIRCLEQ_LAST((head)) = CIRCLEQ_PREV((elm), field); \
205 CIRCLEQ_PREV(CIRCLEQ_NEXT((elm), field), field) = \
206 CIRCLEQ_PREV((elm), field); \
207 if (CIRCLEQ_PREV((elm), field) == (void *)(head)) \
208 CIRCLEQ_FIRST((head)) = CIRCLEQ_NEXT((elm), field); \
210 CIRCLEQ_NEXT(CIRCLEQ_PREV((elm), field), field) = \
211 CIRCLEQ_NEXT((elm), field); \