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