00001
00002
00003
00004
00005 #ifndef _U_QUEUE_H_
00006 #define _U_QUEUE_H_
00007
00008
00009
00010
00011
00012
00013
00014
00015 #define LIST_HEAD(name, type) \
00016 struct name { \
00017 struct type *lh_first; \
00018 }
00019
00020 #define LIST_HEAD_INITIALIZER(head) \
00021 { NULL }
00022
00023 #define LIST_ENTRY(type) \
00024 struct { \
00025 struct type *le_next; \
00026 struct type **le_prev; \
00027 }
00028
00029 #define LIST_FIRST(head) ((head)->lh_first)
00030 #define LIST_END(head) NULL
00031 #define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head))
00032 #define LIST_NEXT(elm, field) ((elm)->field.le_next)
00033
00034 #define LIST_FOREACH(var, head, field) \
00035 for((var) = LIST_FIRST(head); \
00036 (var)!= LIST_END(head); \
00037 (var) = LIST_NEXT(var, field))
00038
00039 #define LIST_INIT(head) do { \
00040 LIST_FIRST(head) = LIST_END(head); \
00041 } while (0)
00042
00043 #define LIST_INSERT_AFTER(listelm, elm, field) do { \
00044 if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
00045 (listelm)->field.le_next->field.le_prev = \
00046 &(elm)->field.le_next; \
00047 (listelm)->field.le_next = (elm); \
00048 (elm)->field.le_prev = &(listelm)->field.le_next; \
00049 } while (0)
00050
00051 #define LIST_INSERT_BEFORE(listelm, elm, field) do { \
00052 (elm)->field.le_prev = (listelm)->field.le_prev; \
00053 (elm)->field.le_next = (listelm); \
00054 *(listelm)->field.le_prev = (elm); \
00055 (listelm)->field.le_prev = &(elm)->field.le_next; \
00056 } while (0)
00057
00058 #define LIST_INSERT_HEAD(head, elm, field) do { \
00059 if (((elm)->field.le_next = (head)->lh_first) != NULL) \
00060 (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
00061 (head)->lh_first = (elm); \
00062 (elm)->field.le_prev = &(head)->lh_first; \
00063 } while (0)
00064
00065 #define LIST_REMOVE(elm, field) do { \
00066 if ((elm)->field.le_next != NULL) \
00067 (elm)->field.le_next->field.le_prev = \
00068 (elm)->field.le_prev; \
00069 *(elm)->field.le_prev = (elm)->field.le_next; \
00070 } while (0)
00071
00072 #define LIST_REPLACE(elm, elm2, field) do { \
00073 if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
00074 (elm2)->field.le_next->field.le_prev = \
00075 &(elm2)->field.le_next; \
00076 (elm2)->field.le_prev = (elm)->field.le_prev; \
00077 *(elm2)->field.le_prev = (elm2); \
00078 } while (0)
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 #define TAILQ_HEAD(name, type) \
00090 struct name { \
00091 struct type *tqh_first; \
00092 struct type **tqh_last; \
00093 }
00094
00095 #define TAILQ_ENTRY(type) \
00096 struct { \
00097 struct type *tqe_next; \
00098 struct type **tqe_prev; \
00099 }
00100
00101
00102 #define TAILQ_INIT(head) { \
00103 (head)->tqh_first = NULL; \
00104 (head)->tqh_last = &(head)->tqh_first; \
00105 }
00106
00107 #define TAILQ_INSERT_HEAD(head, elm, field) { \
00108 if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
00109 (elm)->field.tqe_next->field.tqe_prev = \
00110 &(elm)->field.tqe_next; \
00111 else \
00112 (head)->tqh_last = &(elm)->field.tqe_next; \
00113 (head)->tqh_first = (elm); \
00114 (elm)->field.tqe_prev = &(head)->tqh_first; \
00115 }
00116
00117 #define TAILQ_INSERT_TAIL(head, elm, field) { \
00118 (elm)->field.tqe_next = NULL; \
00119 (elm)->field.tqe_prev = (head)->tqh_last; \
00120 *(head)->tqh_last = (elm); \
00121 (head)->tqh_last = &(elm)->field.tqe_next; \
00122 }
00123
00124 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) { \
00125 if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL) \
00126 (elm)->field.tqe_next->field.tqe_prev = \
00127 &(elm)->field.tqe_next; \
00128 else \
00129 (head)->tqh_last = &(elm)->field.tqe_next; \
00130 (listelm)->field.tqe_next = (elm); \
00131 (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
00132 }
00133
00134 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
00135 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
00136 (elm)->field.tqe_next = (listelm); \
00137 *(listelm)->field.tqe_prev = (elm); \
00138 (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
00139 } while (0)
00140
00141 #define TAILQ_REMOVE(head, elm, field) { \
00142 if (((elm)->field.tqe_next) != NULL) \
00143 (elm)->field.tqe_next->field.tqe_prev = \
00144 (elm)->field.tqe_prev; \
00145 else \
00146 (head)->tqh_last = (elm)->field.tqe_prev; \
00147 *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 #define CIRCLEQ_HEAD(name, type) \
00161 struct name { \
00162 struct type *cqh_first; \
00163 struct type *cqh_last; \
00164 }
00165
00166 #define CIRCLEQ_ENTRY(type) \
00167 struct { \
00168 struct type *cqe_next; \
00169 struct type *cqe_prev; \
00170 }
00171
00172
00173 #define CIRCLEQ_INIT(head) { \
00174 (head)->cqh_first = (void *)(head); \
00175 (head)->cqh_last = (void *)(head); \
00176 }
00177
00178 #define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) { \
00179 (elm)->field.cqe_next = (listelm)->field.cqe_next; \
00180 (elm)->field.cqe_prev = (listelm); \
00181 if ((listelm)->field.cqe_next == (void *)(head)) \
00182 (head)->cqh_last = (elm); \
00183 else \
00184 (listelm)->field.cqe_next->field.cqe_prev = (elm); \
00185 (listelm)->field.cqe_next = (elm); \
00186 }
00187
00188 #define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) { \
00189 (elm)->field.cqe_next = (listelm); \
00190 (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
00191 if ((listelm)->field.cqe_prev == (void *)(head)) \
00192 (head)->cqh_first = (elm); \
00193 else \
00194 (listelm)->field.cqe_prev->field.cqe_next = (elm); \
00195 (listelm)->field.cqe_prev = (elm); \
00196 }
00197
00198 #define CIRCLEQ_INSERT_HEAD(head, elm, field) { \
00199 (elm)->field.cqe_next = (head)->cqh_first; \
00200 (elm)->field.cqe_prev = (void *)(head); \
00201 if ((head)->cqh_last == (void *)(head)) \
00202 (head)->cqh_last = (elm); \
00203 else \
00204 (head)->cqh_first->field.cqe_prev = (elm); \
00205 (head)->cqh_first = (elm); \
00206 }
00207
00208 #define CIRCLEQ_INSERT_TAIL(head, elm, field) { \
00209 (elm)->field.cqe_next = (void *)(head); \
00210 (elm)->field.cqe_prev = (head)->cqh_last; \
00211 if ((head)->cqh_first == (void *)(head)) \
00212 (head)->cqh_first = (elm); \
00213 else \
00214 (head)->cqh_last->field.cqe_next = (elm); \
00215 (head)->cqh_last = (elm); \
00216 }
00217
00218 #define CIRCLEQ_REMOVE(head, elm, field) { \
00219 if ((elm)->field.cqe_next == (void *)(head)) \
00220 (head)->cqh_last = (elm)->field.cqe_prev; \
00221 else \
00222 (elm)->field.cqe_next->field.cqe_prev = \
00223 (elm)->field.cqe_prev; \
00224 if ((elm)->field.cqe_prev == (void *)(head)) \
00225 (head)->cqh_first = (elm)->field.cqe_next; \
00226 else \
00227 (elm)->field.cqe_prev->field.cqe_next = \
00228 (elm)->field.cqe_next; \
00229 }
00230
00231 #ifndef LIST_ENTRY_NULL
00232 #define LIST_ENTRY_NULL { NULL, NULL }
00233 #endif
00234
00235 #ifndef LIST_FOREACH_SAFE
00236 #define LIST_FOREACH_SAFE(var, head, field, tvar) \
00237 for ((var) = LIST_FIRST((head)); \
00238 (var) && ((tvar) = LIST_NEXT((var), field), 1); \
00239 (var) = (tvar))
00240 #endif
00241
00242 #ifndef LIST_FIRST
00243 #define LIST_FIRST(head) ((head)->lh_first)
00244 #endif
00245
00246 #ifndef TAILQ_ENTRY_NULL
00247 #define TAILQ_ENTRY_NULL { NULL, NULL }
00248 #endif
00249
00250 #ifndef TAILQ_FIRST
00251 #define TAILQ_FIRST(head) ((head)->tqh_first)
00252 #endif
00253
00254 #ifndef TAILQ_END
00255 #define TAILQ_END(head) NULL
00256 #endif
00257
00258 #ifndef TAILQ_NEXT
00259 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
00260 #endif
00261
00262 #ifndef TAILQ_LAST
00263 #define TAILQ_LAST(head, headname) \
00264 (*(((struct headname *)((head)->tqh_last))->tqh_last))
00265 #endif
00266
00267 #ifndef TAILQ_PREV
00268 #define TAILQ_PREV(elm, headname, field) \
00269 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
00270 #endif
00271
00272 #ifndef TAILQ_EMPTY
00273 #define TAILQ_EMPTY(head) \
00274 (TAILQ_FIRST(head) == TAILQ_END(head))
00275 #endif
00276
00277 #ifndef TAILQ_FOREACH
00278 #define TAILQ_FOREACH(var, head, field) \
00279 for((var) = TAILQ_FIRST(head); \
00280 (var) != TAILQ_END(head); \
00281 (var) = TAILQ_NEXT(var, field))
00282 #endif
00283
00284 #ifndef TAILQ_FOREACH_SAFE
00285 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
00286 for ((var) = TAILQ_FIRST((head)); \
00287 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
00288 (var) = (tvar))
00289
00290 #endif
00291 #ifndef TAILQ_FOREACH_REVERSE
00292 #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
00293 for ((var) = TAILQ_LAST((head), headname); \
00294 (var); \
00295 (var) = TAILQ_PREV((var), headname, field))
00296
00297 #endif
00298
00299 #ifndef TAILQ_FOREACH_REVERSE_SAFE
00300 #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
00301 for ((var) = TAILQ_LAST((head), headname); \
00302 (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
00303 (var) = (tvar))
00304 #endif
00305
00306 #endif