6 #ifndef NETLINK_LIST_H_
7 #define NETLINK_LIST_H_
17 static inline void NL_INIT_LIST_HEAD(
struct nl_list_head *list)
23 static inline void __nl_list_add(
struct nl_list_head *obj,
33 static inline void nl_list_add_tail(
struct nl_list_head *obj,
36 __nl_list_add(obj, head->prev, head);
39 static inline void nl_list_add_head(
struct nl_list_head *obj,
42 __nl_list_add(obj, head, head->next);
47 obj->next->prev = obj->prev;
48 obj->prev->next = obj->next;
51 static inline int nl_list_empty(
struct nl_list_head *head)
53 return head->next == head;
56 #define nl_container_of(ptr, type, member) ({ \
57 const __typeof__( ((type *)0)->member ) *__mptr = (ptr);\
58 (type *)( (char *)__mptr - (offsetof(type, member)));})
60 #define nl_list_entry(ptr, type, member) \
61 nl_container_of(ptr, type, member)
63 #define nl_list_at_tail(pos, head, member) \
64 ((pos)->member.next == (head))
66 #define nl_list_at_head(pos, head, member) \
67 ((pos)->member.prev == (head))
69 #define NL_LIST_HEAD(name) \
70 struct nl_list_head name = { &(name), &(name) }
72 #define nl_list_first_entry(head, type, member) \
73 nl_list_entry((head)->next, type, member)
75 #define nl_list_for_each_entry(pos, head, member) \
76 for (pos = nl_list_entry((head)->next, __typeof__(*pos), member); \
77 &(pos)->member != (head); \
78 (pos) = nl_list_entry((pos)->member.next, __typeof__(*(pos)), member))
80 #define nl_list_for_each_entry_safe(pos, n, head, member) \
81 for (pos = nl_list_entry((head)->next, __typeof__(*pos), member), \
82 n = nl_list_entry(pos->member.next, __typeof__(*pos), member); \
83 &(pos)->member != (head); \
84 pos = n, n = nl_list_entry(n->member.next, __typeof__(*n), member))
86 #define nl_init_list_head(head) \
87 do { (head)->next = (head); (head)->prev = (head); } while (0)