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