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