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
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 #define SLIST_HEAD(name, type) \
00093 struct name { \
00094 struct type *slh_first; \
00095 }
00096
00097 #define SLIST_HEAD_INITIALIZER(head) \
00098 { NULL }
00099
00100 #define SLIST_ENTRY(type) \
00101 struct { \
00102 struct type *sle_next; \
00103 }
00104
00105
00106
00107
00108 #define SLIST_FIRST(head) ((head)->slh_first)
00109 #define SLIST_END(head) NULL
00110 #define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
00111 #define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
00112
00113 #define SLIST_FOREACH(var, head, field) \
00114 for((var) = SLIST_FIRST(head); \
00115 (var) != SLIST_END(head); \
00116 (var) = SLIST_NEXT(var, field))
00117
00118
00119
00120
00121 #define SLIST_INIT(head) { \
00122 SLIST_FIRST(head) = SLIST_END(head); \
00123 }
00124
00125 #define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
00126 (elm)->field.sle_next = (slistelm)->field.sle_next; \
00127 (slistelm)->field.sle_next = (elm); \
00128 } while (0)
00129
00130 #define SLIST_INSERT_HEAD(head, elm, field) do { \
00131 (elm)->field.sle_next = (head)->slh_first; \
00132 (head)->slh_first = (elm); \
00133 } while (0)
00134
00135 #define SLIST_REMOVE_HEAD(head, field) do { \
00136 (head)->slh_first = (head)->slh_first->field.sle_next; \
00137 } while (0)
00138
00139 #define SLIST_REMOVE(head, elm, type, field) do { \
00140 if ((head)->slh_first == (elm)) { \
00141 SLIST_REMOVE_HEAD((head), field); \
00142 } \
00143 else { \
00144 struct type *curelm = (head)->slh_first; \
00145 while( curelm->field.sle_next != (elm) ) \
00146 curelm = curelm->field.sle_next; \
00147 curelm->field.sle_next = \
00148 curelm->field.sle_next->field.sle_next; \
00149 } \
00150 } while (0)
00151
00152
00153
00154
00155 #define LIST_HEAD(name, type) \
00156 struct name { \
00157 struct type *lh_first; \
00158 }
00159
00160 #define LIST_HEAD_INITIALIZER(head) \
00161 { NULL }
00162
00163 #define LIST_ENTRY(type) \
00164 struct { \
00165 struct type *le_next; \
00166 struct type **le_prev; \
00167 }
00168
00169
00170
00171
00172 #define LIST_FIRST(head) ((head)->lh_first)
00173 #define LIST_END(head) NULL
00174 #define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head))
00175 #define LIST_NEXT(elm, field) ((elm)->field.le_next)
00176
00177 #define LIST_FOREACH(var, head, field) \
00178 for((var) = LIST_FIRST(head); \
00179 (var)!= LIST_END(head); \
00180 (var) = LIST_NEXT(var, field))
00181
00182
00183
00184
00185 #define LIST_INIT(head) do { \
00186 LIST_FIRST(head) = LIST_END(head); \
00187 } while (0)
00188
00189 #define LIST_INSERT_AFTER(listelm, elm, field) do { \
00190 if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
00191 (listelm)->field.le_next->field.le_prev = \
00192 &(elm)->field.le_next; \
00193 (listelm)->field.le_next = (elm); \
00194 (elm)->field.le_prev = &(listelm)->field.le_next; \
00195 } while (0)
00196
00197 #define LIST_INSERT_BEFORE(listelm, elm, field) do { \
00198 (elm)->field.le_prev = (listelm)->field.le_prev; \
00199 (elm)->field.le_next = (listelm); \
00200 *(listelm)->field.le_prev = (elm); \
00201 (listelm)->field.le_prev = &(elm)->field.le_next; \
00202 } while (0)
00203
00204 #define LIST_INSERT_HEAD(head, elm, field) do { \
00205 if (((elm)->field.le_next = (head)->lh_first) != NULL) \
00206 (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
00207 (head)->lh_first = (elm); \
00208 (elm)->field.le_prev = &(head)->lh_first; \
00209 } while (0)
00210
00211 #define LIST_REMOVE(elm, field) do { \
00212 if ((elm)->field.le_next != NULL) \
00213 (elm)->field.le_next->field.le_prev = \
00214 (elm)->field.le_prev; \
00215 *(elm)->field.le_prev = (elm)->field.le_next; \
00216 } while (0)
00217
00218 #define LIST_REPLACE(elm, elm2, field) do { \
00219 if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
00220 (elm2)->field.le_next->field.le_prev = \
00221 &(elm2)->field.le_next; \
00222 (elm2)->field.le_prev = (elm)->field.le_prev; \
00223 *(elm2)->field.le_prev = (elm2); \
00224 } while (0)
00225
00226
00227
00228
00229 #define SIMPLEQ_HEAD(name, type) \
00230 struct name { \
00231 struct type *sqh_first; \
00232 struct type **sqh_last; \
00233 }
00234
00235 #define SIMPLEQ_HEAD_INITIALIZER(head) \
00236 { NULL, &(head).sqh_first }
00237
00238 #define SIMPLEQ_ENTRY(type) \
00239 struct { \
00240 struct type *sqe_next; \
00241 }
00242
00243
00244
00245
00246 #define SIMPLEQ_FIRST(head) ((head)->sqh_first)
00247 #define SIMPLEQ_END(head) NULL
00248 #define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
00249 #define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
00250
00251 #define SIMPLEQ_FOREACH(var, head, field) \
00252 for((var) = SIMPLEQ_FIRST(head); \
00253 (var) != SIMPLEQ_END(head); \
00254 (var) = SIMPLEQ_NEXT(var, field))
00255
00256
00257
00258
00259 #define SIMPLEQ_INIT(head) do { \
00260 (head)->sqh_first = NULL; \
00261 (head)->sqh_last = &(head)->sqh_first; \
00262 } while (0)
00263
00264 #define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
00265 if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
00266 (head)->sqh_last = &(elm)->field.sqe_next; \
00267 (head)->sqh_first = (elm); \
00268 } while (0)
00269
00270 #define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
00271 (elm)->field.sqe_next = NULL; \
00272 *(head)->sqh_last = (elm); \
00273 (head)->sqh_last = &(elm)->field.sqe_next; \
00274 } while (0)
00275
00276 #define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
00277 if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
00278 (head)->sqh_last = &(elm)->field.sqe_next; \
00279 (listelm)->field.sqe_next = (elm); \
00280 } while (0)
00281
00282 #define SIMPLEQ_REMOVE_HEAD(head, elm, field) do { \
00283 if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) \
00284 (head)->sqh_last = &(head)->sqh_first; \
00285 } while (0)
00286
00287
00288
00289
00290 #define TAILQ_HEAD(name, type) \
00291 struct name { \
00292 struct type *tqh_first; \
00293 struct type **tqh_last; \
00294 }
00295
00296 #define TAILQ_HEAD_INITIALIZER(head) \
00297 { NULL, &(head).tqh_first }
00298
00299 #define TAILQ_ENTRY(type) \
00300 struct { \
00301 struct type *tqe_next; \
00302 struct type **tqe_prev; \
00303 }
00304
00305
00306
00307
00308 #define TAILQ_FIRST(head) ((head)->tqh_first)
00309 #define TAILQ_END(head) NULL
00310 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
00311 #define TAILQ_LAST(head, headname) \
00312 (*(((struct headname *)((head)->tqh_last))->tqh_last))
00313
00314 #define TAILQ_PREV(elm, headname, field) \
00315 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
00316 #define TAILQ_EMPTY(head) \
00317 (TAILQ_FIRST(head) == TAILQ_END(head))
00318
00319 #define TAILQ_FOREACH(var, head, field) \
00320 for((var) = TAILQ_FIRST(head); \
00321 (var) != TAILQ_END(head); \
00322 (var) = TAILQ_NEXT(var, field))
00323
00324 #define TAILQ_FOREACH_REVERSE(var, head, field, headname) \
00325 for((var) = TAILQ_LAST(head, headname); \
00326 (var) != TAILQ_END(head); \
00327 (var) = TAILQ_PREV(var, headname, field))
00328
00329
00330
00331
00332 #define TAILQ_INIT(head) do { \
00333 (head)->tqh_first = NULL; \
00334 (head)->tqh_last = &(head)->tqh_first; \
00335 } while (0)
00336
00337 #define TAILQ_INSERT_HEAD(head, elm, field) do { \
00338 if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
00339 (head)->tqh_first->field.tqe_prev = \
00340 &(elm)->field.tqe_next; \
00341 else \
00342 (head)->tqh_last = &(elm)->field.tqe_next; \
00343 (head)->tqh_first = (elm); \
00344 (elm)->field.tqe_prev = &(head)->tqh_first; \
00345 } while (0)
00346
00347 #define TAILQ_INSERT_TAIL(head, elm, field) do { \
00348 (elm)->field.tqe_next = NULL; \
00349 (elm)->field.tqe_prev = (head)->tqh_last; \
00350 *(head)->tqh_last = (elm); \
00351 (head)->tqh_last = &(elm)->field.tqe_next; \
00352 } while (0)
00353
00354 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
00355 if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
00356 (elm)->field.tqe_next->field.tqe_prev = \
00357 &(elm)->field.tqe_next; \
00358 else \
00359 (head)->tqh_last = &(elm)->field.tqe_next; \
00360 (listelm)->field.tqe_next = (elm); \
00361 (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
00362 } while (0)
00363
00364 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
00365 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
00366 (elm)->field.tqe_next = (listelm); \
00367 *(listelm)->field.tqe_prev = (elm); \
00368 (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
00369 } while (0)
00370
00371 #define TAILQ_REMOVE(head, elm, field) do { \
00372 if (((elm)->field.tqe_next) != NULL) \
00373 (elm)->field.tqe_next->field.tqe_prev = \
00374 (elm)->field.tqe_prev; \
00375 else \
00376 (head)->tqh_last = (elm)->field.tqe_prev; \
00377 *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
00378 } while (0)
00379
00380 #define TAILQ_REPLACE(head, elm, elm2, field) do { \
00381 if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
00382 (elm2)->field.tqe_next->field.tqe_prev = \
00383 &(elm2)->field.tqe_next; \
00384 else \
00385 (head)->tqh_last = &(elm2)->field.tqe_next; \
00386 (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
00387 *(elm2)->field.tqe_prev = (elm2); \
00388 } while (0)
00389
00390
00391
00392
00393 #define CIRCLEQ_HEAD(name, type) \
00394 struct name { \
00395 struct type *cqh_first; \
00396 struct type *cqh_last; \
00397 }
00398
00399 #define CIRCLEQ_HEAD_INITIALIZER(head) \
00400 { CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
00401
00402 #define CIRCLEQ_ENTRY(type) \
00403 struct { \
00404 struct type *cqe_next; \
00405 struct type *cqe_prev; \
00406 }
00407
00408
00409
00410
00411 #define CIRCLEQ_FIRST(head) ((head)->cqh_first)
00412 #define CIRCLEQ_LAST(head) ((head)->cqh_last)
00413 #define CIRCLEQ_END(head) ((void *)(head))
00414 #define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
00415 #define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
00416 #define CIRCLEQ_EMPTY(head) \
00417 (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))
00418
00419 #define CIRCLEQ_FOREACH(var, head, field) \
00420 for((var) = CIRCLEQ_FIRST(head); \
00421 (var) != CIRCLEQ_END(head); \
00422 (var) = CIRCLEQ_NEXT(var, field))
00423
00424 #define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
00425 for((var) = CIRCLEQ_LAST(head); \
00426 (var) != CIRCLEQ_END(head); \
00427 (var) = CIRCLEQ_PREV(var, field))
00428
00429
00430
00431
00432 #define CIRCLEQ_INIT(head) do { \
00433 (head)->cqh_first = CIRCLEQ_END(head); \
00434 (head)->cqh_last = CIRCLEQ_END(head); \
00435 } while (0)
00436
00437 #define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
00438 (elm)->field.cqe_next = (listelm)->field.cqe_next; \
00439 (elm)->field.cqe_prev = (listelm); \
00440 if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \
00441 (head)->cqh_last = (elm); \
00442 else \
00443 (listelm)->field.cqe_next->field.cqe_prev = (elm); \
00444 (listelm)->field.cqe_next = (elm); \
00445 } while (0)
00446
00447 #define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
00448 (elm)->field.cqe_next = (listelm); \
00449 (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
00450 if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \
00451 (head)->cqh_first = (elm); \
00452 else \
00453 (listelm)->field.cqe_prev->field.cqe_next = (elm); \
00454 (listelm)->field.cqe_prev = (elm); \
00455 } while (0)
00456
00457 #define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
00458 (elm)->field.cqe_next = (head)->cqh_first; \
00459 (elm)->field.cqe_prev = CIRCLEQ_END(head); \
00460 if ((head)->cqh_last == CIRCLEQ_END(head)) \
00461 (head)->cqh_last = (elm); \
00462 else \
00463 (head)->cqh_first->field.cqe_prev = (elm); \
00464 (head)->cqh_first = (elm); \
00465 } while (0)
00466
00467 #define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
00468 (elm)->field.cqe_next = CIRCLEQ_END(head); \
00469 (elm)->field.cqe_prev = (head)->cqh_last; \
00470 if ((head)->cqh_first == CIRCLEQ_END(head)) \
00471 (head)->cqh_first = (elm); \
00472 else \
00473 (head)->cqh_last->field.cqe_next = (elm); \
00474 (head)->cqh_last = (elm); \
00475 } while (0)
00476
00477 #define CIRCLEQ_REMOVE(head, elm, field) do { \
00478 if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \
00479 (head)->cqh_last = (elm)->field.cqe_prev; \
00480 else \
00481 (elm)->field.cqe_next->field.cqe_prev = \
00482 (elm)->field.cqe_prev; \
00483 if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \
00484 (head)->cqh_first = (elm)->field.cqe_next; \
00485 else \
00486 (elm)->field.cqe_prev->field.cqe_next = \
00487 (elm)->field.cqe_next; \
00488 } while (0)
00489
00490 #define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
00491 if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
00492 CIRCLEQ_END(head)) \
00493 (head).cqh_last = (elm2); \
00494 else \
00495 (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
00496 if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
00497 CIRCLEQ_END(head)) \
00498 (head).cqh_first = (elm2); \
00499 else \
00500 (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
00501 } while (0)
00502
00503 #endif