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