Whamcloud - gitweb
b7478049570de53c1699faf3222b49cad9ccbf58
[fs/lustre-release.git] / libcfs / include / libcfs / list.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License version 2 for more details.  A copy is
14  * included in the COPYING file that accompanied this code.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * GPL HEADER END
21  */
22
23 #ifndef __LIBCFS_LIST_H__
24 #define __LIBCFS_LIST_H__
25
26 #if defined (__linux__) && defined(__KERNEL__)
27
28 #include <linux/list.h>
29
30 typedef struct list_head cfs_list_t;
31
32 #define __cfs_list_add(new, prev, next)      __list_add(new, prev, next)
33 #define cfs_list_add(new, head)              list_add(new, head)
34
35 #define cfs_list_add_tail(new, head)         list_add_tail(new, head)
36
37 #define __cfs_list_del(prev, next)           __list_del(prev, next)
38 #define cfs_list_del(entry)                  list_del(entry)
39 #define cfs_list_del_init(entry)             list_del_init(entry)
40
41 #define cfs_list_move(list, head)            list_move(list, head)
42 #define cfs_list_move_tail(list, head)       list_move_tail(list, head)
43
44 #define cfs_list_empty(head)                 list_empty(head)
45 #define cfs_list_empty_careful(head)         list_empty_careful(head)
46
47 #define __cfs_list_splice(list, head)        __list_splice(list, head)
48 #define cfs_list_splice(list, head)          list_splice(list, head)
49
50 #define cfs_list_splice_init(list, head)     list_splice_init(list, head)
51
52 #define cfs_list_entry(ptr, type, member)    list_entry(ptr, type, member)
53 #define cfs_list_for_each(pos, head)         list_for_each(pos, head)
54 #define cfs_list_for_each_safe(pos, n, head) list_for_each_safe(pos, n, head)
55 #define cfs_list_for_each_prev(pos, head)    list_for_each_prev(pos, head)
56 #define cfs_list_for_each_entry(pos, head, member) \
57         list_for_each_entry(pos, head, member)
58 #define cfs_list_for_each_entry_reverse(pos, head, member) \
59         list_for_each_entry_reverse(pos, head, member)
60 #define cfs_list_for_each_entry_safe_reverse(pos, n, head, member) \
61         list_for_each_entry_safe_reverse(pos, n, head, member)
62 #define cfs_list_for_each_entry_safe(pos, n, head, member) \
63         list_for_each_entry_safe(pos, n, head, member)
64 #ifdef list_for_each_entry_safe_from
65 #define cfs_list_for_each_entry_safe_from(pos, n, head, member) \
66         list_for_each_entry_safe_from(pos, n, head, member)
67 #endif /* list_for_each_entry_safe_from */
68 #define cfs_list_for_each_entry_continue(pos, head, member) \
69         list_for_each_entry_continue(pos, head, member)
70
71 #define CFS_LIST_HEAD_INIT(n)                LIST_HEAD_INIT(n)
72 #define CFS_LIST_HEAD(n)                     LIST_HEAD(n)
73 #define CFS_INIT_LIST_HEAD(p)                INIT_LIST_HEAD(p)
74
75 typedef struct hlist_head cfs_hlist_head_t;
76 typedef struct hlist_node cfs_hlist_node_t;
77
78 #define cfs_hlist_unhashed(h)              hlist_unhashed(h)
79
80 #define cfs_hlist_empty(h)                 hlist_empty(h)
81
82 #define __cfs_hlist_del(n)                 __hlist_del(n)
83 #define cfs_hlist_del(n)                   hlist_del(n)
84 #define cfs_hlist_del_init(n)              hlist_del_init(n)
85
86 #define cfs_hlist_add_head(n, next)        hlist_add_head(n, next)
87 #define cfs_hlist_add_before(n, next)      hlist_add_before(n, next)
88 #define cfs_hlist_add_after(n, next)       hlist_add_after(n, next)
89
90 #define cfs_hlist_entry(ptr, type, member) hlist_entry(ptr, type, member)
91 #define cfs_hlist_for_each(pos, head)      hlist_for_each(pos, head)
92 #define cfs_hlist_for_each_safe(pos, n, head) \
93         hlist_for_each_safe(pos, n, head)
94 #ifdef HAVE_HLIST_FOR_EACH_3ARG
95 #define cfs_hlist_for_each_entry(tpos, pos, head, member) \
96         pos = NULL; hlist_for_each_entry(tpos, head, member)
97 #else
98 #define cfs_hlist_for_each_entry(tpos, pos, head, member) \
99         hlist_for_each_entry(tpos, pos, head, member)
100 #endif
101 #define cfs_hlist_for_each_entry_continue(tpos, pos, member) \
102         hlist_for_each_entry_continue(tpos, pos, member)
103 #define cfs_hlist_for_each_entry_from(tpos, pos, member) \
104         hlist_for_each_entry_from(tpos, pos, member)
105 #ifdef HAVE_HLIST_FOR_EACH_3ARG
106 #define cfs_hlist_for_each_entry_safe(tpos, pos, n, head, member) \
107         pos = NULL; hlist_for_each_entry_safe(tpos, n, head, member)
108 #else
109 #define cfs_hlist_for_each_entry_safe(tpos, pos, n, head, member) \
110         hlist_for_each_entry_safe(tpos, pos, n, head, member)
111 #endif
112
113 #define CFS_HLIST_HEAD_INIT                HLIST_HEAD_INIT
114 #define CFS_HLIST_HEAD(n)                  HLIST_HEAD(n)
115 #define CFS_INIT_HLIST_HEAD(p)             INIT_HLIST_HEAD(p)
116 #define CFS_INIT_HLIST_NODE(p)             INIT_HLIST_NODE(p)
117
118 #else /* !defined (__linux__) || !defined(__KERNEL__) */
119
120 /*
121  * Simple doubly linked list implementation.
122  *
123  * Some of the internal functions ("__xxx") are useful when
124  * manipulating whole lists rather than single entries, as
125  * sometimes we already know the next/prev entries and we can
126  * generate better code by using them directly rather than
127  * using the generic single-entry routines.
128  */
129
130 #define prefetch(a) ((void)a)
131
132 struct cfs_list_head {
133         struct cfs_list_head *next, *prev;
134 };
135
136 typedef struct cfs_list_head cfs_list_t;
137
138 #define CFS_LIST_HEAD_INIT(name) { &(name), &(name) }
139
140 #define CFS_LIST_HEAD(name) \
141         cfs_list_t name = CFS_LIST_HEAD_INIT(name)
142
143 #define CFS_INIT_LIST_HEAD(ptr) do { \
144         (ptr)->next = (ptr); (ptr)->prev = (ptr); \
145 } while (0)
146
147 /**
148  * Insert a new entry between two known consecutive entries.
149  *
150  * This is only for internal list manipulation where we know
151  * the prev/next entries already!
152  */
153 static inline void __cfs_list_add(cfs_list_t * new,
154                                   cfs_list_t * prev,
155                                   cfs_list_t * next)
156 {
157         next->prev = new;
158         new->next = next;
159         new->prev = prev;
160         prev->next = new;
161 }
162
163 /**
164  * Insert an entry at the start of a list.
165  * \param new  new entry to be inserted
166  * \param head list to add it to
167  *
168  * Insert a new entry after the specified head.
169  * This is good for implementing stacks.
170  */
171 static inline void cfs_list_add(cfs_list_t *new,
172                                 cfs_list_t *head)
173 {
174         __cfs_list_add(new, head, head->next);
175 }
176
177 /**
178  * Insert an entry at the end of a list.
179  * \param new  new entry to be inserted
180  * \param head list to add it to
181  *
182  * Insert a new entry before the specified head.
183  * This is useful for implementing queues.
184  */
185 static inline void cfs_list_add_tail(cfs_list_t *new,
186                                      cfs_list_t *head)
187 {
188         __cfs_list_add(new, head->prev, head);
189 }
190
191 /*
192  * Delete a list entry by making the prev/next entries
193  * point to each other.
194  *
195  * This is only for internal list manipulation where we know
196  * the prev/next entries already!
197  */
198 static inline void __cfs_list_del(cfs_list_t *prev,
199                                   cfs_list_t *next)
200 {
201         next->prev = prev;
202         prev->next = next;
203 }
204
205 /**
206  * Remove an entry from the list it is currently in.
207  * \param entry the entry to remove
208  * Note: list_empty(entry) does not return true after this, the entry is in an
209  * undefined state.
210  */
211 static inline void cfs_list_del(cfs_list_t *entry)
212 {
213         __cfs_list_del(entry->prev, entry->next);
214 }
215
216 /**
217  * Remove an entry from the list it is currently in and reinitialize it.
218  * \param entry the entry to remove.
219  */
220 static inline void cfs_list_del_init(cfs_list_t *entry)
221 {
222         __cfs_list_del(entry->prev, entry->next);
223         CFS_INIT_LIST_HEAD(entry);
224 }
225
226 /**
227  * Remove an entry from the list it is currently in and insert it at the start
228  * of another list.
229  * \param list the entry to move
230  * \param head the list to move it to
231  */
232 static inline void cfs_list_move(cfs_list_t *list,
233                                  cfs_list_t *head)
234 {
235         __cfs_list_del(list->prev, list->next);
236         cfs_list_add(list, head);
237 }
238
239 /**
240  * Remove an entry from the list it is currently in and insert it at the end of
241  * another list.
242  * \param list the entry to move
243  * \param head the list to move it to
244  */
245 static inline void cfs_list_move_tail(cfs_list_t *list,
246                                       cfs_list_t *head)
247 {
248         __cfs_list_del(list->prev, list->next);
249         cfs_list_add_tail(list, head);
250 }
251
252 /**
253  * Test whether a list is empty
254  * \param head the list to test.
255  */
256 static inline int cfs_list_empty(cfs_list_t *head)
257 {
258         return head->next == head;
259 }
260
261 /**
262  * Test whether a list is empty and not being modified
263  * \param head the list to test
264  *
265  * Tests whether a list is empty _and_ checks that no other CPU might be
266  * in the process of modifying either member (next or prev)
267  *
268  * NOTE: using cfs_list_empty_careful() without synchronization
269  * can only be safe if the only activity that can happen
270  * to the list entry is cfs_list_del_init(). Eg. it cannot be used
271  * if another CPU could re-list_add() it.
272  */
273 static inline int cfs_list_empty_careful(const cfs_list_t *head)
274 {
275         cfs_list_t *next = head->next;
276         return (next == head) && (next == head->prev);
277 }
278
279 static inline void __cfs_list_splice(cfs_list_t *list,
280                                      cfs_list_t *head)
281 {
282         cfs_list_t *first = list->next;
283         cfs_list_t *last = list->prev;
284         cfs_list_t *at = head->next;
285
286         first->prev = head;
287         head->next = first;
288
289         last->next = at;
290         at->prev = last;
291 }
292
293 /**
294  * Join two lists
295  * \param list the new list to add.
296  * \param head the place to add it in the first list.
297  *
298  * The contents of \a list are added at the start of \a head.  \a list is in an
299  * undefined state on return.
300  */
301 static inline void cfs_list_splice(cfs_list_t *list,
302                                    cfs_list_t *head)
303 {
304         if (!cfs_list_empty(list))
305                 __cfs_list_splice(list, head);
306 }
307
308 /**
309  * Join two lists and reinitialise the emptied list.
310  * \param list the new list to add.
311  * \param head the place to add it in the first list.
312  *
313  * The contents of \a list are added at the start of \a head.  \a list is empty
314  * on return.
315  */
316 static inline void cfs_list_splice_init(cfs_list_t *list,
317                                         cfs_list_t *head)
318 {
319         if (!cfs_list_empty(list)) {
320                 __cfs_list_splice(list, head);
321                 CFS_INIT_LIST_HEAD(list);
322         }
323 }
324
325 /**
326  * Get the container of a list
327  * \param ptr    the embedded list.
328  * \param type   the type of the struct this is embedded in.
329  * \param member the member name of the list within the struct.
330  */
331 #define cfs_list_entry(ptr, type, member) \
332         ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
333
334 /**
335  * Iterate over a list
336  * \param pos   the iterator
337  * \param head  the list to iterate over
338  *
339  * Behaviour is undefined if \a pos is removed from the list in the body of the
340  * loop.
341  */
342 #define cfs_list_for_each(pos, head) \
343         for (pos = (head)->next, prefetch(pos->next); pos != (head); \
344                 pos = pos->next, prefetch(pos->next))
345
346 /**
347  * Iterate over a list safely
348  * \param pos   the iterator
349  * \param n     temporary storage
350  * \param head  the list to iterate over
351  *
352  * This is safe to use if \a pos could be removed from the list in the body of
353  * the loop.
354  */
355 #define cfs_list_for_each_safe(pos, n, head) \
356         for (pos = (head)->next, n = pos->next; pos != (head); \
357                 pos = n, n = pos->next)
358
359 /**
360  * Iterate over a list continuing after existing point
361  * \param pos    the type * to use as a loop counter
362  * \param head   the list head
363  * \param member the name of the list_struct within the struct  
364  */
365 #define cfs_list_for_each_entry_continue(pos, head, member)                 \
366         for (pos = cfs_list_entry(pos->member.next, typeof(*pos), member);  \
367              prefetch(pos->member.next), &pos->member != (head);            \
368              pos = cfs_list_entry(pos->member.next, typeof(*pos), member))
369
370 /**
371  * \defgroup hlist Hash List
372  * Double linked lists with a single pointer list head.
373  * Mostly useful for hash tables where the two pointer list head is too
374  * wasteful.  You lose the ability to access the tail in O(1).
375  * @{
376  */
377
378 typedef struct cfs_hlist_node {
379         struct cfs_hlist_node *next, **pprev;
380 } cfs_hlist_node_t;
381
382 typedef struct cfs_hlist_head {
383         cfs_hlist_node_t *first;
384 } cfs_hlist_head_t;
385
386 /* @} */
387
388 /*
389  * "NULL" might not be defined at this point
390  */
391 #ifdef NULL
392 #define NULL_P NULL
393 #else
394 #define NULL_P ((void *)0)
395 #endif
396
397 /**
398  * \addtogroup hlist
399  * @{
400  */
401
402 #define CFS_HLIST_HEAD_INIT { NULL_P }
403 #define CFS_HLIST_HEAD(name) cfs_hlist_head_t name = { NULL_P }
404 #define CFS_INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL_P)
405 #define CFS_INIT_HLIST_NODE(ptr) ((ptr)->next = NULL_P, (ptr)->pprev = NULL_P)
406
407 static inline int cfs_hlist_unhashed(const cfs_hlist_node_t *h)
408 {
409         return !h->pprev;
410 }
411
412 static inline int cfs_hlist_empty(const cfs_hlist_head_t *h)
413 {
414         return !h->first;
415 }
416
417 static inline void __cfs_hlist_del(cfs_hlist_node_t *n)
418 {
419         cfs_hlist_node_t *next = n->next;
420         cfs_hlist_node_t **pprev = n->pprev;
421         *pprev = next;
422         if (next)
423                 next->pprev = pprev;
424 }
425
426 static inline void cfs_hlist_del(cfs_hlist_node_t *n)
427 {
428         __cfs_hlist_del(n);
429 }
430
431 static inline void cfs_hlist_del_init(cfs_hlist_node_t *n)
432 {
433         if (n->pprev)  {
434                 __cfs_hlist_del(n);
435                 CFS_INIT_HLIST_NODE(n);
436         }
437 }
438
439 static inline void cfs_hlist_add_head(cfs_hlist_node_t *n,
440                                       cfs_hlist_head_t *h)
441 {
442         cfs_hlist_node_t *first = h->first;
443         n->next = first;
444         if (first)
445                 first->pprev = &n->next;
446         h->first = n;
447         n->pprev = &h->first;
448 }
449
450 /* next must be != NULL */
451 static inline void cfs_hlist_add_before(cfs_hlist_node_t *n,
452                                         cfs_hlist_node_t *next)
453 {
454         n->pprev = next->pprev;
455         n->next = next;
456         next->pprev = &n->next;
457         *(n->pprev) = n;
458 }
459
460 static inline void cfs_hlist_add_after(cfs_hlist_node_t *n,
461                                        cfs_hlist_node_t *next)
462 {
463         next->next = n->next;
464         n->next = next;
465         next->pprev = &n->next;
466
467         if(next->next)
468                 next->next->pprev  = &next->next;
469 }
470
471 #define cfs_hlist_entry(ptr, type, member) container_of(ptr,type,member)
472
473 #define cfs_hlist_for_each(pos, head) \
474         for (pos = (head)->first; pos && (prefetch(pos->next), 1); \
475              pos = pos->next)
476
477 #define cfs_hlist_for_each_safe(pos, n, head) \
478         for (pos = (head)->first; pos && (n = pos->next, 1); \
479              pos = n)
480
481 /**
482  * Iterate over an hlist of given type
483  * \param tpos   the type * to use as a loop counter.
484  * \param pos    the &struct hlist_node to use as a loop counter.
485  * \param head   the head for your list.
486  * \param member the name of the hlist_node within the struct.
487  */
488 #define cfs_hlist_for_each_entry(tpos, pos, head, member)                    \
489         for (pos = (head)->first;                                            \
490              pos && ({ prefetch(pos->next); 1;}) &&                          \
491                 ({ tpos = cfs_hlist_entry(pos, typeof(*tpos), member); 1;}); \
492              pos = pos->next)
493
494 /**
495  * Iterate over an hlist continuing after existing point
496  * \param tpos   the type * to use as a loop counter.
497  * \param pos    the &struct hlist_node to use as a loop counter.
498  * \param member the name of the hlist_node within the struct.
499  */
500 #define cfs_hlist_for_each_entry_continue(tpos, pos, member)                 \
501         for (pos = (pos)->next;                                              \
502              pos && ({ prefetch(pos->next); 1;}) &&                          \
503                 ({ tpos = cfs_hlist_entry(pos, typeof(*tpos), member); 1;}); \
504              pos = pos->next)
505
506 /**
507  * Iterate over an hlist continuing from an existing point
508  * \param tpos   the type * to use as a loop counter.
509  * \param pos    the &struct hlist_node to use as a loop counter.
510  * \param member the name of the hlist_node within the struct.
511  */
512 #define cfs_hlist_for_each_entry_from(tpos, pos, member)                         \
513         for (; pos && ({ prefetch(pos->next); 1;}) &&                        \
514                 ({ tpos = cfs_hlist_entry(pos, typeof(*tpos), member); 1;}); \
515              pos = pos->next)
516
517 /**
518  * Iterate over an hlist of given type safe against removal of list entry
519  * \param tpos   the type * to use as a loop counter.
520  * \param pos    the &struct hlist_node to use as a loop counter.
521  * \param n      another &struct hlist_node to use as temporary storage
522  * \param head   the head for your list.
523  * \param member the name of the hlist_node within the struct.
524  */
525 #define cfs_hlist_for_each_entry_safe(tpos, pos, n, head, member)            \
526         for (pos = (head)->first;                                            \
527              pos && ({ n = pos->next; 1; }) &&                               \
528                 ({ tpos = cfs_hlist_entry(pos, typeof(*tpos), member); 1;}); \
529              pos = n)
530
531 /* @} */
532
533 #endif /* __linux__ && __KERNEL__ */
534
535 #ifndef cfs_list_for_each_prev
536 /**
537  * Iterate over a list in reverse order
538  * \param pos   the &struct list_head to use as a loop counter.
539  * \param head  the head for your list.
540  */
541 #define cfs_list_for_each_prev(pos, head) \
542         for (pos = (head)->prev, prefetch(pos->prev); pos != (head);     \
543                 pos = pos->prev, prefetch(pos->prev))
544
545 #endif /* cfs_list_for_each_prev */
546
547 #ifndef cfs_list_for_each_entry
548 /**
549  * Iterate over a list of given type
550  * \param pos        the type * to use as a loop counter.
551  * \param head       the head for your list.
552  * \param member     the name of the list_struct within the struct.
553  */
554 #define cfs_list_for_each_entry(pos, head, member)                          \
555         for (pos = cfs_list_entry((head)->next, typeof(*pos), member),      \
556                      prefetch(pos->member.next);                            \
557              &pos->member != (head);                                        \
558              pos = cfs_list_entry(pos->member.next, typeof(*pos), member),  \
559              prefetch(pos->member.next))
560 #endif /* cfs_list_for_each_entry */
561
562 #ifndef cfs_list_for_each_entry_rcu
563 #define cfs_list_for_each_entry_rcu(pos, head, member) \
564        list_for_each_entry(pos, head, member)
565 #endif
566
567 #ifndef cfs_list_for_each_entry_rcu
568 #define cfs_list_for_each_entry_rcu(pos, head, member) \
569        list_for_each_entry(pos, head, member)
570 #endif
571
572 #ifndef cfs_list_for_each_entry_reverse
573 /**
574  * Iterate backwards over a list of given type.
575  * \param pos        the type * to use as a loop counter.
576  * \param head       the head for your list.
577  * \param member     the name of the list_struct within the struct.
578  */
579 #define cfs_list_for_each_entry_reverse(pos, head, member)                  \
580         for (pos = cfs_list_entry((head)->prev, typeof(*pos), member);      \
581              prefetch(pos->member.prev), &pos->member != (head);            \
582              pos = cfs_list_entry(pos->member.prev, typeof(*pos), member))
583 #endif /* cfs_list_for_each_entry_reverse */
584
585 #ifndef cfs_list_for_each_entry_safe
586 /**
587  * Iterate over a list of given type safe against removal of list entry
588  * \param pos        the type * to use as a loop counter.
589  * \param n          another type * to use as temporary storage
590  * \param head       the head for your list.
591  * \param member     the name of the list_struct within the struct.
592  */
593 #define cfs_list_for_each_entry_safe(pos, n, head, member)                   \
594         for (pos = cfs_list_entry((head)->next, typeof(*pos), member),       \
595                 n = cfs_list_entry(pos->member.next, typeof(*pos), member);  \
596              &pos->member != (head);                                         \
597              pos = n, n = cfs_list_entry(n->member.next, typeof(*n), member))
598
599 #endif /* cfs_list_for_each_entry_safe */
600
601 #ifndef cfs_list_for_each_entry_safe_from
602 /**
603  * Iterate over a list continuing from an existing point
604  * \param pos        the type * to use as a loop cursor.
605  * \param n          another type * to use as temporary storage
606  * \param head       the head for your list.
607  * \param member     the name of the list_struct within the struct.
608  *
609  * Iterate over list of given type from current point, safe against
610  * removal of list entry.
611  */
612 #define cfs_list_for_each_entry_safe_from(pos, n, head, member)             \
613         for (n = cfs_list_entry(pos->member.next, typeof(*pos), member);    \
614              &pos->member != (head);                                        \
615              pos = n, n = cfs_list_entry(n->member.next, typeof(*n), member))
616 #endif /* cfs_list_for_each_entry_safe_from */
617
618 #define cfs_list_for_each_entry_typed(pos, head, type, member)          \
619         for (pos = cfs_list_entry((head)->next, type, member),          \
620                      prefetch(pos->member.next);                        \
621              &pos->member != (head);                                    \
622              pos = cfs_list_entry(pos->member.next, type, member),      \
623              prefetch(pos->member.next))
624
625 #define cfs_list_for_each_entry_reverse_typed(pos, head, type, member)  \
626         for (pos = cfs_list_entry((head)->prev, type, member);          \
627              prefetch(pos->member.prev), &pos->member != (head);        \
628              pos = cfs_list_entry(pos->member.prev, type, member))
629
630 #define cfs_list_for_each_entry_safe_typed(pos, n, head, type, member)  \
631     for (pos = cfs_list_entry((head)->next, type, member),              \
632                 n = cfs_list_entry(pos->member.next, type, member);     \
633              &pos->member != (head);                                    \
634              pos = n, n = cfs_list_entry(n->member.next, type, member))
635
636 #define cfs_list_for_each_entry_safe_from_typed(pos, n, head, type, member)  \
637         for (n = cfs_list_entry(pos->member.next, type, member);             \
638              &pos->member != (head);                                         \
639              pos = n, n = cfs_list_entry(n->member.next, type, member))
640
641 #define cfs_hlist_for_each_entry_typed(tpos, pos, head, type, member)   \
642         for (pos = (head)->first;                                       \
643              pos && (prefetch(pos->next), 1) &&                         \
644                 (tpos = cfs_hlist_entry(pos, type, member), 1);         \
645              pos = pos->next)
646
647 #define cfs_hlist_for_each_entry_safe_typed(tpos, pos, n, head, type, member) \
648         for (pos = (head)->first;                                             \
649              pos && (n = pos->next, 1) &&                                     \
650                 (tpos = cfs_hlist_entry(pos, type, member), 1);               \
651              pos = n)
652
653 #endif /* __LIBCFS_LUSTRE_LIST_H__ */