| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
#define CIRCLEQ_HEAD(name, type) \ |
| 41 |
struct name { \ |
| 42 |
struct type *cqh_first; \ |
| 43 |
struct type *cqh_last; \ |
| 44 |
} |
| 45 |
|
| 46 |
#define CIRCLEQ_ENTRY(type) \ |
| 47 |
struct { \ |
| 48 |
struct type *cqe_next; \ |
| 49 |
struct type *cqe_prev; \ |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 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) |