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