Home | History | Annotate | Download | only in include
      1 #ifndef __HLIST_H__
      2 #define __HLIST_H__ 1
      3 /* Hash list stuff from kernel */
      4 
      5 #include <stddef.h>
      6 
      7 #define container_of(ptr, type, member) ({			\
      8 	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
      9 	(type *)( (char *)__mptr - offsetof(type,member) );})
     10 
     11 struct hlist_head {
     12 	struct hlist_node *first;
     13 };
     14 
     15 struct hlist_node {
     16 	struct hlist_node *next, **pprev;
     17 };
     18 
     19 static inline void hlist_del(struct hlist_node *n)
     20 {
     21 	struct hlist_node *next = n->next;
     22 	struct hlist_node **pprev = n->pprev;
     23 	*pprev = next;
     24 	if (next)
     25 		next->pprev = pprev;
     26 }
     27 
     28 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
     29 {
     30 	struct hlist_node *first = h->first;
     31 	n->next = first;
     32 	if (first)
     33 		first->pprev = &n->next;
     34 	h->first = n;
     35 	n->pprev = &h->first;
     36 }
     37 
     38 #define hlist_for_each(pos, head) \
     39 	for (pos = (head)->first; pos ; pos = pos->next)
     40 
     41 
     42 #define hlist_for_each_safe(pos, n, head) \
     43 	for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
     44 	     pos = n)
     45 
     46 #define hlist_entry_safe(ptr, type, member) \
     47 	({ typeof(ptr) ____ptr = (ptr); \
     48 	   ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
     49 	})
     50 
     51 #define hlist_for_each_entry(pos, head, member)				\
     52 	for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
     53 	     pos;							\
     54 	     pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
     55 
     56 #endif /* __HLIST_H__ */
     57