103 #define QUEUE_MACRO_DEBUG 0
104 #if QUEUE_MACRO_DEBUG
113 #define TRACEBUF struct qm_trace trace;
114 #define TRASHIT(x) do {(x) = (void *)-1;} while (0)
116 #define QMD_TRACE_HEAD(head) do { \
117 (head)->trace.prevline = (head)->trace.lastline; \
118 (head)->trace.prevfile = (head)->trace.lastfile; \
119 (head)->trace.lastline = __LINE__; \
120 (head)->trace.lastfile = __FILE__; \
123 #define QMD_TRACE_ELEM(elem) do { \
124 (elem)->trace.prevline = (elem)->trace.lastline; \
125 (elem)->trace.prevfile = (elem)->trace.lastfile; \
126 (elem)->trace.lastline = __LINE__; \
127 (elem)->trace.lastfile = __FILE__; \
131 #define QMD_TRACE_ELEM(elem)
132 #define QMD_TRACE_HEAD(head)
140 #define SLIST_HEAD(name, type) \
142 struct type *slh_first; \
145 #define SLIST_HEAD_INITIALIZER(head) \
148 #define SLIST_ENTRY(type) \
150 struct type *sle_next; \
156 #define SLIST_EMPTY(head) ((head)->slh_first == NULL)
158 #define SLIST_FIRST(head) ((head)->slh_first)
160 #define SLIST_FOREACH(var, head, field) \
161 for ((var) = SLIST_FIRST((head)); \
163 (var) = SLIST_NEXT((var), field))
165 #define SLIST_FOREACH_SAFE(var, head, field, tvar) \
166 for ((var) = SLIST_FIRST((head)); \
167 (var) && ((tvar) = SLIST_NEXT((var), field), 1); \
170 #define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
171 for ((varp) = &SLIST_FIRST((head)); \
172 ((var) = *(varp)) != NULL; \
173 (varp) = &SLIST_NEXT((var), field))
175 #define SLIST_INIT(head) do { \
176 SLIST_FIRST((head)) = NULL; \
179 #define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
180 SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \
181 SLIST_NEXT((slistelm), field) = (elm); \
184 #define SLIST_INSERT_HEAD(head, elm, field) do { \
185 SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \
186 SLIST_FIRST((head)) = (elm); \
189 #define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
191 #define SLIST_REMOVE(head, elm, type, field) do { \
192 if (SLIST_FIRST((head)) == (elm)) { \
193 SLIST_REMOVE_HEAD((head), field); \
196 struct type *curelm = SLIST_FIRST((head)); \
197 while (SLIST_NEXT(curelm, field) != (elm)) \
198 curelm = SLIST_NEXT(curelm, field); \
199 SLIST_NEXT(curelm, field) = \
200 SLIST_NEXT(SLIST_NEXT(curelm, field), field); \
204 #define SLIST_REMOVE_HEAD(head, field) do { \
205 SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
211 #define STAILQ_HEAD(name, type) \
213 struct type *stqh_first; \
214 struct type **stqh_last; \
217 #define STAILQ_HEAD_INITIALIZER(head) \
218 { NULL, &(head).stqh_first }
220 #define STAILQ_ENTRY(type) \
222 struct type *stqe_next; \
228 #define STAILQ_CONCAT(head1, head2) do { \
229 if (!STAILQ_EMPTY((head2))) { \
230 *(head1)->stqh_last = (head2)->stqh_first; \
231 (head1)->stqh_last = (head2)->stqh_last; \
232 STAILQ_INIT((head2)); \
236 #define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
238 #define STAILQ_FIRST(head) ((head)->stqh_first)
240 #define STAILQ_FOREACH(var, head, field) \
241 for((var) = STAILQ_FIRST((head)); \
243 (var) = STAILQ_NEXT((var), field))
246 #define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
247 for ((var) = STAILQ_FIRST((head)); \
248 (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
251 #define STAILQ_INIT(head) do { \
252 STAILQ_FIRST((head)) = NULL; \
253 (head)->stqh_last = &STAILQ_FIRST((head)); \
256 #define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \
257 if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
258 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
259 STAILQ_NEXT((tqelm), field) = (elm); \
262 #define STAILQ_INSERT_HEAD(head, elm, field) do { \
263 if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
264 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
265 STAILQ_FIRST((head)) = (elm); \
268 #define STAILQ_INSERT_TAIL(head, elm, field) do { \
269 STAILQ_NEXT((elm), field) = NULL; \
270 *(head)->stqh_last = (elm); \
271 (head)->stqh_last = &STAILQ_NEXT((elm), field); \
274 #define STAILQ_LAST(head, type, field) \
275 (STAILQ_EMPTY((head)) ? \
278 ((char *)((head)->stqh_last) - __offsetof(struct type, field))))
280 #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
282 #define STAILQ_REMOVE(head, elm, type, field) do { \
283 if (STAILQ_FIRST((head)) == (elm)) { \
284 STAILQ_REMOVE_HEAD((head), field); \
287 struct type *curelm = STAILQ_FIRST((head)); \
288 while (STAILQ_NEXT(curelm, field) != (elm)) \
289 curelm = STAILQ_NEXT(curelm, field); \
290 if ((STAILQ_NEXT(curelm, field) = \
291 STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\
292 (head)->stqh_last = &STAILQ_NEXT((curelm), field);\
296 #define STAILQ_REMOVE_HEAD(head, field) do { \
297 if ((STAILQ_FIRST((head)) = \
298 STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \
299 (head)->stqh_last = &STAILQ_FIRST((head)); \
302 #define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \
303 if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \
304 (head)->stqh_last = &STAILQ_FIRST((head)); \
310 #define LIST_HEAD(name, type) \
312 struct type *lh_first; \
315 #define LIST_HEAD_INITIALIZER(head) \
318 #define LIST_ENTRY(type) \
320 struct type *le_next; \
321 struct type **le_prev; \
328 #define LIST_EMPTY(head) ((head)->lh_first == NULL)
330 #define LIST_FIRST(head) ((head)->lh_first)
332 #define LIST_FOREACH(var, head, field) \
333 for ((var) = LIST_FIRST((head)); \
335 (var) = LIST_NEXT((var), field))
337 #define LIST_FOREACH_SAFE(var, head, field, tvar) \
338 for ((var) = LIST_FIRST((head)); \
339 (var) && ((tvar) = LIST_NEXT((var), field), 1); \
342 #define LIST_INIT(head) do { \
343 LIST_FIRST((head)) = NULL; \
346 #define LIST_INSERT_AFTER(listelm, elm, field) do { \
347 if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
348 LIST_NEXT((listelm), field)->field.le_prev = \
349 &LIST_NEXT((elm), field); \
350 LIST_NEXT((listelm), field) = (elm); \
351 (elm)->field.le_prev = &LIST_NEXT((listelm), field); \
354 #define LIST_INSERT_BEFORE(listelm, elm, field) do { \
355 (elm)->field.le_prev = (listelm)->field.le_prev; \
356 LIST_NEXT((elm), field) = (listelm); \
357 *(listelm)->field.le_prev = (elm); \
358 (listelm)->field.le_prev = &LIST_NEXT((elm), field); \
361 #define LIST_INSERT_HEAD(head, elm, field) do { \
362 if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
363 LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
364 LIST_FIRST((head)) = (elm); \
365 (elm)->field.le_prev = &LIST_FIRST((head)); \
368 #define LIST_NEXT(elm, field) ((elm)->field.le_next)
370 #define LIST_REMOVE(elm, field) do { \
371 if (LIST_NEXT((elm), field) != NULL) \
372 LIST_NEXT((elm), field)->field.le_prev = \
373 (elm)->field.le_prev; \
374 *(elm)->field.le_prev = LIST_NEXT((elm), field); \
380 #define TAILQ_HEAD(name, type) \
382 struct type *tqh_first; \
383 struct type **tqh_last; \
387 #define TAILQ_HEAD_INITIALIZER(head) \
388 { NULL, &(head).tqh_first }
390 #define TAILQ_ENTRY(type) \
392 struct type *tqe_next; \
393 struct type **tqe_prev; \
400 #define TAILQ_CONCAT(head1, head2, field) do { \
401 if (!TAILQ_EMPTY(head2)) { \
402 *(head1)->tqh_last = (head2)->tqh_first; \
403 (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
404 (head1)->tqh_last = (head2)->tqh_last; \
405 TAILQ_INIT((head2)); \
406 QMD_TRACE_HEAD(head); \
407 QMD_TRACE_HEAD(head2); \
411 #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
413 #define TAILQ_FIRST(head) ((head)->tqh_first)
415 #define TAILQ_FOREACH(var, head, field) \
416 for ((var) = TAILQ_FIRST((head)); \
418 (var) = TAILQ_NEXT((var), field))
420 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
421 for ((var) = TAILQ_FIRST((head)); \
422 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
425 #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
426 for ((var) = TAILQ_LAST((head), headname); \
428 (var) = TAILQ_PREV((var), headname, field))
430 #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
431 for ((var) = TAILQ_LAST((head), headname); \
432 (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
435 #define TAILQ_INIT(head) do { \
436 TAILQ_FIRST((head)) = NULL; \
437 (head)->tqh_last = &TAILQ_FIRST((head)); \
438 QMD_TRACE_HEAD(head); \
441 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
442 if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
443 TAILQ_NEXT((elm), field)->field.tqe_prev = \
444 &TAILQ_NEXT((elm), field); \
446 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
447 QMD_TRACE_HEAD(head); \
449 TAILQ_NEXT((listelm), field) = (elm); \
450 (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
451 QMD_TRACE_ELEM(&(elm)->field); \
452 QMD_TRACE_ELEM(&listelm->field); \
455 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
456 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
457 TAILQ_NEXT((elm), field) = (listelm); \
458 *(listelm)->field.tqe_prev = (elm); \
459 (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
460 QMD_TRACE_ELEM(&(elm)->field); \
461 QMD_TRACE_ELEM(&listelm->field); \
464 #define TAILQ_INSERT_HEAD(head, elm, field) do { \
465 if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
466 TAILQ_FIRST((head))->field.tqe_prev = \
467 &TAILQ_NEXT((elm), field); \
469 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
470 TAILQ_FIRST((head)) = (elm); \
471 (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
472 QMD_TRACE_HEAD(head); \
473 QMD_TRACE_ELEM(&(elm)->field); \
476 #define TAILQ_INSERT_TAIL(head, elm, field) do { \
477 TAILQ_NEXT((elm), field) = NULL; \
478 (elm)->field.tqe_prev = (head)->tqh_last; \
479 *(head)->tqh_last = (elm); \
480 (head)->tqh_last = &TAILQ_NEXT((elm), field); \
481 QMD_TRACE_HEAD(head); \
482 QMD_TRACE_ELEM(&(elm)->field); \
485 #define TAILQ_LAST(head, headname) \
486 (*(((struct headname *)((head)->tqh_last))->tqh_last))
488 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
490 #define TAILQ_PREV(elm, headname, field) \
491 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
493 #define TAILQ_REMOVE(head, elm, field) do { \
494 if ((TAILQ_NEXT((elm), field)) != NULL) \
495 TAILQ_NEXT((elm), field)->field.tqe_prev = \
496 (elm)->field.tqe_prev; \
498 (head)->tqh_last = (elm)->field.tqe_prev; \
499 QMD_TRACE_HEAD(head); \
501 *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
502 TRASHIT((elm)->field.tqe_next); \
503 TRASHIT((elm)->field.tqe_prev); \
504 QMD_TRACE_ELEM(&(elm)->field); \
516 struct quehead *qh_link;
517 struct quehead *qh_rlink;
520 #if defined(__GNUC__) || defined(__INTEL_COMPILER)
523 insque(
void *
a,
void *
b)
525 struct quehead *element = (
struct quehead *)
a,
526 *
head = (
struct quehead *)
b;
528 element->qh_link =
head->qh_link;
529 element->qh_rlink =
head;
530 head->qh_link = element;
531 element->qh_link->qh_rlink = element;
537 struct quehead *element = (
struct quehead *)
a;
539 element->qh_link->qh_rlink = element->qh_rlink;
540 element->qh_rlink->qh_link = element->qh_link;
541 element->qh_rlink = 0;
546 void insque(
void *
a,
void *
b);
547 void remque(
void *
a);