1#ifndef _LINUX_LIST_NULLS_H
2#define _LINUX_LIST_NULLS_H
3
4#include <linux/poison.h>
5#include <linux/const.h>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20struct hlist_nulls_head {
21 struct hlist_nulls_node *first;
22};
23
24struct hlist_nulls_node {
25 struct hlist_nulls_node *next, **pprev;
26};
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))
30
31#define hlist_nulls_entry(ptr, type, member) container_of(ptr,type,member)
32
33#define hlist_nulls_entry_safe(ptr, type, member) \
34 ({ typeof(ptr) ____ptr = (ptr); \
35 !is_a_nulls(____ptr) ? hlist_nulls_entry(____ptr, type, member) : NULL; \
36 })
37
38
39
40
41
42static inline int is_a_nulls(const struct hlist_nulls_node *ptr)
43{
44 return ((unsigned long)ptr & 1);
45}
46
47
48
49
50
51
52
53static inline unsigned long get_nulls_value(const struct hlist_nulls_node *ptr)
54{
55 return ((unsigned long)ptr) >> 1;
56}
57
58static inline int hlist_nulls_unhashed(const struct hlist_nulls_node *h)
59{
60 return !h->pprev;
61}
62
63static inline int hlist_nulls_empty(const struct hlist_nulls_head *h)
64{
65 return is_a_nulls(READ_ONCE(h->first));
66}
67
68static inline void hlist_nulls_add_head(struct hlist_nulls_node *n,
69 struct hlist_nulls_head *h)
70{
71 struct hlist_nulls_node *first = h->first;
72
73 n->next = first;
74 n->pprev = &h->first;
75 h->first = n;
76 if (!is_a_nulls(first))
77 first->pprev = &n->next;
78}
79
80static inline void __hlist_nulls_del(struct hlist_nulls_node *n)
81{
82 struct hlist_nulls_node *next = n->next;
83 struct hlist_nulls_node **pprev = n->pprev;
84
85 WRITE_ONCE(*pprev, next);
86 if (!is_a_nulls(next))
87 next->pprev = pprev;
88}
89
90static inline void hlist_nulls_del(struct hlist_nulls_node *n)
91{
92 __hlist_nulls_del(n);
93 n->pprev = LIST_POISON2;
94}
95
96
97
98
99
100
101
102
103
104#define hlist_nulls_for_each_entry(tpos, pos, head, member) \
105 for (pos = (head)->first; \
106 (!is_a_nulls(pos)) && \
107 ({ tpos = hlist_nulls_entry(pos, typeof(*tpos), member); 1;}); \
108 pos = pos->next)
109
110
111
112
113
114
115
116
117#define hlist_nulls_for_each_entry_from(tpos, pos, member) \
118 for (; (!is_a_nulls(pos)) && \
119 ({ tpos = hlist_nulls_entry(pos, typeof(*tpos), member); 1;}); \
120 pos = pos->next)
121
122#endif
123