Rev 1964 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1408 | serge | 1 | #ifndef _LINUX_LIST_H |
2 | #define _LINUX_LIST_H |
||
3 | |||
4 | #include |
||
5 | //#include |
||
6 | //#include |
||
7 | //#include |
||
8 | |||
9 | /* |
||
10 | * Simple doubly linked list implementation. |
||
11 | * |
||
12 | * Some of the internal functions ("__xxx") are useful when |
||
13 | * manipulating whole lists rather than single entries, as |
||
14 | * sometimes we already know the next/prev entries and we can |
||
15 | * generate better code by using them directly rather than |
||
16 | * using the generic single-entry routines. |
||
17 | */ |
||
18 | |||
19 | #define LIST_POISON1 ((struct list_head*)0xFFFF0100) |
||
20 | #define LIST_POISON2 ((struct list_head*)0xFFFF0200) |
||
21 | |||
22 | #define prefetch(x) __builtin_prefetch(x) |
||
23 | |||
24 | struct list_head { |
||
25 | struct list_head *next, *prev; |
||
26 | }; |
||
27 | |||
28 | #define LIST_HEAD_INIT(name) { &(name), &(name) } |
||
29 | |||
30 | #define LIST_HEAD(name) \ |
||
31 | struct list_head name = LIST_HEAD_INIT(name) |
||
32 | |||
33 | static inline void INIT_LIST_HEAD(struct list_head *list) |
||
34 | { |
||
35 | list->next = list; |
||
36 | list->prev = list; |
||
37 | } |
||
38 | |||
39 | /* |
||
40 | * Insert a new entry between two known consecutive entries. |
||
41 | * |
||
42 | * This is only for internal list manipulation where we know |
||
43 | * the prev/next entries already! |
||
44 | */ |
||
45 | #ifndef CONFIG_DEBUG_LIST |
||
46 | static inline void __list_add(struct list_head *new, |
||
47 | struct list_head *prev, |
||
48 | struct list_head *next) |
||
49 | { |
||
50 | next->prev = new; |
||
51 | new->next = next; |
||
52 | new->prev = prev; |
||
53 | prev->next = new; |
||
54 | } |
||
55 | #else |
||
56 | extern void __list_add(struct list_head *new, |
||
57 | struct list_head *prev, |
||
58 | struct list_head *next); |
||
59 | #endif |
||
60 | |||
61 | /** |
||
62 | * list_add - add a new entry |
||
63 | * @new: new entry to be added |
||
64 | * @head: list head to add it after |
||
65 | * |
||
66 | * Insert a new entry after the specified head. |
||
67 | * This is good for implementing stacks. |
||
68 | */ |
||
69 | static inline void list_add(struct list_head *new, struct list_head *head) |
||
70 | { |
||
71 | __list_add(new, head, head->next); |
||
72 | } |
||
73 | |||
74 | |||
75 | /** |
||
76 | * list_add_tail - add a new entry |
||
77 | * @new: new entry to be added |
||
78 | * @head: list head to add it before |
||
79 | * |
||
80 | * Insert a new entry before the specified head. |
||
81 | * This is useful for implementing queues. |
||
82 | */ |
||
83 | static inline void list_add_tail(struct list_head *new, struct list_head *head) |
||
84 | { |
||
85 | __list_add(new, head->prev, head); |
||
86 | } |
||
87 | |||
88 | /* |
||
89 | * Delete a list entry by making the prev/next entries |
||
90 | * point to each other. |
||
91 | * |
||
92 | * This is only for internal list manipulation where we know |
||
93 | * the prev/next entries already! |
||
94 | */ |
||
95 | static inline void __list_del(struct list_head * prev, struct list_head * next) |
||
96 | { |
||
97 | next->prev = prev; |
||
98 | prev->next = next; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * list_del - deletes entry from list. |
||
103 | * @entry: the element to delete from the list. |
||
104 | * Note: list_empty() on entry does not return true after this, the entry is |
||
105 | * in an undefined state. |
||
106 | */ |
||
107 | #ifndef CONFIG_DEBUG_LIST |
||
108 | static inline void list_del(struct list_head *entry) |
||
109 | { |
||
110 | __list_del(entry->prev, entry->next); |
||
111 | entry->next = LIST_POISON1; |
||
112 | entry->prev = LIST_POISON2; |
||
113 | } |
||
114 | #else |
||
115 | extern void list_del(struct list_head *entry); |
||
116 | #endif |
||
117 | |||
118 | /** |
||
119 | * list_replace - replace old entry by new one |
||
120 | * @old : the element to be replaced |
||
121 | * @new : the new element to insert |
||
122 | * |
||
123 | * If @old was empty, it will be overwritten. |
||
124 | */ |
||
125 | static inline void list_replace(struct list_head *old, |
||
126 | struct list_head *new) |
||
127 | { |
||
128 | new->next = old->next; |
||
129 | new->next->prev = new; |
||
130 | new->prev = old->prev; |
||
131 | new->prev->next = new; |
||
132 | } |
||
133 | |||
134 | static inline void list_replace_init(struct list_head *old, |
||
135 | struct list_head *new) |
||
136 | { |
||
137 | list_replace(old, new); |
||
138 | INIT_LIST_HEAD(old); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * list_del_init - deletes entry from list and reinitialize it. |
||
143 | * @entry: the element to delete from the list. |
||
144 | */ |
||
145 | static inline void list_del_init(struct list_head *entry) |
||
146 | { |
||
147 | __list_del(entry->prev, entry->next); |
||
148 | INIT_LIST_HEAD(entry); |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * list_move - delete from one list and add as another's head |
||
153 | * @list: the entry to move |
||
154 | * @head: the head that will precede our entry |
||
155 | */ |
||
156 | static inline void list_move(struct list_head *list, struct list_head *head) |
||
157 | { |
||
158 | __list_del(list->prev, list->next); |
||
159 | list_add(list, head); |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * list_move_tail - delete from one list and add as another's tail |
||
164 | * @list: the entry to move |
||
165 | * @head: the head that will follow our entry |
||
166 | */ |
||
167 | static inline void list_move_tail(struct list_head *list, |
||
168 | struct list_head *head) |
||
169 | { |
||
170 | __list_del(list->prev, list->next); |
||
171 | list_add_tail(list, head); |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * list_is_last - tests whether @list is the last entry in list @head |
||
176 | * @list: the entry to test |
||
177 | * @head: the head of the list |
||
178 | */ |
||
179 | static inline int list_is_last(const struct list_head *list, |
||
180 | const struct list_head *head) |
||
181 | { |
||
182 | return list->next == head; |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * list_empty - tests whether a list is empty |
||
187 | * @head: the list to test. |
||
188 | */ |
||
189 | static inline int list_empty(const struct list_head *head) |
||
190 | { |
||
191 | return head->next == head; |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * list_empty_careful - tests whether a list is empty and not being modified |
||
196 | * @head: the list to test |
||
197 | * |
||
198 | * Description: |
||
199 | * tests whether a list is empty _and_ checks that no other CPU might be |
||
200 | * in the process of modifying either member (next or prev) |
||
201 | * |
||
202 | * NOTE: using list_empty_careful() without synchronization |
||
203 | * can only be safe if the only activity that can happen |
||
204 | * to the list entry is list_del_init(). Eg. it cannot be used |
||
205 | * if another CPU could re-list_add() it. |
||
206 | */ |
||
207 | static inline int list_empty_careful(const struct list_head *head) |
||
208 | { |
||
209 | struct list_head *next = head->next; |
||
210 | return (next == head) && (next == head->prev); |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * list_is_singular - tests whether a list has just one entry. |
||
215 | * @head: the list to test. |
||
216 | */ |
||
217 | static inline int list_is_singular(const struct list_head *head) |
||
218 | { |
||
219 | return !list_empty(head) && (head->next == head->prev); |
||
220 | } |
||
221 | |||
222 | static inline void __list_cut_position(struct list_head *list, |
||
223 | struct list_head *head, struct list_head *entry) |
||
224 | { |
||
225 | struct list_head *new_first = entry->next; |
||
226 | list->next = head->next; |
||
227 | list->next->prev = list; |
||
228 | list->prev = entry; |
||
229 | entry->next = list; |
||
230 | head->next = new_first; |
||
231 | new_first->prev = head; |
||
232 | } |
||
233 | |||
234 | /** |
||
235 | * list_cut_position - cut a list into two |
||
236 | * @list: a new list to add all removed entries |
||
237 | * @head: a list with entries |
||
238 | * @entry: an entry within head, could be the head itself |
||
239 | * and if so we won't cut the list |
||
240 | * |
||
241 | * This helper moves the initial part of @head, up to and |
||
242 | * including @entry, from @head to @list. You should |
||
243 | * pass on @entry an element you know is on @head. @list |
||
244 | * should be an empty list or a list you do not care about |
||
245 | * losing its data. |
||
246 | * |
||
247 | */ |
||
248 | static inline void list_cut_position(struct list_head *list, |
||
249 | struct list_head *head, struct list_head *entry) |
||
250 | { |
||
251 | if (list_empty(head)) |
||
252 | return; |
||
253 | if (list_is_singular(head) && |
||
254 | (head->next != entry && head != entry)) |
||
255 | return; |
||
256 | if (entry == head) |
||
257 | INIT_LIST_HEAD(list); |
||
258 | else |
||
259 | __list_cut_position(list, head, entry); |
||
260 | } |
||
261 | |||
262 | static inline void __list_splice(const struct list_head *list, |
||
263 | struct list_head *prev, |
||
264 | struct list_head *next) |
||
265 | { |
||
266 | struct list_head *first = list->next; |
||
267 | struct list_head *last = list->prev; |
||
268 | |||
269 | first->prev = prev; |
||
270 | prev->next = first; |
||
271 | |||
272 | last->next = next; |
||
273 | next->prev = last; |
||
274 | } |
||
275 | |||
276 | /** |
||
277 | * list_splice - join two lists, this is designed for stacks |
||
278 | * @list: the new list to add. |
||
279 | * @head: the place to add it in the first list. |
||
280 | */ |
||
281 | static inline void list_splice(const struct list_head *list, |
||
282 | struct list_head *head) |
||
283 | { |
||
284 | if (!list_empty(list)) |
||
285 | __list_splice(list, head, head->next); |
||
286 | } |
||
287 | |||
288 | /** |
||
289 | * list_splice_tail - join two lists, each list being a queue |
||
290 | * @list: the new list to add. |
||
291 | * @head: the place to add it in the first list. |
||
292 | */ |
||
293 | static inline void list_splice_tail(struct list_head *list, |
||
294 | struct list_head *head) |
||
295 | { |
||
296 | if (!list_empty(list)) |
||
297 | __list_splice(list, head->prev, head); |
||
298 | } |
||
299 | |||
300 | /** |
||
301 | * list_splice_init - join two lists and reinitialise the emptied list. |
||
302 | * @list: the new list to add. |
||
303 | * @head: the place to add it in the first list. |
||
304 | * |
||
305 | * The list at @list is reinitialised |
||
306 | */ |
||
307 | static inline void list_splice_init(struct list_head *list, |
||
308 | struct list_head *head) |
||
309 | { |
||
310 | if (!list_empty(list)) { |
||
311 | __list_splice(list, head, head->next); |
||
312 | INIT_LIST_HEAD(list); |
||
313 | } |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * list_splice_tail_init - join two lists and reinitialise the emptied list |
||
318 | * @list: the new list to add. |
||
319 | * @head: the place to add it in the first list. |
||
320 | * |
||
321 | * Each of the lists is a queue. |
||
322 | * The list at @list is reinitialised |
||
323 | */ |
||
324 | static inline void list_splice_tail_init(struct list_head *list, |
||
325 | struct list_head *head) |
||
326 | { |
||
327 | if (!list_empty(list)) { |
||
328 | __list_splice(list, head->prev, head); |
||
329 | INIT_LIST_HEAD(list); |
||
330 | } |
||
331 | } |
||
332 | |||
333 | /** |
||
334 | * list_entry - get the struct for this entry |
||
335 | * @ptr: the &struct list_head pointer. |
||
336 | * @type: the type of the struct this is embedded in. |
||
337 | * @member: the name of the list_struct within the struct. |
||
338 | */ |
||
339 | #define list_entry(ptr, type, member) \ |
||
340 | container_of(ptr, type, member) |
||
341 | |||
342 | /** |
||
343 | * list_first_entry - get the first element from a list |
||
344 | * @ptr: the list head to take the element from. |
||
345 | * @type: the type of the struct this is embedded in. |
||
346 | * @member: the name of the list_struct within the struct. |
||
347 | * |
||
348 | * Note, that list is expected to be not empty. |
||
349 | */ |
||
350 | #define list_first_entry(ptr, type, member) \ |
||
351 | list_entry((ptr)->next, type, member) |
||
352 | |||
353 | /** |
||
354 | * list_for_each - iterate over a list |
||
355 | * @pos: the &struct list_head to use as a loop cursor. |
||
356 | * @head: the head for your list. |
||
357 | */ |
||
358 | #define list_for_each(pos, head) \ |
||
359 | for (pos = (head)->next; prefetch(pos->next), pos != (head); \ |
||
360 | pos = pos->next) |
||
361 | |||
362 | /** |
||
363 | * __list_for_each - iterate over a list |
||
364 | * @pos: the &struct list_head to use as a loop cursor. |
||
365 | * @head: the head for your list. |
||
366 | * |
||
367 | * This variant differs from list_for_each() in that it's the |
||
368 | * simplest possible list iteration code, no prefetching is done. |
||
369 | * Use this for code that knows the list to be very short (empty |
||
370 | * or 1 entry) most of the time. |
||
371 | */ |
||
372 | #define __list_for_each(pos, head) \ |
||
373 | for (pos = (head)->next; pos != (head); pos = pos->next) |
||
374 | |||
375 | /** |
||
376 | * list_for_each_prev - iterate over a list backwards |
||
377 | * @pos: the &struct list_head to use as a loop cursor. |
||
378 | * @head: the head for your list. |
||
379 | */ |
||
380 | #define list_for_each_prev(pos, head) \ |
||
381 | for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \ |
||
382 | pos = pos->prev) |
||
383 | |||
384 | /** |
||
385 | * list_for_each_safe - iterate over a list safe against removal of list entry |
||
386 | * @pos: the &struct list_head to use as a loop cursor. |
||
387 | * @n: another &struct list_head to use as temporary storage |
||
388 | * @head: the head for your list. |
||
389 | */ |
||
390 | #define list_for_each_safe(pos, n, head) \ |
||
391 | for (pos = (head)->next, n = pos->next; pos != (head); \ |
||
392 | pos = n, n = pos->next) |
||
393 | |||
394 | /** |
||
395 | * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry |
||
396 | * @pos: the &struct list_head to use as a loop cursor. |
||
397 | * @n: another &struct list_head to use as temporary storage |
||
398 | * @head: the head for your list. |
||
399 | */ |
||
400 | #define list_for_each_prev_safe(pos, n, head) \ |
||
401 | for (pos = (head)->prev, n = pos->prev; \ |
||
402 | prefetch(pos->prev), pos != (head); \ |
||
403 | pos = n, n = pos->prev) |
||
404 | |||
405 | /** |
||
406 | * list_for_each_entry - iterate over list of given type |
||
407 | * @pos: the type * to use as a loop cursor. |
||
408 | * @head: the head for your list. |
||
409 | * @member: the name of the list_struct within the struct. |
||
410 | */ |
||
411 | #define list_for_each_entry(pos, head, member) \ |
||
412 | for (pos = list_entry((head)->next, typeof(*pos), member); \ |
||
413 | prefetch(pos->member.next), &pos->member != (head); \ |
||
414 | pos = list_entry(pos->member.next, typeof(*pos), member)) |
||
415 | |||
416 | /** |
||
417 | * list_for_each_entry_reverse - iterate backwards over list of given type. |
||
418 | * @pos: the type * to use as a loop cursor. |
||
419 | * @head: the head for your list. |
||
420 | * @member: the name of the list_struct within the struct. |
||
421 | */ |
||
422 | #define list_for_each_entry_reverse(pos, head, member) \ |
||
423 | for (pos = list_entry((head)->prev, typeof(*pos), member); \ |
||
424 | prefetch(pos->member.prev), &pos->member != (head); \ |
||
425 | pos = list_entry(pos->member.prev, typeof(*pos), member)) |
||
426 | |||
427 | /** |
||
428 | * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() |
||
429 | * @pos: the type * to use as a start point |
||
430 | * @head: the head of the list |
||
431 | * @member: the name of the list_struct within the struct. |
||
432 | * |
||
433 | * Prepares a pos entry for use as a start point in list_for_each_entry_continue(). |
||
434 | */ |
||
435 | #define list_prepare_entry(pos, head, member) \ |
||
436 | ((pos) ? : list_entry(head, typeof(*pos), member)) |
||
437 | |||
438 | /** |
||
439 | * list_for_each_entry_continue - continue iteration over list of given type |
||
440 | * @pos: the type * to use as a loop cursor. |
||
441 | * @head: the head for your list. |
||
442 | * @member: the name of the list_struct within the struct. |
||
443 | * |
||
444 | * Continue to iterate over list of given type, continuing after |
||
445 | * the current position. |
||
446 | */ |
||
447 | #define list_for_each_entry_continue(pos, head, member) \ |
||
448 | for (pos = list_entry(pos->member.next, typeof(*pos), member); \ |
||
449 | prefetch(pos->member.next), &pos->member != (head); \ |
||
450 | pos = list_entry(pos->member.next, typeof(*pos), member)) |
||
451 | |||
452 | /** |
||
453 | * list_for_each_entry_continue_reverse - iterate backwards from the given point |
||
454 | * @pos: the type * to use as a loop cursor. |
||
455 | * @head: the head for your list. |
||
456 | * @member: the name of the list_struct within the struct. |
||
457 | * |
||
458 | * Start to iterate over list of given type backwards, continuing after |
||
459 | * the current position. |
||
460 | */ |
||
461 | #define list_for_each_entry_continue_reverse(pos, head, member) \ |
||
462 | for (pos = list_entry(pos->member.prev, typeof(*pos), member); \ |
||
463 | prefetch(pos->member.prev), &pos->member != (head); \ |
||
464 | pos = list_entry(pos->member.prev, typeof(*pos), member)) |
||
465 | |||
466 | /** |
||
467 | * list_for_each_entry_from - iterate over list of given type from the current point |
||
468 | * @pos: the type * to use as a loop cursor. |
||
469 | * @head: the head for your list. |
||
470 | * @member: the name of the list_struct within the struct. |
||
471 | * |
||
472 | * Iterate over list of given type, continuing from current position. |
||
473 | */ |
||
474 | #define list_for_each_entry_from(pos, head, member) \ |
||
475 | for (; prefetch(pos->member.next), &pos->member != (head); \ |
||
476 | pos = list_entry(pos->member.next, typeof(*pos), member)) |
||
477 | |||
478 | /** |
||
479 | * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry |
||
480 | * @pos: the type * to use as a loop cursor. |
||
481 | * @n: another type * to use as temporary storage |
||
482 | * @head: the head for your list. |
||
483 | * @member: the name of the list_struct within the struct. |
||
484 | */ |
||
485 | #define list_for_each_entry_safe(pos, n, head, member) \ |
||
486 | for (pos = list_entry((head)->next, typeof(*pos), member), \ |
||
487 | n = list_entry(pos->member.next, typeof(*pos), member); \ |
||
488 | &pos->member != (head); \ |
||
489 | pos = n, n = list_entry(n->member.next, typeof(*n), member)) |
||
490 | |||
491 | /** |
||
492 | * list_for_each_entry_safe_continue |
||
493 | * @pos: the type * to use as a loop cursor. |
||
494 | * @n: another type * to use as temporary storage |
||
495 | * @head: the head for your list. |
||
496 | * @member: the name of the list_struct within the struct. |
||
497 | * |
||
498 | * Iterate over list of given type, continuing after current point, |
||
499 | * safe against removal of list entry. |
||
500 | */ |
||
501 | #define list_for_each_entry_safe_continue(pos, n, head, member) \ |
||
502 | for (pos = list_entry(pos->member.next, typeof(*pos), member), \ |
||
503 | n = list_entry(pos->member.next, typeof(*pos), member); \ |
||
504 | &pos->member != (head); \ |
||
505 | pos = n, n = list_entry(n->member.next, typeof(*n), member)) |
||
506 | |||
507 | /** |
||
508 | * list_for_each_entry_safe_from |
||
509 | * @pos: the type * to use as a loop cursor. |
||
510 | * @n: another type * to use as temporary storage |
||
511 | * @head: the head for your list. |
||
512 | * @member: the name of the list_struct within the struct. |
||
513 | * |
||
514 | * Iterate over list of given type from current point, safe against |
||
515 | * removal of list entry. |
||
516 | */ |
||
517 | #define list_for_each_entry_safe_from(pos, n, head, member) \ |
||
518 | for (n = list_entry(pos->member.next, typeof(*pos), member); \ |
||
519 | &pos->member != (head); \ |
||
520 | pos = n, n = list_entry(n->member.next, typeof(*n), member)) |
||
521 | |||
522 | /** |
||
523 | * list_for_each_entry_safe_reverse |
||
524 | * @pos: the type * to use as a loop cursor. |
||
525 | * @n: another type * to use as temporary storage |
||
526 | * @head: the head for your list. |
||
527 | * @member: the name of the list_struct within the struct. |
||
528 | * |
||
529 | * Iterate backwards over list of given type, safe against removal |
||
530 | * of list entry. |
||
531 | */ |
||
532 | #define list_for_each_entry_safe_reverse(pos, n, head, member) \ |
||
533 | for (pos = list_entry((head)->prev, typeof(*pos), member), \ |
||
534 | n = list_entry(pos->member.prev, typeof(*pos), member); \ |
||
535 | &pos->member != (head); \ |
||
536 | pos = n, n = list_entry(n->member.prev, typeof(*n), member)) |
||
537 | |||
538 | /* |
||
539 | * Double linked lists with a single pointer list head. |
||
540 | * Mostly useful for hash tables where the two pointer list head is |
||
541 | * too wasteful. |
||
542 | * You lose the ability to access the tail in O(1). |
||
543 | */ |
||
544 | |||
545 | struct hlist_head { |
||
546 | struct hlist_node *first; |
||
547 | }; |
||
548 | |||
549 | struct hlist_node { |
||
550 | struct hlist_node *next, **pprev; |
||
551 | }; |
||
552 | |||
553 | #define HLIST_HEAD_INIT { .first = NULL } |
||
554 | #define HLIST_HEAD(name) struct hlist_head name = { .first = NULL } |
||
555 | #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) |
||
556 | static inline void INIT_HLIST_NODE(struct hlist_node *h) |
||
557 | { |
||
558 | h->next = NULL; |
||
559 | h->pprev = NULL; |
||
560 | } |
||
561 | |||
562 | static inline int hlist_unhashed(const struct hlist_node *h) |
||
563 | { |
||
564 | return !h->pprev; |
||
565 | } |
||
566 | |||
567 | static inline int hlist_empty(const struct hlist_head *h) |
||
568 | { |
||
569 | return !h->first; |
||
570 | } |
||
571 | |||
572 | static inline void __hlist_del(struct hlist_node *n) |
||
573 | { |
||
574 | struct hlist_node *next = n->next; |
||
575 | struct hlist_node **pprev = n->pprev; |
||
576 | *pprev = next; |
||
577 | if (next) |
||
578 | next->pprev = pprev; |
||
579 | } |
||
580 | |||
581 | static inline void hlist_del(struct hlist_node *n) |
||
582 | { |
||
583 | __hlist_del(n); |
||
584 | n->next = (struct hlist_node*)LIST_POISON1; |
||
585 | n->pprev = (struct hlist_node**)LIST_POISON2; |
||
586 | } |
||
587 | |||
588 | static inline void hlist_del_init(struct hlist_node *n) |
||
589 | { |
||
590 | if (!hlist_unhashed(n)) { |
||
591 | __hlist_del(n); |
||
592 | INIT_HLIST_NODE(n); |
||
593 | } |
||
594 | } |
||
595 | |||
596 | static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) |
||
597 | { |
||
598 | struct hlist_node *first = h->first; |
||
599 | n->next = first; |
||
600 | if (first) |
||
601 | first->pprev = &n->next; |
||
602 | h->first = n; |
||
603 | n->pprev = &h->first; |
||
604 | } |
||
605 | |||
606 | /* next must be != NULL */ |
||
607 | static inline void hlist_add_before(struct hlist_node *n, |
||
608 | struct hlist_node *next) |
||
609 | { |
||
610 | n->pprev = next->pprev; |
||
611 | n->next = next; |
||
612 | next->pprev = &n->next; |
||
613 | *(n->pprev) = n; |
||
614 | } |
||
615 | |||
616 | static inline void hlist_add_after(struct hlist_node *n, |
||
617 | struct hlist_node *next) |
||
618 | { |
||
619 | next->next = n->next; |
||
620 | n->next = next; |
||
621 | next->pprev = &n->next; |
||
622 | |||
623 | if(next->next) |
||
624 | next->next->pprev = &next->next; |
||
625 | } |
||
626 | |||
627 | /* |
||
628 | * Move a list from one list head to another. Fixup the pprev |
||
629 | * reference of the first entry if it exists. |
||
630 | */ |
||
631 | static inline void hlist_move_list(struct hlist_head *old, |
||
632 | struct hlist_head *new) |
||
633 | { |
||
634 | new->first = old->first; |
||
635 | if (new->first) |
||
636 | new->first->pprev = &new->first; |
||
637 | old->first = NULL; |
||
638 | } |
||
639 | |||
640 | #define hlist_entry(ptr, type, member) container_of(ptr,type,member) |
||
641 | |||
642 | #define hlist_for_each(pos, head) \ |
||
643 | for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \ |
||
644 | pos = pos->next) |
||
645 | |||
646 | #define hlist_for_each_safe(pos, n, head) \ |
||
647 | for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \ |
||
648 | pos = n) |
||
649 | |||
650 | /** |
||
651 | * hlist_for_each_entry - iterate over list of given type |
||
652 | * @tpos: the type * to use as a loop cursor. |
||
653 | * @pos: the &struct hlist_node to use as a loop cursor. |
||
654 | * @head: the head for your list. |
||
655 | * @member: the name of the hlist_node within the struct. |
||
656 | */ |
||
657 | #define hlist_for_each_entry(tpos, pos, head, member) \ |
||
658 | for (pos = (head)->first; \ |
||
659 | pos && ({ prefetch(pos->next); 1;}) && \ |
||
660 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ |
||
661 | pos = pos->next) |
||
662 | |||
663 | /** |
||
664 | * hlist_for_each_entry_continue - iterate over a hlist continuing after current point |
||
665 | * @tpos: the type * to use as a loop cursor. |
||
666 | * @pos: the &struct hlist_node to use as a loop cursor. |
||
667 | * @member: the name of the hlist_node within the struct. |
||
668 | */ |
||
669 | #define hlist_for_each_entry_continue(tpos, pos, member) \ |
||
670 | for (pos = (pos)->next; \ |
||
671 | pos && ({ prefetch(pos->next); 1;}) && \ |
||
672 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ |
||
673 | pos = pos->next) |
||
674 | |||
675 | /** |
||
676 | * hlist_for_each_entry_from - iterate over a hlist continuing from current point |
||
677 | * @tpos: the type * to use as a loop cursor. |
||
678 | * @pos: the &struct hlist_node to use as a loop cursor. |
||
679 | * @member: the name of the hlist_node within the struct. |
||
680 | */ |
||
681 | #define hlist_for_each_entry_from(tpos, pos, member) \ |
||
682 | for (; pos && ({ prefetch(pos->next); 1;}) && \ |
||
683 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ |
||
684 | pos = pos->next) |
||
685 | |||
686 | /** |
||
687 | * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry |
||
688 | * @tpos: the type * to use as a loop cursor. |
||
689 | * @pos: the &struct hlist_node to use as a loop cursor. |
||
690 | * @n: another &struct hlist_node to use as temporary storage |
||
691 | * @head: the head for your list. |
||
692 | * @member: the name of the hlist_node within the struct. |
||
693 | */ |
||
694 | #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \ |
||
695 | for (pos = (head)->first; \ |
||
696 | pos && ({ n = pos->next; 1; }) && \ |
||
697 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ |
||
698 | pos = n) |
||
699 | |||
700 | #endif |