6 #include <linux/stddef.h>
7 #include <linux/poison.h>
8 #include <linux/prefetch.h>
9 #include <asm/system.h>
12 * Simple doubly linked list implementation.
14 * Some of the internal functions ("__xxx") are useful when
15 * manipulating whole lists rather than single entries, as
16 * sometimes we already know the next/prev entries and we can
17 * generate better code by using them directly rather than
18 * using the generic single-entry routines.
22 struct list_head *next, *prev;
25 #define LIST_HEAD_INIT(name) { &(name), &(name) }
27 #define LIST_HEAD(name) \
28 struct list_head name = LIST_HEAD_INIT(name)
30 static inline void INIT_LIST_HEAD(struct list_head *list)
37 * Insert a new entry between two known consecutive entries.
39 * This is only for internal list manipulation where we know
40 * the prev/next entries already!
42 #ifndef CONFIG_DEBUG_LIST
43 static inline void __list_add(struct list_head *new,
44 struct list_head *prev,
45 struct list_head *next)
53 extern void __list_add(struct list_head *new,
54 struct list_head *prev,
55 struct list_head *next);
59 * list_add - add a new entry
60 * @new: new entry to be added
61 * @head: list head to add it after
63 * Insert a new entry after the specified head.
64 * This is good for implementing stacks.
66 #ifndef CONFIG_DEBUG_LIST
67 static inline void list_add(struct list_head *new, struct list_head *head)
69 __list_add(new, head, head->next);
72 extern void list_add(struct list_head *new, struct list_head *head);
77 * list_add_tail - add a new entry
78 * @new: new entry to be added
79 * @head: list head to add it before
81 * Insert a new entry before the specified head.
82 * This is useful for implementing queues.
84 static inline void list_add_tail(struct list_head *new, struct list_head *head)
86 __list_add(new, head->prev, head);
90 * Insert a new entry between two known consecutive entries.
92 * This is only for internal list manipulation where we know
93 * the prev/next entries already!
95 static inline void __list_add_rcu(struct list_head * new,
96 struct list_head * prev, struct list_head * next)
106 * list_add_rcu - add a new entry to rcu-protected list
107 * @new: new entry to be added
108 * @head: list head to add it after
110 * Insert a new entry after the specified head.
111 * This is good for implementing stacks.
113 * The caller must take whatever precautions are necessary
114 * (such as holding appropriate locks) to avoid racing
115 * with another list-mutation primitive, such as list_add_rcu()
116 * or list_del_rcu(), running on this same list.
117 * However, it is perfectly legal to run concurrently with
118 * the _rcu list-traversal primitives, such as
119 * list_for_each_entry_rcu().
121 static inline void list_add_rcu(struct list_head *new, struct list_head *head)
123 __list_add_rcu(new, head, head->next);
127 * list_add_tail_rcu - add a new entry to rcu-protected list
128 * @new: new entry to be added
129 * @head: list head to add it before
131 * Insert a new entry before the specified head.
132 * This is useful for implementing queues.
134 * The caller must take whatever precautions are necessary
135 * (such as holding appropriate locks) to avoid racing
136 * with another list-mutation primitive, such as list_add_tail_rcu()
137 * or list_del_rcu(), running on this same list.
138 * However, it is perfectly legal to run concurrently with
139 * the _rcu list-traversal primitives, such as
140 * list_for_each_entry_rcu().
142 static inline void list_add_tail_rcu(struct list_head *new,
143 struct list_head *head)
145 __list_add_rcu(new, head->prev, head);
149 * Delete a list entry by making the prev/next entries
150 * point to each other.
152 * This is only for internal list manipulation where we know
153 * the prev/next entries already!
155 static inline void __list_del(struct list_head * prev, struct list_head * next)
162 * list_del - deletes entry from list.
163 * @entry: the element to delete from the list.
164 * Note: list_empty() on entry does not return true after this, the entry is
165 * in an undefined state.
167 #ifndef CONFIG_DEBUG_LIST
168 static inline void list_del(struct list_head *entry)
170 __list_del(entry->prev, entry->next);
171 entry->next = LIST_POISON1;
172 entry->prev = LIST_POISON2;
175 extern void list_del(struct list_head *entry);
179 * list_del_rcu - deletes entry from list without re-initialization
180 * @entry: the element to delete from the list.
182 * Note: list_empty() on entry does not return true after this,
183 * the entry is in an undefined state. It is useful for RCU based
184 * lockfree traversal.
186 * In particular, it means that we can not poison the forward
187 * pointers that may still be used for walking the list.
189 * The caller must take whatever precautions are necessary
190 * (such as holding appropriate locks) to avoid racing
191 * with another list-mutation primitive, such as list_del_rcu()
192 * or list_add_rcu(), running on this same list.
193 * However, it is perfectly legal to run concurrently with
194 * the _rcu list-traversal primitives, such as
195 * list_for_each_entry_rcu().
197 * Note that the caller is not permitted to immediately free
198 * the newly deleted entry. Instead, either synchronize_rcu()
199 * or call_rcu() must be used to defer freeing until an RCU
200 * grace period has elapsed.
202 static inline void list_del_rcu(struct list_head *entry)
204 __list_del(entry->prev, entry->next);
205 entry->prev = LIST_POISON2;
209 * list_replace - replace old entry by new one
210 * @old : the element to be replaced
211 * @new : the new element to insert
213 * If @old was empty, it will be overwritten.
215 static inline void list_replace(struct list_head *old,
216 struct list_head *new)
218 new->next = old->next;
219 new->next->prev = new;
220 new->prev = old->prev;
221 new->prev->next = new;
224 static inline void list_replace_init(struct list_head *old,
225 struct list_head *new)
227 list_replace(old, new);
232 * list_replace_rcu - replace old entry by new one
233 * @old : the element to be replaced
234 * @new : the new element to insert
236 * The @old entry will be replaced with the @new entry atomically.
237 * Note: @old should not be empty.
239 static inline void list_replace_rcu(struct list_head *old,
240 struct list_head *new)
242 new->next = old->next;
243 new->prev = old->prev;
245 new->next->prev = new;
246 new->prev->next = new;
247 old->prev = LIST_POISON2;
251 * list_del_init - deletes entry from list and reinitialize it.
252 * @entry: the element to delete from the list.
254 static inline void list_del_init(struct list_head *entry)
256 __list_del(entry->prev, entry->next);
257 INIT_LIST_HEAD(entry);
261 * list_move - delete from one list and add as another's head
262 * @list: the entry to move
263 * @head: the head that will precede our entry
265 static inline void list_move(struct list_head *list, struct list_head *head)
267 __list_del(list->prev, list->next);
268 list_add(list, head);
272 * list_move_tail - delete from one list and add as another's tail
273 * @list: the entry to move
274 * @head: the head that will follow our entry
276 static inline void list_move_tail(struct list_head *list,
277 struct list_head *head)
279 __list_del(list->prev, list->next);
280 list_add_tail(list, head);
284 * list_is_last - tests whether @list is the last entry in list @head
285 * @list: the entry to test
286 * @head: the head of the list
288 static inline int list_is_last(const struct list_head *list,
289 const struct list_head *head)
291 return list->next == head;
295 * list_empty - tests whether a list is empty
296 * @head: the list to test.
298 static inline int list_empty(const struct list_head *head)
300 return head->next == head;
304 * list_empty_careful - tests whether a list is empty and not being modified
305 * @head: the list to test
308 * tests whether a list is empty _and_ checks that no other CPU might be
309 * in the process of modifying either member (next or prev)
311 * NOTE: using list_empty_careful() without synchronization
312 * can only be safe if the only activity that can happen
313 * to the list entry is list_del_init(). Eg. it cannot be used
314 * if another CPU could re-list_add() it.
316 static inline int list_empty_careful(const struct list_head *head)
318 struct list_head *next = head->next;
319 return (next == head) && (next == head->prev);
322 static inline void __list_splice(struct list_head *list,
323 struct list_head *head)
325 struct list_head *first = list->next;
326 struct list_head *last = list->prev;
327 struct list_head *at = head->next;
337 * list_splice - join two lists
338 * @list: the new list to add.
339 * @head: the place to add it in the first list.
341 static inline void list_splice(struct list_head *list, struct list_head *head)
343 if (!list_empty(list))
344 __list_splice(list, head);
348 * list_splice_init - join two lists and reinitialise the emptied list.
349 * @list: the new list to add.
350 * @head: the place to add it in the first list.
352 * The list at @list is reinitialised
354 static inline void list_splice_init(struct list_head *list,
355 struct list_head *head)
357 if (!list_empty(list)) {
358 __list_splice(list, head);
359 INIT_LIST_HEAD(list);
364 * list_splice_init_rcu - splice an RCU-protected list into an existing list.
365 * @list: the RCU-protected list to splice
366 * @head: the place in the list to splice the first list into
367 * @sync: function to sync: synchronize_rcu(), synchronize_sched(), ...
369 * @head can be RCU-read traversed concurrently with this function.
371 * Note that this function blocks.
373 * Important note: the caller must take whatever action is necessary to
374 * prevent any other updates to @head. In principle, it is possible
375 * to modify the list as soon as sync() begins execution.
376 * If this sort of thing becomes necessary, an alternative version
377 * based on call_rcu() could be created. But only if -really-
378 * needed -- there is no shortage of RCU API members.
380 static inline void list_splice_init_rcu(struct list_head *list,
381 struct list_head *head,
384 struct list_head *first = list->next;
385 struct list_head *last = list->prev;
386 struct list_head *at = head->next;
388 if (list_empty(head))
391 /* "first" and "last" tracking list, so initialize it. */
393 INIT_LIST_HEAD(list);
396 * At this point, the list body still points to the source list.
397 * Wait for any readers to finish using the list before splicing
398 * the list body into the new list. Any new readers will see
405 * Readers are finished with the source list, so perform splice.
406 * The order is important if the new list is global and accessible
407 * to concurrent RCU readers. Note that RCU readers are not
408 * permitted to traverse the prev pointers without excluding
420 * list_entry - get the struct for this entry
421 * @ptr: the &struct list_head pointer.
422 * @type: the type of the struct this is embedded in.
423 * @member: the name of the list_struct within the struct.
425 #define list_entry(ptr, type, member) \
426 container_of(ptr, type, member)
429 * list_first_entry - get the first element from a list
430 * @ptr: the list head to take the element from.
431 * @type: the type of the struct this is embedded in.
432 * @member: the name of the list_struct within the struct.
434 * Note, that list is expected to be not empty.
436 #define list_first_entry(ptr, type, member) \
437 list_entry((ptr)->next, type, member)
440 * list_for_each - iterate over a list
441 * @pos: the &struct list_head to use as a loop cursor.
442 * @head: the head for your list.
444 #define list_for_each(pos, head) \
445 for (pos = (head)->next; prefetch(pos->next), pos != (head); \
449 * __list_for_each - iterate over a list
450 * @pos: the &struct list_head to use as a loop cursor.
451 * @head: the head for your list.
453 * This variant differs from list_for_each() in that it's the
454 * simplest possible list iteration code, no prefetching is done.
455 * Use this for code that knows the list to be very short (empty
456 * or 1 entry) most of the time.
458 #define __list_for_each(pos, head) \
459 for (pos = (head)->next; pos != (head); pos = pos->next)
462 * list_for_each_prev - iterate over a list backwards
463 * @pos: the &struct list_head to use as a loop cursor.
464 * @head: the head for your list.
466 #define list_for_each_prev(pos, head) \
467 for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
471 * list_for_each_safe - iterate over a list safe against removal of list entry
472 * @pos: the &struct list_head to use as a loop cursor.
473 * @n: another &struct list_head to use as temporary storage
474 * @head: the head for your list.
476 #define list_for_each_safe(pos, n, head) \
477 for (pos = (head)->next, n = pos->next; pos != (head); \
478 pos = n, n = pos->next)
481 * list_for_each_entry - iterate over list of given type
482 * @pos: the type * to use as a loop cursor.
483 * @head: the head for your list.
484 * @member: the name of the list_struct within the struct.
486 #define list_for_each_entry(pos, head, member) \
487 for (pos = list_entry((head)->next, typeof(*pos), member); \
488 prefetch(pos->member.next), &pos->member != (head); \
489 pos = list_entry(pos->member.next, typeof(*pos), member))
492 * list_for_each_entry_reverse - iterate backwards over list of given type.
493 * @pos: the type * to use as a loop cursor.
494 * @head: the head for your list.
495 * @member: the name of the list_struct within the struct.
497 #define list_for_each_entry_reverse(pos, head, member) \
498 for (pos = list_entry((head)->prev, typeof(*pos), member); \
499 prefetch(pos->member.prev), &pos->member != (head); \
500 pos = list_entry(pos->member.prev, typeof(*pos), member))
503 * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
504 * @pos: the type * to use as a start point
505 * @head: the head of the list
506 * @member: the name of the list_struct within the struct.
508 * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
510 #define list_prepare_entry(pos, head, member) \
511 ((pos) ? : list_entry(head, typeof(*pos), member))
514 * list_for_each_entry_continue - continue iteration over list of given type
515 * @pos: the type * to use as a loop cursor.
516 * @head: the head for your list.
517 * @member: the name of the list_struct within the struct.
519 * Continue to iterate over list of given type, continuing after
520 * the current position.
522 #define list_for_each_entry_continue(pos, head, member) \
523 for (pos = list_entry(pos->member.next, typeof(*pos), member); \
524 prefetch(pos->member.next), &pos->member != (head); \
525 pos = list_entry(pos->member.next, typeof(*pos), member))
528 * list_for_each_entry_from - iterate over list of given type from the current point
529 * @pos: the type * to use as a loop cursor.
530 * @head: the head for your list.
531 * @member: the name of the list_struct within the struct.
533 * Iterate over list of given type, continuing from current position.
535 #define list_for_each_entry_from(pos, head, member) \
536 for (; prefetch(pos->member.next), &pos->member != (head); \
537 pos = list_entry(pos->member.next, typeof(*pos), member))
540 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
541 * @pos: the type * to use as a loop cursor.
542 * @n: another type * to use as temporary storage
543 * @head: the head for your list.
544 * @member: the name of the list_struct within the struct.
546 #define list_for_each_entry_safe(pos, n, head, member) \
547 for (pos = list_entry((head)->next, typeof(*pos), member), \
548 n = list_entry(pos->member.next, typeof(*pos), member); \
549 &pos->member != (head); \
550 pos = n, n = list_entry(n->member.next, typeof(*n), member))
553 * list_for_each_entry_safe_continue
554 * @pos: the type * to use as a loop cursor.
555 * @n: another type * to use as temporary storage
556 * @head: the head for your list.
557 * @member: the name of the list_struct within the struct.
559 * Iterate over list of given type, continuing after current point,
560 * safe against removal of list entry.
562 #define list_for_each_entry_safe_continue(pos, n, head, member) \
563 for (pos = list_entry(pos->member.next, typeof(*pos), member), \
564 n = list_entry(pos->member.next, typeof(*pos), member); \
565 &pos->member != (head); \
566 pos = n, n = list_entry(n->member.next, typeof(*n), member))
569 * list_for_each_entry_safe_from
570 * @pos: the type * to use as a loop cursor.
571 * @n: another type * to use as temporary storage
572 * @head: the head for your list.
573 * @member: the name of the list_struct within the struct.
575 * Iterate over list of given type from current point, safe against
576 * removal of list entry.
578 #define list_for_each_entry_safe_from(pos, n, head, member) \
579 for (n = list_entry(pos->member.next, typeof(*pos), member); \
580 &pos->member != (head); \
581 pos = n, n = list_entry(n->member.next, typeof(*n), member))
584 * list_for_each_entry_safe_reverse
585 * @pos: the type * to use as a loop cursor.
586 * @n: another type * to use as temporary storage
587 * @head: the head for your list.
588 * @member: the name of the list_struct within the struct.
590 * Iterate backwards over list of given type, safe against removal
593 #define list_for_each_entry_safe_reverse(pos, n, head, member) \
594 for (pos = list_entry((head)->prev, typeof(*pos), member), \
595 n = list_entry(pos->member.prev, typeof(*pos), member); \
596 &pos->member != (head); \
597 pos = n, n = list_entry(n->member.prev, typeof(*n), member))
600 * list_for_each_rcu - iterate over an rcu-protected list
601 * @pos: the &struct list_head to use as a loop cursor.
602 * @head: the head for your list.
604 * This list-traversal primitive may safely run concurrently with
605 * the _rcu list-mutation primitives such as list_add_rcu()
606 * as long as the traversal is guarded by rcu_read_lock().
608 #define list_for_each_rcu(pos, head) \
609 for (pos = (head)->next; \
610 prefetch(rcu_dereference(pos)->next), pos != (head); \
613 #define __list_for_each_rcu(pos, head) \
614 for (pos = (head)->next; \
615 rcu_dereference(pos) != (head); \
619 * list_for_each_safe_rcu
620 * @pos: the &struct list_head to use as a loop cursor.
621 * @n: another &struct list_head to use as temporary storage
622 * @head: the head for your list.
624 * Iterate over an rcu-protected list, safe against removal of list entry.
626 * This list-traversal primitive may safely run concurrently with
627 * the _rcu list-mutation primitives such as list_add_rcu()
628 * as long as the traversal is guarded by rcu_read_lock().
630 #define list_for_each_safe_rcu(pos, n, head) \
631 for (pos = (head)->next; \
632 n = rcu_dereference(pos)->next, pos != (head); \
636 * list_for_each_entry_rcu - iterate over rcu list of given type
637 * @pos: the type * to use as a loop cursor.
638 * @head: the head for your list.
639 * @member: the name of the list_struct within the struct.
641 * This list-traversal primitive may safely run concurrently with
642 * the _rcu list-mutation primitives such as list_add_rcu()
643 * as long as the traversal is guarded by rcu_read_lock().
645 #define list_for_each_entry_rcu(pos, head, member) \
646 for (pos = list_entry((head)->next, typeof(*pos), member); \
647 prefetch(rcu_dereference(pos)->member.next), \
648 &pos->member != (head); \
649 pos = list_entry(pos->member.next, typeof(*pos), member))
653 * list_for_each_continue_rcu
654 * @pos: the &struct list_head to use as a loop cursor.
655 * @head: the head for your list.
657 * Iterate over an rcu-protected list, continuing after current point.
659 * This list-traversal primitive may safely run concurrently with
660 * the _rcu list-mutation primitives such as list_add_rcu()
661 * as long as the traversal is guarded by rcu_read_lock().
663 #define list_for_each_continue_rcu(pos, head) \
664 for ((pos) = (pos)->next; \
665 prefetch(rcu_dereference((pos))->next), (pos) != (head); \
669 * Double linked lists with a single pointer list head.
670 * Mostly useful for hash tables where the two pointer list head is
672 * You lose the ability to access the tail in O(1).
676 struct hlist_node *first;
680 struct hlist_node *next, **pprev;
683 #define HLIST_HEAD_INIT { .first = NULL }
684 #define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
685 #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
686 static inline void INIT_HLIST_NODE(struct hlist_node *h)
692 static inline int hlist_unhashed(const struct hlist_node *h)
697 static inline int hlist_empty(const struct hlist_head *h)
702 static inline void __hlist_del(struct hlist_node *n)
704 struct hlist_node *next = n->next;
705 struct hlist_node **pprev = n->pprev;
711 static inline void hlist_del(struct hlist_node *n)
714 n->next = LIST_POISON1;
715 n->pprev = LIST_POISON2;
719 * hlist_del_rcu - deletes entry from hash list without re-initialization
720 * @n: the element to delete from the hash list.
722 * Note: list_unhashed() on entry does not return true after this,
723 * the entry is in an undefined state. It is useful for RCU based
724 * lockfree traversal.
726 * In particular, it means that we can not poison the forward
727 * pointers that may still be used for walking the hash list.
729 * The caller must take whatever precautions are necessary
730 * (such as holding appropriate locks) to avoid racing
731 * with another list-mutation primitive, such as hlist_add_head_rcu()
732 * or hlist_del_rcu(), running on this same list.
733 * However, it is perfectly legal to run concurrently with
734 * the _rcu list-traversal primitives, such as
735 * hlist_for_each_entry().
737 static inline void hlist_del_rcu(struct hlist_node *n)
740 n->pprev = LIST_POISON2;
743 static inline void hlist_del_init(struct hlist_node *n)
745 if (!hlist_unhashed(n)) {
752 * hlist_replace_rcu - replace old entry by new one
753 * @old : the element to be replaced
754 * @new : the new element to insert
756 * The @old entry will be replaced with the @new entry atomically.
758 static inline void hlist_replace_rcu(struct hlist_node *old,
759 struct hlist_node *new)
761 struct hlist_node *next = old->next;
764 new->pprev = old->pprev;
767 new->next->pprev = &new->next;
769 old->pprev = LIST_POISON2;
772 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
774 struct hlist_node *first = h->first;
777 first->pprev = &n->next;
779 n->pprev = &h->first;
785 * @n: the element to add to the hash list.
786 * @h: the list to add to.
789 * Adds the specified element to the specified hlist,
790 * while permitting racing traversals.
792 * The caller must take whatever precautions are necessary
793 * (such as holding appropriate locks) to avoid racing
794 * with another list-mutation primitive, such as hlist_add_head_rcu()
795 * or hlist_del_rcu(), running on this same list.
796 * However, it is perfectly legal to run concurrently with
797 * the _rcu list-traversal primitives, such as
798 * hlist_for_each_entry_rcu(), used to prevent memory-consistency
799 * problems on Alpha CPUs. Regardless of the type of CPU, the
800 * list-traversal primitive must be guarded by rcu_read_lock().
802 static inline void hlist_add_head_rcu(struct hlist_node *n,
803 struct hlist_head *h)
805 struct hlist_node *first = h->first;
807 n->pprev = &h->first;
810 first->pprev = &n->next;
814 /* next must be != NULL */
815 static inline void hlist_add_before(struct hlist_node *n,
816 struct hlist_node *next)
818 n->pprev = next->pprev;
820 next->pprev = &n->next;
824 static inline void hlist_add_after(struct hlist_node *n,
825 struct hlist_node *next)
827 next->next = n->next;
829 next->pprev = &n->next;
832 next->next->pprev = &next->next;
836 * hlist_add_before_rcu
837 * @n: the new element to add to the hash list.
838 * @next: the existing element to add the new element before.
841 * Adds the specified element to the specified hlist
842 * before the specified node while permitting racing traversals.
844 * The caller must take whatever precautions are necessary
845 * (such as holding appropriate locks) to avoid racing
846 * with another list-mutation primitive, such as hlist_add_head_rcu()
847 * or hlist_del_rcu(), running on this same list.
848 * However, it is perfectly legal to run concurrently with
849 * the _rcu list-traversal primitives, such as
850 * hlist_for_each_entry_rcu(), used to prevent memory-consistency
851 * problems on Alpha CPUs.
853 static inline void hlist_add_before_rcu(struct hlist_node *n,
854 struct hlist_node *next)
856 n->pprev = next->pprev;
859 next->pprev = &n->next;
864 * hlist_add_after_rcu
865 * @prev: the existing element to add the new element after.
866 * @n: the new element to add to the hash list.
869 * Adds the specified element to the specified hlist
870 * after the specified node while permitting racing traversals.
872 * The caller must take whatever precautions are necessary
873 * (such as holding appropriate locks) to avoid racing
874 * with another list-mutation primitive, such as hlist_add_head_rcu()
875 * or hlist_del_rcu(), running on this same list.
876 * However, it is perfectly legal to run concurrently with
877 * the _rcu list-traversal primitives, such as
878 * hlist_for_each_entry_rcu(), used to prevent memory-consistency
879 * problems on Alpha CPUs.
881 static inline void hlist_add_after_rcu(struct hlist_node *prev,
882 struct hlist_node *n)
884 n->next = prev->next;
885 n->pprev = &prev->next;
889 n->next->pprev = &n->next;
892 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
894 #define hlist_for_each(pos, head) \
895 for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
898 #define hlist_for_each_safe(pos, n, head) \
899 for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
903 * hlist_for_each_entry - iterate over list of given type
904 * @tpos: the type * to use as a loop cursor.
905 * @pos: the &struct hlist_node to use as a loop cursor.
906 * @head: the head for your list.
907 * @member: the name of the hlist_node within the struct.
909 #define hlist_for_each_entry(tpos, pos, head, member) \
910 for (pos = (head)->first; \
911 pos && ({ prefetch(pos->next); 1;}) && \
912 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
916 * hlist_for_each_entry_continue - iterate over a hlist continuing after current point
917 * @tpos: the type * to use as a loop cursor.
918 * @pos: the &struct hlist_node to use as a loop cursor.
919 * @member: the name of the hlist_node within the struct.
921 #define hlist_for_each_entry_continue(tpos, pos, member) \
922 for (pos = (pos)->next; \
923 pos && ({ prefetch(pos->next); 1;}) && \
924 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
928 * hlist_for_each_entry_from - iterate over a hlist continuing from current point
929 * @tpos: the type * to use as a loop cursor.
930 * @pos: the &struct hlist_node to use as a loop cursor.
931 * @member: the name of the hlist_node within the struct.
933 #define hlist_for_each_entry_from(tpos, pos, member) \
934 for (; pos && ({ prefetch(pos->next); 1;}) && \
935 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
939 * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
940 * @tpos: the type * to use as a loop cursor.
941 * @pos: the &struct hlist_node to use as a loop cursor.
942 * @n: another &struct hlist_node to use as temporary storage
943 * @head: the head for your list.
944 * @member: the name of the hlist_node within the struct.
946 #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
947 for (pos = (head)->first; \
948 pos && ({ n = pos->next; 1; }) && \
949 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
953 * hlist_for_each_entry_rcu - iterate over rcu list of given type
954 * @tpos: the type * to use as a loop cursor.
955 * @pos: the &struct hlist_node to use as a loop cursor.
956 * @head: the head for your list.
957 * @member: the name of the hlist_node within the struct.
959 * This list-traversal primitive may safely run concurrently with
960 * the _rcu list-mutation primitives such as hlist_add_head_rcu()
961 * as long as the traversal is guarded by rcu_read_lock().
963 #define hlist_for_each_entry_rcu(tpos, pos, head, member) \
964 for (pos = (head)->first; \
965 rcu_dereference(pos) && ({ prefetch(pos->next); 1;}) && \
966 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
970 #warning "don't include kernel headers in userspace"
971 #endif /* __KERNEL__ */