1#ifndef _LINUX_LIST_H
2#define _LINUX_LIST_H
3
4#if defined(__KERNEL__) || defined(_LVM_H_INCLUDE)
5
6#include <linux/prefetch.h>
7
8
9
10
11
12
13
14
15
16
17
18struct list_head {
19 struct list_head *next, *prev;
20};
21
22#define LIST_HEAD_INIT(name) { &(name), &(name) }
23
24#define LIST_HEAD(name) \
25 struct list_head name = LIST_HEAD_INIT(name)
26
27#define INIT_LIST_HEAD(ptr) do { \
28 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
29} while (0)
30
31
32
33
34
35
36
37static inline void __list_add(struct list_head *new,
38 struct list_head *prev,
39 struct list_head *next)
40{
41 next->prev = new;
42 new->next = next;
43 new->prev = prev;
44 prev->next = new;
45}
46
47
48
49
50
51
52
53
54
55static inline void list_add(struct list_head *new, struct list_head *head)
56{
57 __list_add(new, head, head->next);
58}
59
60
61
62
63
64
65
66
67
68static inline void list_add_tail(struct list_head *new, struct list_head *head)
69{
70 __list_add(new, head->prev, head);
71}
72
73
74
75
76
77
78
79
80static inline void __list_del(struct list_head *prev, struct list_head *next)
81{
82 next->prev = prev;
83 prev->next = next;
84}
85
86
87
88
89
90
91static inline void list_del(struct list_head *entry)
92{
93 __list_del(entry->prev, entry->next);
94 entry->next = (void *) 0;
95 entry->prev = (void *) 0;
96}
97
98
99
100
101
102static inline void list_del_init(struct list_head *entry)
103{
104 __list_del(entry->prev, entry->next);
105 INIT_LIST_HEAD(entry);
106}
107
108
109
110
111
112
113static inline void list_move(struct list_head *list, struct list_head *head)
114{
115 __list_del(list->prev, list->next);
116 list_add(list, head);
117}
118
119
120
121
122
123
124static inline void list_move_tail(struct list_head *list,
125 struct list_head *head)
126{
127 __list_del(list->prev, list->next);
128 list_add_tail(list, head);
129}
130
131
132
133
134
135static inline int list_empty(struct list_head *head)
136{
137 return head->next == head;
138}
139
140static inline void __list_splice(struct list_head *list,
141 struct list_head *head)
142{
143 struct list_head *first = list->next;
144 struct list_head *last = list->prev;
145 struct list_head *at = head->next;
146
147 first->prev = head;
148 head->next = first;
149
150 last->next = at;
151 at->prev = last;
152}
153
154
155
156
157
158
159static inline void list_splice(struct list_head *list, struct list_head *head)
160{
161 if (!list_empty(list))
162 __list_splice(list, head);
163}
164
165
166
167
168
169
170
171
172static inline void list_splice_init(struct list_head *list,
173 struct list_head *head)
174{
175 if (!list_empty(list)) {
176 __list_splice(list, head);
177 INIT_LIST_HEAD(list);
178 }
179}
180
181
182
183
184
185
186
187#define list_entry(ptr, type, member) \
188 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
189
190
191
192
193
194
195#define list_for_each(pos, head) \
196 for (pos = (head)->next, prefetch(pos->next); pos != (head); \
197 pos = pos->next, prefetch(pos->next))
198
199
200
201
202
203#define list_for_each_prev(pos, head) \
204 for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
205 pos = pos->prev, prefetch(pos->prev))
206
207
208
209
210
211
212
213#define list_for_each_safe(pos, n, head) \
214 for (pos = (head)->next, n = pos->next; pos != (head); \
215 pos = n, n = pos->next)
216
217
218
219
220
221
222
223#define list_for_each_entry(pos, head, member) \
224 for (pos = list_entry((head)->next, typeof(*pos), member), \
225 prefetch(pos->member.next); \
226 &pos->member != (head); \
227 pos = list_entry(pos->member.next, typeof(*pos), member), \
228 prefetch(pos->member.next))
229
230
231
232
233
234
235
236
237#define list_for_each_entry_safe(pos, n, head, member) \
238 for (pos = list_entry((head)->next, typeof(*pos), member), \
239 n = list_entry(pos->member.next, typeof(*pos), member); \
240 &pos->member != (head); \
241 pos = n, n = list_entry(n->member.next, typeof(*n), member))
242
243
244
245
246
247
248
249
250#define list_for_each_entry_continue(pos, head, member) \
251 for (pos = list_entry(pos->member.next, typeof(*pos), member), \
252 prefetch(pos->member.next); \
253 &pos->member != (head); \
254 pos = list_entry(pos->member.next, typeof(*pos), member), \
255 prefetch(pos->member.next))
256
257#endif
258
259#endif
260