00001 #ifndef _LINUX_LIST_H
00002 #define _LINUX_LIST_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 struct list_head {
00016 struct list_head *next, *prev;
00017 };
00018
00019 #define LIST_HEAD_INIT(name) { &(name), &(name) }
00020
00021 #define LIST_HEAD(name) \
00022 struct list_head name = LIST_HEAD_INIT(name)
00023
00024 #define INIT_LIST_HEAD(ptr) do { \
00025 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
00026 } while (0)
00027
00028
00029
00030
00031
00032
00033
00034 static inline void __list_add(struct list_head *new,
00035 struct list_head *prev,
00036 struct list_head *next)
00037 {
00038 next->prev = new;
00039 new->next = next;
00040 new->prev = prev;
00041 prev->next = new;
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 static inline void list_add(struct list_head *new, struct list_head *head)
00053 {
00054 __list_add(new, head, head->next);
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 static inline void list_add_tail(struct list_head *new, struct list_head *head)
00066 {
00067 __list_add(new, head->prev, head);
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077 static inline void __list_del(struct list_head *prev, struct list_head *next)
00078 {
00079 next->prev = prev;
00080 prev->next = next;
00081 }
00082
00083
00084
00085
00086
00087
00088 static inline void list_del(struct list_head *entry)
00089 {
00090 __list_del(entry->prev, entry->next);
00091 entry->next = (void *) 0;
00092 entry->prev = (void *) 0;
00093 }
00094
00095
00096
00097
00098
00099 static inline void list_del_init(struct list_head *entry)
00100 {
00101 __list_del(entry->prev, entry->next);
00102 INIT_LIST_HEAD(entry);
00103 }
00104
00105
00106
00107
00108
00109
00110 static inline void list_move(struct list_head *list, struct list_head *head)
00111 {
00112 __list_del(list->prev, list->next);
00113 list_add(list, head);
00114 }
00115
00116
00117
00118
00119
00120
00121 static inline void list_move_tail(struct list_head *list,
00122 struct list_head *head)
00123 {
00124 __list_del(list->prev, list->next);
00125 list_add_tail(list, head);
00126 }
00127
00128
00129
00130
00131
00132 static inline int list_empty(struct list_head *head)
00133 {
00134 return head->next == head;
00135 }
00136
00137 static inline void __list_splice(struct list_head *list,
00138 struct list_head *head)
00139 {
00140 struct list_head *first = list->next;
00141 struct list_head *last = list->prev;
00142 struct list_head *at = head->next;
00143
00144 first->prev = head;
00145 head->next = first;
00146
00147 last->next = at;
00148 at->prev = last;
00149 }
00150
00151
00152
00153
00154
00155
00156 static inline void list_splice(struct list_head *list, struct list_head *head)
00157 {
00158 if (!list_empty(list))
00159 __list_splice(list, head);
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169 static inline void list_splice_init(struct list_head *list,
00170 struct list_head *head)
00171 {
00172 if (!list_empty(list)) {
00173 __list_splice(list, head);
00174 INIT_LIST_HEAD(list);
00175 }
00176 }
00177
00178
00179
00180
00181
00182
00183
00184 #define list_entry(ptr, type, member) \
00185 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
00186
00187
00188
00189
00190
00191
00192 #define list_for_each(pos, head) \
00193 for (pos = (head)->next, prefetch(pos->next); pos != (head); \
00194 pos = pos->next, prefetch(pos->next))
00195
00196
00197
00198
00199
00200 #define list_for_each_prev(pos, head) \
00201 for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
00202 pos = pos->prev, prefetch(pos->prev))
00203
00204
00205
00206
00207
00208
00209
00210 #define list_for_each_safe(pos, n, head) \
00211 for (pos = (head)->next, n = pos->next; pos != (head); \
00212 pos = n, n = pos->next)
00213
00214
00215
00216
00217
00218
00219
00220 #define list_for_each_entry(pos, head, member) \
00221 for (pos = list_entry((head)->next, typeof(*pos), member), \
00222 prefetch(pos->member.next); \
00223 &pos->member != (head); \
00224 pos = list_entry(pos->member.next, typeof(*pos), member), \
00225 prefetch(pos->member.next))
00226
00227
00228
00229
00230
00231
00232
00233
00234 #define list_for_each_entry_safe(pos, n, head, member) \
00235 for (pos = list_entry((head)->next, typeof(*pos), member), \
00236 n = list_entry(pos->member.next, typeof(*pos), member); \
00237 &pos->member != (head); \
00238 pos = n, n = list_entry(n->member.next, typeof(*n), member))
00239
00240
00241
00242
00243
00244
00245
00246
00247 #define list_for_each_entry_continue(pos, head, member) \
00248 for (pos = list_entry(pos->member.next, typeof(*pos), member), \
00249 prefetch(pos->member.next); \
00250 &pos->member != (head); \
00251 pos = list_entry(pos->member.next, typeof(*pos), member), \
00252 prefetch(pos->member.next))
00253
00254 #endif