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
34
35
36
37static inline int is_a_nulls(const struct hlist_nulls_node *ptr)
38{
39 return ((unsigned long)ptr & 1);
40}
41
42
43
44
45
46
47
48static inline unsigned long get_nulls_value(const struct hlist_nulls_node *ptr)
49{
50 return ((unsigned long)ptr) >> 1;
51}
52
53static inline int hlist_nulls_unhashed(const struct hlist_nulls_node *h)
54{
55 return !h->pprev;
56}
57
58static inline int hlist_nulls_empty(const struct hlist_nulls_head *h)
59{
60 return is_a_nulls(READ_ONCE(h->first));
61}
62
63static inline void hlist_nulls_add_head(struct hlist_nulls_node *n,
64 struct hlist_nulls_head *h)
65{
66 struct hlist_nulls_node *first = h->first;
67
68 n->next = first;
69 n->pprev = &h->first;
70 h->first = n;
71 if (!is_a_nulls(first))
72 first->pprev = &n->next;
73}
74
75static inline void __hlist_nulls_del(struct hlist_nulls_node *n)
76{
77 struct hlist_nulls_node *next = n->next;
78 struct hlist_nulls_node **pprev = n->pprev;
79
80 WRITE_ONCE(*pprev, next);
81 if (!is_a_nulls(next))
82 next->pprev = pprev;
83}
84
85static inline void hlist_nulls_del(struct hlist_nulls_node *n)
86{
87 __hlist_nulls_del(n);
88 n->pprev = LIST_POISON2;
89}
90
91
92
93
94
95
96
97
98
99#define hlist_nulls_for_each_entry(tpos, pos, head, member) \
100 for (pos = (head)->first; \
101 (!is_a_nulls(pos)) && \
102 ({ tpos = hlist_nulls_entry(pos, typeof(*tpos), member); 1;}); \
103 pos = pos->next)
104
105
106
107
108
109
110
111
112#define hlist_nulls_for_each_entry_from(tpos, pos, member) \
113 for (; (!is_a_nulls(pos)) && \
114 ({ tpos = hlist_nulls_entry(pos, typeof(*tpos), member); 1;}); \
115 pos = pos->next)
116
117#endif
118