00001
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
00040
00041
00042
00043
00044 #ifndef _SYS_QUEUE_H_
00045 #define _SYS_QUEUE_H_
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 #define LIST_HEAD(name, type) \
00087 struct name { \
00088 struct type *lh_first; \
00089 }
00090
00091 #define LIST_HEAD_INITIALIZER(head) \
00092 { NULL }
00093
00094 #define LIST_ENTRY(type) \
00095 struct { \
00096 struct type *le_next; \
00097 struct type **le_prev; \
00098 }
00099
00100 #define LIST_ENTRY_INITIALIZER \
00101 { NULL, NULL }
00102
00103
00104
00105
00106 #define LIST_INIT(head) do { \
00107 (head)->lh_first = NULL; \
00108 } while (0)
00109
00110 #define LIST_ENTRY_INIT(elm, field) do { \
00111 (elm)->field.le_next = NULL; \
00112 (elm)->field.le_prev = NULL; \
00113 } while (0)
00114
00115 #define LIST_INSERT_AFTER(listelm, elm, field) do { \
00116 if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
00117 (listelm)->field.le_next->field.le_prev = \
00118 &(elm)->field.le_next; \
00119 (listelm)->field.le_next = (elm); \
00120 (elm)->field.le_prev = &(listelm)->field.le_next; \
00121 } while (0)
00122
00123 #define LIST_INSERT_BEFORE(listelm, elm, field) do { \
00124 (elm)->field.le_prev = (listelm)->field.le_prev; \
00125 (elm)->field.le_next = (listelm); \
00126 *(listelm)->field.le_prev = (elm); \
00127 (listelm)->field.le_prev = &(elm)->field.le_next; \
00128 } while (0)
00129
00130 #define LIST_INSERT_HEAD(head, elm, field) do { \
00131 if (((elm)->field.le_next = (head)->lh_first) != NULL) \
00132 (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
00133 (head)->lh_first = (elm); \
00134 (elm)->field.le_prev = &(head)->lh_first; \
00135 } while (0)
00136
00137 #define LIST_REMOVE(elm, field) do { \
00138 if ((elm)->field.le_next != NULL) \
00139 (elm)->field.le_next->field.le_prev = \
00140 (elm)->field.le_prev; \
00141 *(elm)->field.le_prev = (elm)->field.le_next; \
00142 } while (0)
00143
00144 #define LIST_FIRST(head) \
00145 ((head)->lh_first)
00146
00147 #define LIST_NEXT(elm, field) \
00148 ((elm)->field.le_next)
00149
00150
00151
00152
00153 #define SIMPLEQ_HEAD(name, type) \
00154 struct name { \
00155 struct type *sqh_first; \
00156 struct type **sqh_last; \
00157 }
00158
00159 #define SIMPLEQ_HEAD_INITIALIZER(head) \
00160 { NULL, &(head).sqh_first }
00161
00162 #define SIMPLEQ_ENTRY(type) \
00163 struct { \
00164 struct type *sqe_next; \
00165 }
00166
00167
00168
00169
00170 #define SIMPLEQ_INIT(head) do { \
00171 (head)->sqh_first = NULL; \
00172 (head)->sqh_last = &(head)->sqh_first; \
00173 } while (0)
00174
00175 #define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
00176 if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
00177 (head)->sqh_last = &(elm)->field.sqe_next; \
00178 (head)->sqh_first = (elm); \
00179 } while (0)
00180
00181 #define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
00182 (elm)->field.sqe_next = NULL; \
00183 *(head)->sqh_last = (elm); \
00184 (head)->sqh_last = &(elm)->field.sqe_next; \
00185 } while (0)
00186
00187 #define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
00188 if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
00189 (head)->sqh_last = &(elm)->field.sqe_next; \
00190 (listelm)->field.sqe_next = (elm); \
00191 } while (0)
00192
00193 #define SIMPLEQ_REMOVE_HEAD(head, elm, field) do { \
00194 if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) \
00195 (head)->sqh_last = &(head)->sqh_first; \
00196 } while (0)
00197
00198
00199
00200
00201 #define TAILQ_HEAD(name, type) \
00202 struct name { \
00203 struct type *tqh_first; \
00204 struct type **tqh_last; \
00205 }
00206
00207 #define TAILQ_HEAD_INITIALIZER(head) \
00208 { NULL, &(head).tqh_first }
00209
00210 #define TAILQ_ENTRY(type) \
00211 struct { \
00212 struct type *tqe_next; \
00213 struct type **tqe_prev; \
00214 }
00215
00216
00217
00218
00219 #define TAILQ_INIT(head) do { \
00220 (head)->tqh_first = NULL; \
00221 (head)->tqh_last = &(head)->tqh_first; \
00222 } while (0)
00223
00224 #define TAILQ_INSERT_HEAD(head, elm, field) do { \
00225 if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
00226 (head)->tqh_first->field.tqe_prev = \
00227 &(elm)->field.tqe_next; \
00228 else \
00229 (head)->tqh_last = &(elm)->field.tqe_next; \
00230 (head)->tqh_first = (elm); \
00231 (elm)->field.tqe_prev = &(head)->tqh_first; \
00232 } while (0)
00233
00234 #define TAILQ_INSERT_TAIL(head, elm, field) do { \
00235 (elm)->field.tqe_next = NULL; \
00236 (elm)->field.tqe_prev = (head)->tqh_last; \
00237 *(head)->tqh_last = (elm); \
00238 (head)->tqh_last = &(elm)->field.tqe_next; \
00239 } while (0)
00240
00241 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
00242 if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
00243 (elm)->field.tqe_next->field.tqe_prev = \
00244 &(elm)->field.tqe_next; \
00245 else \
00246 (head)->tqh_last = &(elm)->field.tqe_next; \
00247 (listelm)->field.tqe_next = (elm); \
00248 (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
00249 } while (0)
00250
00251 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
00252 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
00253 (elm)->field.tqe_next = (listelm); \
00254 *(listelm)->field.tqe_prev = (elm); \
00255 (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
00256 } while (0)
00257
00258 #define TAILQ_REMOVE(head, elm, field) do { \
00259 if (((elm)->field.tqe_next) != NULL) \
00260 (elm)->field.tqe_next->field.tqe_prev = \
00261 (elm)->field.tqe_prev; \
00262 else \
00263 (head)->tqh_last = (elm)->field.tqe_prev; \
00264 *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
00265 } while (0)
00266
00267
00268
00269
00270 #define CIRCLEQ_HEAD(name, type) \
00271 struct name { \
00272 struct type *cqh_first; \
00273 struct type *cqh_last; \
00274 }
00275
00276 #define CIRCLEQ_HEAD_INITIALIZER(head) \
00277 { (void *)&head, (void *)&head }
00278
00279 #define CIRCLEQ_ENTRY(type) \
00280 struct { \
00281 struct type *cqe_next; \
00282 struct type *cqe_prev; \
00283 }
00284
00285
00286
00287
00288 #define CIRCLEQ_INIT(head) do { \
00289 (head)->cqh_first = (void *)(head); \
00290 (head)->cqh_last = (void *)(head); \
00291 } while (0)
00292
00293 #define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
00294 (elm)->field.cqe_next = (listelm)->field.cqe_next; \
00295 (elm)->field.cqe_prev = (listelm); \
00296 if ((listelm)->field.cqe_next == (void *)(head)) \
00297 (head)->cqh_last = (elm); \
00298 else \
00299 (listelm)->field.cqe_next->field.cqe_prev = (elm); \
00300 (listelm)->field.cqe_next = (elm); \
00301 } while (0)
00302
00303 #define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
00304 (elm)->field.cqe_next = (listelm); \
00305 (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
00306 if ((listelm)->field.cqe_prev == (void *)(head)) \
00307 (head)->cqh_first = (elm); \
00308 else \
00309 (listelm)->field.cqe_prev->field.cqe_next = (elm); \
00310 (listelm)->field.cqe_prev = (elm); \
00311 } while (0)
00312
00313 #define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
00314 (elm)->field.cqe_next = (head)->cqh_first; \
00315 (elm)->field.cqe_prev = (void *)(head); \
00316 if ((head)->cqh_last == (void *)(head)) \
00317 (head)->cqh_last = (elm); \
00318 else \
00319 (head)->cqh_first->field.cqe_prev = (elm); \
00320 (head)->cqh_first = (elm); \
00321 } while (0)
00322
00323 #define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
00324 (elm)->field.cqe_next = (void *)(head); \
00325 (elm)->field.cqe_prev = (head)->cqh_last; \
00326 if ((head)->cqh_first == (void *)(head)) \
00327 (head)->cqh_first = (elm); \
00328 else \
00329 (head)->cqh_last->field.cqe_next = (elm); \
00330 (head)->cqh_last = (elm); \
00331 } while (0)
00332
00333 #define CIRCLEQ_REMOVE(head, elm, field) do { \
00334 if ((elm)->field.cqe_next == (void *)(head)) \
00335 (head)->cqh_last = (elm)->field.cqe_prev; \
00336 else \
00337 (elm)->field.cqe_next->field.cqe_prev = \
00338 (elm)->field.cqe_prev; \
00339 if ((elm)->field.cqe_prev == (void *)(head)) \
00340 (head)->cqh_first = (elm)->field.cqe_next; \
00341 else \
00342 (elm)->field.cqe_prev->field.cqe_next = \
00343 (elm)->field.cqe_next; \
00344 } while (0)
00345 #endif