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