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