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