6#define container_of(ptr, type, member) ({ \
7 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
8 (type *)( (char *)__mptr - offsetof(type,member) ); })
15static inline void list_init(
struct list_head *list)
26 node->prev = list->prev;
31static inline int list_empty(
struct list_head *list)
33 return list == list->next;
42static inline void list_remove(
struct list_head *node)
44 list_join(node->prev, node->next);
49static inline int list_node_is_last(
struct list_head *list)
51 return list->next == list->prev;
56 return node1 == node2;
59#define list_first_entry(ptr, type, member) \
60 container_of((ptr)->next, type, member)
62#define list_next_entry(pos, member) \
63 container_of((pos)->member.next, typeof(*(pos)), member)
65#define list_entry_is_head(pos, head, member) \
66 (&(pos)->member == (head))
68#define list_for_each_it(var, list) \
69 for ((var) = (list)->next; \
70 !list_same_node((var), list); \
73#define list_for_each(var, head, member) \
74 for ((var) = list_first_entry(head, typeof(*(var)), member); \
75 !list_entry_is_head(var, head, member); \
76 (var) = list_next_entry(var, member))
78#define list_for_each_safe_it(var, n, list) \
79 for ((var) = (list)->next, (n) = (var)->next; \
80 !list_same_node((var), list); \
81 (var) = (n), (n) = (var)->next)
83#define list_for_each_safe(var, head, member) \
84 typeof((var)) var##__safe; \
85 for ((var) = list_first_entry(head, typeof(*(var)), member), \
86 (var##__safe) = list_next_entry(var, member); \
87 !list_entry_is_head(var, head, member); \
88 (var) = (var##__safe), (var##__safe) = list_next_entry(var##__safe, member))
90static inline int list_length(
struct list_head *list)
95 list_for_each_it(i, list)