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