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