Release 3.6
[gmidimonitor.git] / list.h
blobfee6e73bab46892a8b71e77b02087f06963cfa2e
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * Linux kernel header adapted for user-mode
5 * The 2.6.17-rt1 version was used.
7 * Original copyright holders of this code are unknown, they were not
8 * mentioned in the original file.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23 *****************************************************************************/
25 #ifndef _LINUX_LIST_H
26 #define _LINUX_LIST_H
28 #include <stddef.h>
30 #if !defined(offsetof)
31 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
32 #endif
34 /**
35 * container_of - cast a member of a structure out to the containing structure
36 * @ptr: the pointer to the member.
37 * @type: the type of the container struct this is embedded in.
38 * @member: the name of the member within the struct.
41 #define container_of(ptr, type, member) ({ \
42 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
43 (type *)( (char *)__mptr - offsetof(type,member) );})
45 #define prefetch(x) (x = x)
48 * These are non-NULL pointers that will result in page faults
49 * under normal circumstances, used to verify that nobody uses
50 * non-initialized list entries.
52 #define LIST_POISON1 ((void *) 0x00100100)
53 #define LIST_POISON2 ((void *) 0x00200200)
56 * Simple doubly linked list implementation.
58 * Some of the internal functions ("__xxx") are useful when
59 * manipulating whole lists rather than single entries, as
60 * sometimes we already know the next/prev entries and we can
61 * generate better code by using them directly rather than
62 * using the generic single-entry routines.
65 struct list_head {
66 struct list_head *next, *prev;
69 #define LIST_HEAD_INIT(name) { &(name), &(name) }
71 #define LIST_HEAD(name) \
72 struct list_head name = LIST_HEAD_INIT(name)
74 static inline void INIT_LIST_HEAD(struct list_head *list)
76 list->next = list;
77 list->prev = list;
81 * Insert a new entry between two known consecutive entries.
83 * This is only for internal list manipulation where we know
84 * the prev/next entries already!
86 static inline void __list_add(struct list_head *new,
87 struct list_head *prev,
88 struct list_head *next)
90 next->prev = new;
91 new->next = next;
92 new->prev = prev;
93 prev->next = new;
96 /**
97 * list_add - add a new entry
98 * @new: new entry to be added
99 * @head: list head to add it after
101 * Insert a new entry after the specified head.
102 * This is good for implementing stacks.
104 static inline void list_add(struct list_head *new, struct list_head *head)
106 __list_add(new, head, head->next);
110 * list_add_tail - add a new entry
111 * @new: new entry to be added
112 * @head: list head to add it before
114 * Insert a new entry before the specified head.
115 * This is useful for implementing queues.
117 static inline void list_add_tail(struct list_head *new, struct list_head *head)
119 __list_add(new, head->prev, head);
123 * Insert a new entry between two known consecutive entries.
125 * This is only for internal list manipulation where we know
126 * the prev/next entries already!
128 static inline void __list_add_rcu(struct list_head * new,
129 struct list_head * prev, struct list_head * next)
131 new->next = next;
132 new->prev = prev;
133 // smp_wmb();
134 next->prev = new;
135 prev->next = new;
139 * list_add_rcu - add a new entry to rcu-protected list
140 * @new: new entry to be added
141 * @head: list head to add it after
143 * Insert a new entry after the specified head.
144 * This is good for implementing stacks.
146 * The caller must take whatever precautions are necessary
147 * (such as holding appropriate locks) to avoid racing
148 * with another list-mutation primitive, such as list_add_rcu()
149 * or list_del_rcu(), running on this same list.
150 * However, it is perfectly legal to run concurrently with
151 * the _rcu list-traversal primitives, such as
152 * list_for_each_entry_rcu().
154 static inline void list_add_rcu(struct list_head *new, struct list_head *head)
156 __list_add_rcu(new, head, head->next);
160 * list_add_tail_rcu - add a new entry to rcu-protected list
161 * @new: new entry to be added
162 * @head: list head to add it before
164 * Insert a new entry before the specified head.
165 * This is useful for implementing queues.
167 * The caller must take whatever precautions are necessary
168 * (such as holding appropriate locks) to avoid racing
169 * with another list-mutation primitive, such as list_add_tail_rcu()
170 * or list_del_rcu(), running on this same list.
171 * However, it is perfectly legal to run concurrently with
172 * the _rcu list-traversal primitives, such as
173 * list_for_each_entry_rcu().
175 static inline void list_add_tail_rcu(struct list_head *new,
176 struct list_head *head)
178 __list_add_rcu(new, head->prev, head);
182 * Delete a list entry by making the prev/next entries
183 * point to each other.
185 * This is only for internal list manipulation where we know
186 * the prev/next entries already!
188 static inline void __list_del(struct list_head * prev, struct list_head * next)
190 next->prev = prev;
191 prev->next = next;
195 * list_del - deletes entry from list.
196 * @entry: the element to delete from the list.
197 * Note: list_empty on entry does not return true after this, the entry is
198 * in an undefined state.
200 static inline void list_del(struct list_head *entry)
202 __list_del(entry->prev, entry->next);
203 entry->next = LIST_POISON1;
204 entry->prev = LIST_POISON2;
208 * list_del_rcu - deletes entry from list without re-initialization
209 * @entry: the element to delete from the list.
211 * Note: list_empty on entry does not return true after this,
212 * the entry is in an undefined state. It is useful for RCU based
213 * lockfree traversal.
215 * In particular, it means that we can not poison the forward
216 * pointers that may still be used for walking the list.
218 * The caller must take whatever precautions are necessary
219 * (such as holding appropriate locks) to avoid racing
220 * with another list-mutation primitive, such as list_del_rcu()
221 * or list_add_rcu(), running on this same list.
222 * However, it is perfectly legal to run concurrently with
223 * the _rcu list-traversal primitives, such as
224 * list_for_each_entry_rcu().
226 * Note that the caller is not permitted to immediately free
227 * the newly deleted entry. Instead, either synchronize_rcu()
228 * or call_rcu() must be used to defer freeing until an RCU
229 * grace period has elapsed.
231 static inline void list_del_rcu(struct list_head *entry)
233 __list_del(entry->prev, entry->next);
234 entry->prev = LIST_POISON2;
238 * list_replace_rcu - replace old entry by new one
239 * @old : the element to be replaced
240 * @new : the new element to insert
242 * The old entry will be replaced with the new entry atomically.
244 static inline void list_replace_rcu(struct list_head *old,
245 struct list_head *new)
247 new->next = old->next;
248 new->prev = old->prev;
249 // smp_wmb();
250 new->next->prev = new;
251 new->prev->next = new;
252 old->prev = LIST_POISON2;
256 * list_del_init - deletes entry from list and reinitialize it.
257 * @entry: the element to delete from the list.
259 static inline void list_del_init(struct list_head *entry)
261 __list_del(entry->prev, entry->next);
262 INIT_LIST_HEAD(entry);
266 * list_move - delete from one list and add as another's head
267 * @list: the entry to move
268 * @head: the head that will precede our entry
270 static inline void list_move(struct list_head *list, struct list_head *head)
272 __list_del(list->prev, list->next);
273 list_add(list, head);
277 * list_move_tail - delete from one list and add as another's tail
278 * @list: the entry to move
279 * @head: the head that will follow our entry
281 static inline void list_move_tail(struct list_head *list,
282 struct list_head *head)
284 __list_del(list->prev, list->next);
285 list_add_tail(list, head);
289 * list_empty - tests whether a list is empty
290 * @head: the list to test.
292 static inline int list_empty(const struct list_head *head)
294 return head->next == head;
298 * list_empty_careful - tests whether a list is
299 * empty _and_ checks that no other CPU might be
300 * in the process of still modifying either member
302 * NOTE: using list_empty_careful() without synchronization
303 * can only be safe if the only activity that can happen
304 * to the list entry is list_del_init(). Eg. it cannot be used
305 * if another CPU could re-list_add() it.
307 * @head: the list to test.
309 static inline int list_empty_careful(const struct list_head *head)
311 struct list_head *next = head->next;
312 return (next == head) && (next == head->prev);
315 static inline void __list_splice(struct list_head *list,
316 struct list_head *head)
318 struct list_head *first = list->next;
319 struct list_head *last = list->prev;
320 struct list_head *at = head->next;
322 first->prev = head;
323 head->next = first;
325 last->next = at;
326 at->prev = last;
330 * list_splice - join two lists
331 * @list: the new list to add.
332 * @head: the place to add it in the first list.
334 static inline void list_splice(struct list_head *list, struct list_head *head)
336 if (!list_empty(list))
337 __list_splice(list, head);
341 * list_splice_init - join two lists and reinitialise the emptied list.
342 * @list: the new list to add.
343 * @head: the place to add it in the first list.
345 * The list at @list is reinitialised
347 static inline void list_splice_init(struct list_head *list,
348 struct list_head *head)
350 if (!list_empty(list)) {
351 __list_splice(list, head);
352 INIT_LIST_HEAD(list);
357 * list_entry - get the struct for this entry
358 * @ptr: the &struct list_head pointer.
359 * @type: the type of the struct this is embedded in.
360 * @member: the name of the list_struct within the struct.
362 #define list_entry(ptr, type, member) \
363 container_of(ptr, type, member)
366 * list_for_each - iterate over a list
367 * @pos: the &struct list_head to use as a loop counter.
368 * @head: the head for your list.
370 #define list_for_each(pos, head) \
371 for (pos = (head)->next; prefetch(pos->next), pos != (head); \
372 pos = pos->next)
375 * __list_for_each - iterate over a list
376 * @pos: the &struct list_head to use as a loop counter.
377 * @head: the head for your list.
379 * This variant differs from list_for_each() in that it's the
380 * simplest possible list iteration code, no prefetching is done.
381 * Use this for code that knows the list to be very short (empty
382 * or 1 entry) most of the time.
384 #define __list_for_each(pos, head) \
385 for (pos = (head)->next; pos != (head); pos = pos->next)
388 * list_for_each_prev - iterate over a list backwards
389 * @pos: the &struct list_head to use as a loop counter.
390 * @head: the head for your list.
392 #define list_for_each_prev(pos, head) \
393 for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
394 pos = pos->prev)
397 * list_for_each_safe - iterate over a list safe against removal of list entry
398 * @pos: the &struct list_head to use as a loop counter.
399 * @n: another &struct list_head to use as temporary storage
400 * @head: the head for your list.
402 #define list_for_each_safe(pos, n, head) \
403 for (pos = (head)->next, n = pos->next; pos != (head); \
404 pos = n, n = pos->next)
407 * list_for_each_entry - iterate over list of given type
408 * @pos: the type * to use as a loop counter.
409 * @head: the head for your list.
410 * @member: the name of the list_struct within the struct.
412 #define list_for_each_entry(pos, head, member) \
413 for (pos = list_entry((head)->next, typeof(*pos), member); \
414 prefetch(pos->member.next), &pos->member != (head); \
415 pos = list_entry(pos->member.next, typeof(*pos), member))
418 * list_for_each_entry_reverse - iterate backwards over list of given type.
419 * @pos: the type * to use as a loop counter.
420 * @head: the head for your list.
421 * @member: the name of the list_struct within the struct.
423 #define list_for_each_entry_reverse(pos, head, member) \
424 for (pos = list_entry((head)->prev, typeof(*pos), member); \
425 prefetch(pos->member.prev), &pos->member != (head); \
426 pos = list_entry(pos->member.prev, typeof(*pos), member))
429 * list_prepare_entry - prepare a pos entry for use as a start point in
430 * list_for_each_entry_continue
431 * @pos: the type * to use as a start point
432 * @head: the head of the list
433 * @member: the name of the list_struct within the struct.
435 #define list_prepare_entry(pos, head, member) \
436 ((pos) ? : list_entry(head, typeof(*pos), member))
439 * list_for_each_entry_continue - iterate over list of given type
440 * continuing after existing point
441 * @pos: the type * to use as a loop counter.
442 * @head: the head for your list.
443 * @member: the name of the list_struct within the struct.
445 #define list_for_each_entry_continue(pos, head, member) \
446 for (pos = list_entry(pos->member.next, typeof(*pos), member); \
447 prefetch(pos->member.next), &pos->member != (head); \
448 pos = list_entry(pos->member.next, typeof(*pos), member))
451 * list_for_each_entry_from - iterate over list of given type
452 * continuing from existing point
453 * @pos: the type * to use as a loop counter.
454 * @head: the head for your list.
455 * @member: the name of the list_struct within the struct.
457 #define list_for_each_entry_from(pos, head, member) \
458 for (; prefetch(pos->member.next), &pos->member != (head); \
459 pos = list_entry(pos->member.next, typeof(*pos), member))
462 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
463 * @pos: the type * to use as a loop counter.
464 * @n: another type * to use as temporary storage
465 * @head: the head for your list.
466 * @member: the name of the list_struct within the struct.
468 #define list_for_each_entry_safe(pos, n, head, member) \
469 for (pos = list_entry((head)->next, typeof(*pos), member), \
470 n = list_entry(pos->member.next, typeof(*pos), member); \
471 &pos->member != (head); \
472 pos = n, n = list_entry(n->member.next, typeof(*n), member))
475 * list_for_each_entry_safe_continue - iterate over list of given type
476 * continuing after existing point safe against removal of list entry
477 * @pos: the type * to use as a loop counter.
478 * @n: another type * to use as temporary storage
479 * @head: the head for your list.
480 * @member: the name of the list_struct within the struct.
482 #define list_for_each_entry_safe_continue(pos, n, head, member) \
483 for (pos = list_entry(pos->member.next, typeof(*pos), member), \
484 n = list_entry(pos->member.next, typeof(*pos), member); \
485 &pos->member != (head); \
486 pos = n, n = list_entry(n->member.next, typeof(*n), member))
489 * list_for_each_entry_safe_from - iterate over list of given type
490 * from existing point safe against removal of list entry
491 * @pos: the type * to use as a loop counter.
492 * @n: another type * to use as temporary storage
493 * @head: the head for your list.
494 * @member: the name of the list_struct within the struct.
496 #define list_for_each_entry_safe_from(pos, n, head, member) \
497 for (n = list_entry(pos->member.next, typeof(*pos), member); \
498 &pos->member != (head); \
499 pos = n, n = list_entry(n->member.next, typeof(*n), member))
502 * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against
503 * removal of list entry
504 * @pos: the type * to use as a loop counter.
505 * @n: another type * to use as temporary storage
506 * @head: the head for your list.
507 * @member: the name of the list_struct within the struct.
509 #define list_for_each_entry_safe_reverse(pos, n, head, member) \
510 for (pos = list_entry((head)->prev, typeof(*pos), member), \
511 n = list_entry(pos->member.prev, typeof(*pos), member); \
512 &pos->member != (head); \
513 pos = n, n = list_entry(n->member.prev, typeof(*n), member))
516 * list_for_each_rcu - iterate over an rcu-protected list
517 * @pos: the &struct list_head to use as a loop counter.
518 * @head: the head for your list.
520 * This list-traversal primitive may safely run concurrently with
521 * the _rcu list-mutation primitives such as list_add_rcu()
522 * as long as the traversal is guarded by rcu_read_lock().
524 #define list_for_each_rcu(pos, head) \
525 for (pos = (head)->next; \
526 prefetch(rcu_dereference(pos)->next), pos != (head); \
527 pos = pos->next)
529 #define __list_for_each_rcu(pos, head) \
530 for (pos = (head)->next; \
531 rcu_dereference(pos) != (head); \
532 pos = pos->next)
535 * list_for_each_safe_rcu - iterate over an rcu-protected list safe
536 * against removal of list entry
537 * @pos: the &struct list_head to use as a loop counter.
538 * @n: another &struct list_head to use as temporary storage
539 * @head: the head for your list.
541 * This list-traversal primitive may safely run concurrently with
542 * the _rcu list-mutation primitives such as list_add_rcu()
543 * as long as the traversal is guarded by rcu_read_lock().
545 #define list_for_each_safe_rcu(pos, n, head) \
546 for (pos = (head)->next; \
547 n = rcu_dereference(pos)->next, pos != (head); \
548 pos = n)
551 * list_for_each_entry_rcu - iterate over rcu list of given type
552 * @pos: the type * to use as a loop counter.
553 * @head: the head for your list.
554 * @member: the name of the list_struct within the struct.
556 * This list-traversal primitive may safely run concurrently with
557 * the _rcu list-mutation primitives such as list_add_rcu()
558 * as long as the traversal is guarded by rcu_read_lock().
560 #define list_for_each_entry_rcu(pos, head, member) \
561 for (pos = list_entry((head)->next, typeof(*pos), member); \
562 prefetch(rcu_dereference(pos)->member.next), \
563 &pos->member != (head); \
564 pos = list_entry(pos->member.next, typeof(*pos), member))
568 * list_for_each_continue_rcu - iterate over an rcu-protected list
569 * continuing after existing point.
570 * @pos: the &struct list_head to use as a loop counter.
571 * @head: the head for your list.
573 * This list-traversal primitive may safely run concurrently with
574 * the _rcu list-mutation primitives such as list_add_rcu()
575 * as long as the traversal is guarded by rcu_read_lock().
577 #define list_for_each_continue_rcu(pos, head) \
578 for ((pos) = (pos)->next; \
579 prefetch(rcu_dereference((pos))->next), (pos) != (head); \
580 (pos) = (pos)->next)
583 * Double linked lists with a single pointer list head.
584 * Mostly useful for hash tables where the two pointer list head is
585 * too wasteful.
586 * You lose the ability to access the tail in O(1).
589 struct hlist_head {
590 struct hlist_node *first;
593 struct hlist_node {
594 struct hlist_node *next, **pprev;
597 #define HLIST_HEAD_INIT { .first = NULL }
598 #define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
599 #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
600 static inline void INIT_HLIST_NODE(struct hlist_node *h)
602 h->next = NULL;
603 h->pprev = NULL;
606 static inline int hlist_unhashed(const struct hlist_node *h)
608 return !h->pprev;
611 static inline int hlist_empty(const struct hlist_head *h)
613 return !h->first;
616 static inline void __hlist_del(struct hlist_node *n)
618 struct hlist_node *next = n->next;
619 struct hlist_node **pprev = n->pprev;
620 *pprev = next;
621 if (next)
622 next->pprev = pprev;
625 static inline void hlist_del(struct hlist_node *n)
627 __hlist_del(n);
628 n->next = LIST_POISON1;
629 n->pprev = LIST_POISON2;
633 * hlist_del_rcu - deletes entry from hash list without re-initialization
634 * @n: the element to delete from the hash list.
636 * Note: list_unhashed() on entry does not return true after this,
637 * the entry is in an undefined state. It is useful for RCU based
638 * lockfree traversal.
640 * In particular, it means that we can not poison the forward
641 * pointers that may still be used for walking the hash list.
643 * The caller must take whatever precautions are necessary
644 * (such as holding appropriate locks) to avoid racing
645 * with another list-mutation primitive, such as hlist_add_head_rcu()
646 * or hlist_del_rcu(), running on this same list.
647 * However, it is perfectly legal to run concurrently with
648 * the _rcu list-traversal primitives, such as
649 * hlist_for_each_entry().
651 static inline void hlist_del_rcu(struct hlist_node *n)
653 __hlist_del(n);
654 n->pprev = LIST_POISON2;
657 static inline void hlist_del_init(struct hlist_node *n)
659 if (!hlist_unhashed(n)) {
660 __hlist_del(n);
661 INIT_HLIST_NODE(n);
666 * hlist_replace_rcu - replace old entry by new one
667 * @old : the element to be replaced
668 * @new : the new element to insert
670 * The old entry will be replaced with the new entry atomically.
672 static inline void hlist_replace_rcu(struct hlist_node *old,
673 struct hlist_node *new)
675 struct hlist_node *next = old->next;
677 new->next = next;
678 new->pprev = old->pprev;
679 // smp_wmb();
680 if (next)
681 new->next->pprev = &new->next;
682 *new->pprev = new;
683 old->pprev = LIST_POISON2;
686 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
688 struct hlist_node *first = h->first;
689 n->next = first;
690 if (first)
691 first->pprev = &n->next;
692 h->first = n;
693 n->pprev = &h->first;
698 * hlist_add_head_rcu - adds the specified element to the specified hlist,
699 * while permitting racing traversals.
700 * @n: the element to add to the hash list.
701 * @h: the list to add to.
703 * The caller must take whatever precautions are necessary
704 * (such as holding appropriate locks) to avoid racing
705 * with another list-mutation primitive, such as hlist_add_head_rcu()
706 * or hlist_del_rcu(), running on this same list.
707 * However, it is perfectly legal to run concurrently with
708 * the _rcu list-traversal primitives, such as
709 * hlist_for_each_entry_rcu(), used to prevent memory-consistency
710 * problems on Alpha CPUs. Regardless of the type of CPU, the
711 * list-traversal primitive must be guarded by rcu_read_lock().
713 static inline void hlist_add_head_rcu(struct hlist_node *n,
714 struct hlist_head *h)
716 struct hlist_node *first = h->first;
717 n->next = first;
718 n->pprev = &h->first;
719 // smp_wmb();
720 if (first)
721 first->pprev = &n->next;
722 h->first = n;
725 /* next must be != NULL */
726 static inline void hlist_add_before(struct hlist_node *n,
727 struct hlist_node *next)
729 n->pprev = next->pprev;
730 n->next = next;
731 next->pprev = &n->next;
732 *(n->pprev) = n;
735 static inline void hlist_add_after(struct hlist_node *n,
736 struct hlist_node *next)
738 next->next = n->next;
739 n->next = next;
740 next->pprev = &n->next;
742 if(next->next)
743 next->next->pprev = &next->next;
747 * hlist_add_before_rcu - adds the specified element to the specified hlist
748 * before the specified node while permitting racing traversals.
749 * @n: the new element to add to the hash list.
750 * @next: the existing element to add the new element before.
752 * The caller must take whatever precautions are necessary
753 * (such as holding appropriate locks) to avoid racing
754 * with another list-mutation primitive, such as hlist_add_head_rcu()
755 * or hlist_del_rcu(), running on this same list.
756 * However, it is perfectly legal to run concurrently with
757 * the _rcu list-traversal primitives, such as
758 * hlist_for_each_entry_rcu(), used to prevent memory-consistency
759 * problems on Alpha CPUs.
761 static inline void hlist_add_before_rcu(struct hlist_node *n,
762 struct hlist_node *next)
764 n->pprev = next->pprev;
765 n->next = next;
766 // smp_wmb();
767 next->pprev = &n->next;
768 *(n->pprev) = n;
772 * hlist_add_after_rcu - adds the specified element to the specified hlist
773 * after the specified node while permitting racing traversals.
774 * @prev: the existing element to add the new element after.
775 * @n: the new element to add to the hash list.
777 * The caller must take whatever precautions are necessary
778 * (such as holding appropriate locks) to avoid racing
779 * with another list-mutation primitive, such as hlist_add_head_rcu()
780 * or hlist_del_rcu(), running on this same list.
781 * However, it is perfectly legal to run concurrently with
782 * the _rcu list-traversal primitives, such as
783 * hlist_for_each_entry_rcu(), used to prevent memory-consistency
784 * problems on Alpha CPUs.
786 static inline void hlist_add_after_rcu(struct hlist_node *prev,
787 struct hlist_node *n)
789 n->next = prev->next;
790 n->pprev = &prev->next;
791 // smp_wmb();
792 prev->next = n;
793 if (n->next)
794 n->next->pprev = &n->next;
797 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
799 #define hlist_for_each(pos, head) \
800 for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
801 pos = pos->next)
803 #define hlist_for_each_safe(pos, n, head) \
804 for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
805 pos = n)
808 * hlist_for_each_entry - iterate over list of given type
809 * @tpos: the type * to use as a loop counter.
810 * @pos: the &struct hlist_node to use as a loop counter.
811 * @head: the head for your list.
812 * @member: the name of the hlist_node within the struct.
814 #define hlist_for_each_entry(tpos, pos, head, member) \
815 for (pos = (head)->first; \
816 pos && ({ prefetch(pos->next); 1;}) && \
817 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
818 pos = pos->next)
821 * hlist_for_each_entry_continue - iterate over a hlist continuing after existing point
822 * @tpos: the type * to use as a loop counter.
823 * @pos: the &struct hlist_node to use as a loop counter.
824 * @member: the name of the hlist_node within the struct.
826 #define hlist_for_each_entry_continue(tpos, pos, member) \
827 for (pos = (pos)->next; \
828 pos && ({ prefetch(pos->next); 1;}) && \
829 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
830 pos = pos->next)
833 * hlist_for_each_entry_from - iterate over a hlist continuing from existing point
834 * @tpos: the type * to use as a loop counter.
835 * @pos: the &struct hlist_node to use as a loop counter.
836 * @member: the name of the hlist_node within the struct.
838 #define hlist_for_each_entry_from(tpos, pos, member) \
839 for (; pos && ({ prefetch(pos->next); 1;}) && \
840 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
841 pos = pos->next)
844 * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
845 * @tpos: the type * to use as a loop counter.
846 * @pos: the &struct hlist_node to use as a loop counter.
847 * @n: another &struct hlist_node to use as temporary storage
848 * @head: the head for your list.
849 * @member: the name of the hlist_node within the struct.
851 #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
852 for (pos = (head)->first; \
853 pos && ({ n = pos->next; 1; }) && \
854 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
855 pos = n)
858 * hlist_for_each_entry_rcu - iterate over rcu list of given type
859 * @tpos: the type * to use as a loop counter.
860 * @pos: the &struct hlist_node to use as a loop counter.
861 * @head: the head for your list.
862 * @member: the name of the hlist_node within the struct.
864 * This list-traversal primitive may safely run concurrently with
865 * the _rcu list-mutation primitives such as hlist_add_head_rcu()
866 * as long as the traversal is guarded by rcu_read_lock().
868 #define hlist_for_each_entry_rcu(tpos, pos, head, member) \
869 for (pos = (head)->first; \
870 rcu_dereference(pos) && ({ prefetch(pos->next); 1;}) && \
871 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
872 pos = pos->next)
874 #endif