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