kvm tools, setup: Create private directory
[linux-2.6/next.git] / include / linux / rculist_bl.h
blobcf1244fbf3b66cc444ad80854d7e0126d45cfb09
1 #ifndef _LINUX_RCULIST_BL_H
2 #define _LINUX_RCULIST_BL_H
4 /*
5 * RCU-protected bl list version. See include/linux/list_bl.h.
6 */
7 #include <linux/list_bl.h>
8 #include <linux/rcupdate.h>
10 static inline void hlist_bl_set_first_rcu(struct hlist_bl_head *h,
11 struct hlist_bl_node *n)
13 LIST_BL_BUG_ON((unsigned long)n & LIST_BL_LOCKMASK);
14 LIST_BL_BUG_ON(((unsigned long)h->first & LIST_BL_LOCKMASK) !=
15 LIST_BL_LOCKMASK);
16 rcu_assign_pointer(h->first,
17 (struct hlist_bl_node *)((unsigned long)n | LIST_BL_LOCKMASK));
20 static inline struct hlist_bl_node *hlist_bl_first_rcu(struct hlist_bl_head *h)
22 return (struct hlist_bl_node *)
23 ((unsigned long)rcu_dereference(h->first) & ~LIST_BL_LOCKMASK);
26 /**
27 * hlist_bl_del_init_rcu - deletes entry from hash list with re-initialization
28 * @n: the element to delete from the hash list.
30 * Note: hlist_bl_unhashed() on the node returns true after this. It is
31 * useful for RCU based read lockfree traversal if the writer side
32 * must know if the list entry is still hashed or already unhashed.
34 * In particular, it means that we can not poison the forward pointers
35 * that may still be used for walking the hash list and we can only
36 * zero the pprev pointer so list_unhashed() will return true after
37 * this.
39 * The caller must take whatever precautions are necessary (such as
40 * holding appropriate locks) to avoid racing with another
41 * list-mutation primitive, such as hlist_bl_add_head_rcu() or
42 * hlist_bl_del_rcu(), running on this same list. However, it is
43 * perfectly legal to run concurrently with the _rcu list-traversal
44 * primitives, such as hlist_bl_for_each_entry_rcu().
46 static inline void hlist_bl_del_init_rcu(struct hlist_bl_node *n)
48 if (!hlist_bl_unhashed(n)) {
49 __hlist_bl_del(n);
50 n->pprev = NULL;
54 /**
55 * hlist_bl_del_rcu - deletes entry from hash list without re-initialization
56 * @n: the element to delete from the hash list.
58 * Note: hlist_bl_unhashed() on entry does not return true after this,
59 * the entry is in an undefined state. It is useful for RCU based
60 * lockfree traversal.
62 * In particular, it means that we can not poison the forward
63 * pointers that may still be used for walking the hash list.
65 * The caller must take whatever precautions are necessary
66 * (such as holding appropriate locks) to avoid racing
67 * with another list-mutation primitive, such as hlist_bl_add_head_rcu()
68 * or hlist_bl_del_rcu(), running on this same list.
69 * However, it is perfectly legal to run concurrently with
70 * the _rcu list-traversal primitives, such as
71 * hlist_bl_for_each_entry().
73 static inline void hlist_bl_del_rcu(struct hlist_bl_node *n)
75 __hlist_bl_del(n);
76 n->pprev = LIST_POISON2;
79 /**
80 * hlist_bl_add_head_rcu
81 * @n: the element to add to the hash list.
82 * @h: the list to add to.
84 * Description:
85 * Adds the specified element to the specified hlist_bl,
86 * while permitting racing traversals.
88 * The caller must take whatever precautions are necessary
89 * (such as holding appropriate locks) to avoid racing
90 * with another list-mutation primitive, such as hlist_bl_add_head_rcu()
91 * or hlist_bl_del_rcu(), running on this same list.
92 * However, it is perfectly legal to run concurrently with
93 * the _rcu list-traversal primitives, such as
94 * hlist_bl_for_each_entry_rcu(), used to prevent memory-consistency
95 * problems on Alpha CPUs. Regardless of the type of CPU, the
96 * list-traversal primitive must be guarded by rcu_read_lock().
98 static inline void hlist_bl_add_head_rcu(struct hlist_bl_node *n,
99 struct hlist_bl_head *h)
101 struct hlist_bl_node *first;
103 /* don't need hlist_bl_first_rcu because we're under lock */
104 first = hlist_bl_first(h);
106 n->next = first;
107 if (first)
108 first->pprev = &n->next;
109 n->pprev = &h->first;
111 /* need _rcu because we can have concurrent lock free readers */
112 hlist_bl_set_first_rcu(h, n);
115 * hlist_bl_for_each_entry_rcu - iterate over rcu list of given type
116 * @tpos: the type * to use as a loop cursor.
117 * @pos: the &struct hlist_bl_node to use as a loop cursor.
118 * @head: the head for your list.
119 * @member: the name of the hlist_bl_node within the struct.
122 #define hlist_bl_for_each_entry_rcu(tpos, pos, head, member) \
123 for (pos = hlist_bl_first_rcu(head); \
124 pos && \
125 ({ tpos = hlist_bl_entry(pos, typeof(*tpos), member); 1; }); \
126 pos = rcu_dereference_raw(pos->next))
128 #endif