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 #ifndef _SYS_QUEUE_H_
00033 #define _SYS_QUEUE_H_
00034
00035
00036
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 #if defined(__cplusplus)
00065 extern "C" {
00066 #endif
00067
00068
00069
00070
00071 #define LIST_HEAD(name, type) \
00072 struct name { \
00073 struct type *lh_first; \
00074 }
00075
00076 #define LIST_ENTRY(type) \
00077 struct { \
00078 struct type *le_next; \
00079 struct type **le_prev; \
00080 }
00081
00082 #define LIST_FIRST(head) ((head)->lh_first)
00083 #define LIST_NEXT(elm, field) ((elm)->field.le_next)
00084 #define LIST_END(head) NULL
00085
00086
00087
00088
00089 #define LIST_INIT(head) { \
00090 (head)->lh_first = NULL; \
00091 }
00092
00093 #define LIST_INSERT_AFTER(listelm, elm, field) do { \
00094 if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
00095 (listelm)->field.le_next->field.le_prev = \
00096 &(elm)->field.le_next; \
00097 (listelm)->field.le_next = (elm); \
00098 (elm)->field.le_prev = &(listelm)->field.le_next; \
00099 } while (0)
00100
00101 #define LIST_INSERT_BEFORE(listelm, elm, field) do { \
00102 (elm)->field.le_prev = (listelm)->field.le_prev; \
00103 (elm)->field.le_next = (listelm); \
00104 *(listelm)->field.le_prev = (elm); \
00105 (listelm)->field.le_prev = &(elm)->field.le_next; \
00106 } while (0)
00107
00108 #define LIST_INSERT_HEAD(head, elm, field) do { \
00109 if (((elm)->field.le_next = (head)->lh_first) != NULL) \
00110 (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
00111 (head)->lh_first = (elm); \
00112 (elm)->field.le_prev = &(head)->lh_first; \
00113 } while (0)
00114
00115 #define LIST_REMOVE(elm, field) do { \
00116 if ((elm)->field.le_next != NULL) \
00117 (elm)->field.le_next->field.le_prev = \
00118 (elm)->field.le_prev; \
00119 *(elm)->field.le_prev = (elm)->field.le_next; \
00120 } while (0)
00121
00122
00123
00124
00125 #define TAILQ_HEAD(name, type) \
00126 struct name { \
00127 struct type *tqh_first; \
00128 struct type **tqh_last; \
00129 }
00130
00131 #define TAILQ_ENTRY(type) \
00132 struct { \
00133 struct type *tqe_next; \
00134 struct type **tqe_prev; \
00135 }
00136
00137 #define TAILQ_FIRST(head) ((head)->tqh_first)
00138 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
00139 #define TAILQ_END(head) NULL
00140
00141
00142
00143
00144 #define TAILQ_INIT(head) do { \
00145 (head)->tqh_first = NULL; \
00146 (head)->tqh_last = &(head)->tqh_first; \
00147 } while (0)
00148
00149 #define TAILQ_INSERT_HEAD(head, elm, field) do { \
00150 if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
00151 (head)->tqh_first->field.tqe_prev = \
00152 &(elm)->field.tqe_next; \
00153 else \
00154 (head)->tqh_last = &(elm)->field.tqe_next; \
00155 (head)->tqh_first = (elm); \
00156 (elm)->field.tqe_prev = &(head)->tqh_first; \
00157 } while (0)
00158
00159 #define TAILQ_INSERT_TAIL(head, elm, field) do { \
00160 (elm)->field.tqe_next = NULL; \
00161 (elm)->field.tqe_prev = (head)->tqh_last; \
00162 *(head)->tqh_last = (elm); \
00163 (head)->tqh_last = &(elm)->field.tqe_next; \
00164 } while (0)
00165
00166 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
00167 if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
00168 (elm)->field.tqe_next->field.tqe_prev = \
00169 &(elm)->field.tqe_next; \
00170 else \
00171 (head)->tqh_last = &(elm)->field.tqe_next; \
00172 (listelm)->field.tqe_next = (elm); \
00173 (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
00174 } while (0)
00175
00176 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
00177 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
00178 (elm)->field.tqe_next = (listelm); \
00179 *(listelm)->field.tqe_prev = (elm); \
00180 (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
00181 } while (0)
00182
00183 #define TAILQ_REMOVE(head, elm, field) do { \
00184 if (((elm)->field.tqe_next) != NULL) \
00185 (elm)->field.tqe_next->field.tqe_prev = \
00186 (elm)->field.tqe_prev; \
00187 else \
00188 (head)->tqh_last = (elm)->field.tqe_prev; \
00189 *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
00190 } while (0)
00191
00192
00193
00194
00195 #define CIRCLEQ_HEAD(name, type) \
00196 struct name { \
00197 struct type *cqh_first; \
00198 struct type *cqh_last; \
00199 }
00200
00201 #define CIRCLEQ_ENTRY(type) \
00202 struct { \
00203 struct type *cqe_next; \
00204 struct type *cqe_prev; \
00205 }
00206
00207 #define CIRCLEQ_FIRST(head) ((head)->cqh_first)
00208 #define CIRCLEQ_LAST(head) ((head)->cqh_last)
00209 #define CIRCLEQ_END(head) ((void *)(head))
00210 #define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
00211 #define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
00212
00213
00214
00215
00216 #define CIRCLEQ_INIT(head) do { \
00217 (head)->cqh_first = (void *)(head); \
00218 (head)->cqh_last = (void *)(head); \
00219 } while (0)
00220
00221 #define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
00222 (elm)->field.cqe_next = (listelm)->field.cqe_next; \
00223 (elm)->field.cqe_prev = (listelm); \
00224 if ((listelm)->field.cqe_next == (void *)(head)) \
00225 (head)->cqh_last = (elm); \
00226 else \
00227 (listelm)->field.cqe_next->field.cqe_prev = (elm); \
00228 (listelm)->field.cqe_next = (elm); \
00229 } while (0)
00230
00231 #define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
00232 (elm)->field.cqe_next = (listelm); \
00233 (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
00234 if ((listelm)->field.cqe_prev == (void *)(head)) \
00235 (head)->cqh_first = (elm); \
00236 else \
00237 (listelm)->field.cqe_prev->field.cqe_next = (elm); \
00238 (listelm)->field.cqe_prev = (elm); \
00239 } while (0)
00240
00241 #define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
00242 (elm)->field.cqe_next = (head)->cqh_first; \
00243 (elm)->field.cqe_prev = (void *)(head); \
00244 if ((head)->cqh_last == (void *)(head)) \
00245 (head)->cqh_last = (elm); \
00246 else \
00247 (head)->cqh_first->field.cqe_prev = (elm); \
00248 (head)->cqh_first = (elm); \
00249 } while (0)
00250
00251 #define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
00252 (elm)->field.cqe_next = (void *)(head); \
00253 (elm)->field.cqe_prev = (head)->cqh_last; \
00254 if ((head)->cqh_first == (void *)(head)) \
00255 (head)->cqh_first = (elm); \
00256 else \
00257 (head)->cqh_last->field.cqe_next = (elm); \
00258 (head)->cqh_last = (elm); \
00259 } while (0)
00260
00261 #define CIRCLEQ_REMOVE(head, elm, field) do { \
00262 if ((elm)->field.cqe_next == (void *)(head)) \
00263 (head)->cqh_last = (elm)->field.cqe_prev; \
00264 else \
00265 (elm)->field.cqe_next->field.cqe_prev = \
00266 (elm)->field.cqe_prev; \
00267 if ((elm)->field.cqe_prev == (void *)(head)) \
00268 (head)->cqh_first = (elm)->field.cqe_next; \
00269 else \
00270 (elm)->field.cqe_prev->field.cqe_next = \
00271 (elm)->field.cqe_next; \
00272 } while (0)
00273
00274 #if defined(__cplusplus)
00275 }
00276 #endif
00277
00278 #endif