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