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 _LUCID_LIST_H
00038 #define _LUCID_LIST_H
00039
00040 #include <stddef.h>
00041
00042
00043 #define container_of(ptr, type, member) \
00044 ((type *)((char *)(ptr) - offsetof(type, member)))
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 struct list_head {
00058 struct list_head *next, *prev;
00059 };
00060
00061
00062 #define LIST_HEAD_INIT(name) { &(name), &(name) }
00063
00064
00065 #define LIST_HEAD(name) \
00066 struct list_head name = LIST_HEAD_INIT(name)
00067
00068 static inline void INIT_LIST_HEAD(struct list_head *list)
00069 {
00070 list->next = list;
00071 list->prev = list;
00072 }
00073
00074
00075
00076
00077
00078
00079
00080 static inline
00081 void __list_add(struct list_head *new,
00082 struct list_head *prev,
00083 struct list_head *next)
00084 {
00085 next->prev = new;
00086 new->next = next;
00087 new->prev = prev;
00088 prev->next = new;
00089 }
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 static inline
00101 void list_add(struct list_head *new, struct list_head *head)
00102 {
00103 __list_add(new, head, head->next);
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 static inline
00116 void list_add_tail(struct list_head *new, struct list_head *head)
00117 {
00118 __list_add(new, head->prev, head);
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128 static inline
00129 void __list_del(struct list_head * prev, struct list_head * next)
00130 {
00131 next->prev = prev;
00132 prev->next = next;
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 static inline
00144 void list_del(struct list_head *entry)
00145 {
00146 __list_del(entry->prev, entry->next);
00147 entry->next = (void *) 0;
00148 entry->prev = (void *) 0;
00149 }
00150
00151
00152
00153
00154
00155
00156 static inline
00157 void list_del_init(struct list_head *entry)
00158 {
00159 __list_del(entry->prev, entry->next);
00160 INIT_LIST_HEAD(entry);
00161 }
00162
00163
00164
00165
00166
00167
00168
00169 static inline
00170 void list_move(struct list_head *list, struct list_head *head)
00171 {
00172 __list_del(list->prev, list->next);
00173 list_add(list, head);
00174 }
00175
00176
00177
00178
00179
00180
00181
00182 static inline
00183 void list_move_tail(struct list_head *list, struct list_head *head)
00184 {
00185 __list_del(list->prev, list->next);
00186 list_add_tail(list, head);
00187 }
00188
00189
00190
00191
00192
00193
00194 static inline
00195 int list_empty(const struct list_head *head)
00196 {
00197 return head->next == head;
00198 }
00199
00200 static inline
00201 void __list_splice(struct list_head *list, struct list_head *head)
00202 {
00203 struct list_head *first = list->next;
00204 struct list_head *last = list->prev;
00205 struct list_head *at = head->next;
00206
00207 first->prev = head;
00208 head->next = first;
00209
00210 last->next = at;
00211 at->prev = last;
00212 }
00213
00214
00215
00216
00217
00218
00219
00220 static inline
00221 void list_splice(struct list_head *list, struct list_head *head)
00222 {
00223 if (!list_empty(list))
00224 __list_splice(list, head);
00225 }
00226
00227
00228
00229
00230
00231
00232
00233 static inline
00234 void list_splice_init(struct list_head *list, struct list_head *head)
00235 {
00236 if (!list_empty(list)) {
00237 __list_splice(list, head);
00238 INIT_LIST_HEAD(list);
00239 }
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249 #define list_entry(ptr, type, member) \
00250 container_of(ptr, type, member)
00251
00252
00253
00254
00255
00256
00257
00258 #define list_for_each(pos, head) \
00259 for (pos = (head)->next; pos != (head); pos = pos->next)
00260
00261
00262
00263
00264
00265
00266
00267 #define list_for_each_prev(pos, head) \
00268 for (pos = (head)->prev; pos != (head); pos = pos->prev)
00269
00270
00271
00272
00273
00274
00275
00276
00277 #define list_for_each_safe(pos, n, head) \
00278 for (pos = (head)->next, n = pos->next; pos != (head); \
00279 pos = n, n = pos->next)
00280
00281
00282
00283
00284
00285
00286
00287
00288 #define list_for_each_entry(pos, head, member) \
00289 for (pos = list_entry((head)->next, typeof(*pos), member); \
00290 &pos->member != (head); \
00291 pos = list_entry(pos->member.next, typeof(*pos), member))
00292
00293
00294
00295
00296
00297
00298
00299
00300 #define list_for_each_entry_reverse(pos, head, member) \
00301 for (pos = list_entry((head)->prev, typeof(*pos), member); \
00302 &pos->member != (head); \
00303 pos = list_entry(pos->member.prev, typeof(*pos), member))
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 #define list_for_each_entry_safe(pos, n, head, member) \
00314 for (pos = list_entry((head)->next, typeof(*pos), member), \
00315 n = list_entry(pos->member.next, typeof(*pos), member); \
00316 &pos->member != (head); \
00317 pos = n, n = list_entry(n->member.next, typeof(*n), member))
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327 #define list_for_each_entry_safe_reverse(pos, n, head, member) \
00328 for (pos = list_entry((head)->prev, typeof(*pos), member), \
00329 n = list_entry(pos->member.prev, typeof(*pos), member); \
00330 &pos->member != (head); \
00331 pos = n, n = list_entry(n->member.prev, typeof(*n), member))
00332
00333 #endif
00334
00335