]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/list_nulls.h
1 #ifndef _LINUX_LIST_NULLS_H
2 #define _LINUX_LIST_NULLS_H
4 #include <linux/poison.h>
5 #include <linux/const.h>
8 * Special version of lists, where end of list is not a NULL pointer,
9 * but a 'nulls' marker, which can have many different values.
10 * (up to 2^31 different values guaranteed on all platforms)
12 * In the standard hlist, termination of a list is the NULL pointer.
13 * In this special 'nulls' variant, we use the fact that objects stored in
14 * a list are aligned on a word (4 or 8 bytes alignment).
15 * We therefore use the last significant bit of 'ptr' :
16 * Set to 1 : This is a 'nulls' end-of-list marker (ptr >> 1)
17 * Set to 0 : This is a pointer to some object (ptr)
20 struct hlist_nulls_head
{
21 struct hlist_nulls_node
*first
;
24 struct hlist_nulls_node
{
25 struct hlist_nulls_node
*next
, **pprev
;
27 #define NULLS_MARKER(value) (1UL | (((long)value) << 1))
28 #define INIT_HLIST_NULLS_HEAD(ptr, nulls) \
29 ((ptr)->first = (struct hlist_nulls_node *) NULLS_MARKER(nulls))
31 #define hlist_nulls_entry(ptr, type, member) container_of(ptr,type,member)
33 * ptr_is_a_nulls - Test if a ptr is a nulls
34 * @ptr: ptr to be tested
37 static inline int is_a_nulls(const struct hlist_nulls_node
*ptr
)
39 return ((unsigned long)ptr
& 1);
43 * get_nulls_value - Get the 'nulls' value of the end of chain
46 * Should be called only if is_a_nulls(ptr);
48 static inline unsigned long get_nulls_value(const struct hlist_nulls_node
*ptr
)
50 return ((unsigned long)ptr
) >> 1;
53 static inline int hlist_nulls_unhashed(const struct hlist_nulls_node
*h
)
58 static inline int hlist_nulls_empty(const struct hlist_nulls_head
*h
)
60 return is_a_nulls(h
->first
);
63 static inline void hlist_nulls_add_head(struct hlist_nulls_node
*n
,
64 struct hlist_nulls_head
*h
)
66 struct hlist_nulls_node
*first
= h
->first
;
71 if (!is_a_nulls(first
))
72 first
->pprev
= &n
->next
;
75 static inline void __hlist_nulls_del(struct hlist_nulls_node
*n
)
77 struct hlist_nulls_node
*next
= n
->next
;
78 struct hlist_nulls_node
**pprev
= n
->pprev
;
80 if (!is_a_nulls(next
))
84 static inline void hlist_nulls_del(struct hlist_nulls_node
*n
)
87 n
->pprev
= LIST_POISON2
;
91 * hlist_nulls_for_each_entry - iterate over list of given type
92 * @tpos: the type * to use as a loop cursor.
93 * @pos: the &struct hlist_node to use as a loop cursor.
94 * @head: the head for your list.
95 * @member: the name of the hlist_node within the struct.
98 #define hlist_nulls_for_each_entry(tpos, pos, head, member) \
99 for (pos = (head)->first; \
100 (!is_a_nulls(pos)) && \
101 ({ tpos = hlist_nulls_entry(pos, typeof(*tpos), member); 1;}); \
105 * hlist_nulls_for_each_entry_from - iterate over a hlist continuing from current point
106 * @tpos: the type * to use as a loop cursor.
107 * @pos: the &struct hlist_node to use as a loop cursor.
108 * @member: the name of the hlist_node within the struct.
111 #define hlist_nulls_for_each_entry_from(tpos, pos, member) \
112 for (; (!is_a_nulls(pos)) && \
113 ({ tpos = hlist_nulls_entry(pos, typeof(*tpos), member); 1;}); \