252afe3f7cf29a081f518439bca7303431312d3c
1 #ifndef _KCOMPAT_RCULIST_H
2 #define _KCOMPAT_RCULIST_H
5 * RCU-protected list version
7 * 2002-10-18 19:01:25-07:00, dipankar@in.ibm.com
8 * [PATCH] RCU helper patchset 2/2
10 * This adds a set of list macros that make handling of list protected
11 * by RCU simpler. The interfaces added are -
15 * - Adds an element by taking care of memory barrier (wmb()).
18 * - Deletes an element but doesn't re-initialize the pointers in
19 * the element for supporting RCU based traversal.
23 * - Traversal of RCU protected list - takes care of memory barriers
30 #include <kcompat/list.h>
33 * Insert a new entry between two known consecutive entries.
35 * This is only for internal list manipulation where we know
36 * the prev/next entries already!
38 static __inline__
void __list_add_rcu(struct list_head
* new,
39 struct list_head
* prev
,
40 struct list_head
* next
)
50 * list_add_rcu - add a new entry to rcu-protected list
51 * @new: new entry to be added
52 * @head: list head to add it after
54 * Insert a new entry after the specified head.
55 * This is good for implementing stacks.
57 * The caller must take whatever precautions are necessary
58 * (such as holding appropriate locks) to avoid racing
59 * with another list-mutation primitive, such as list_add_rcu()
60 * or list_del_rcu(), running on this same list.
61 * However, it is perfectly legal to run concurrently with
62 * the _rcu list-traversal primitives, such as
63 * list_for_each_entry_rcu().
65 static __inline__
void list_add_rcu(struct list_head
*new,
66 struct list_head
*head
)
68 __list_add_rcu(new, head
, head
->next
);
72 * list_add_tail_rcu - add a new entry to rcu-protected list
73 * @new: new entry to be added
74 * @head: list head to add it before
76 * Insert a new entry before the specified head.
77 * This is useful for implementing queues.
79 * The caller must take whatever precautions are necessary
80 * (such as holding appropriate locks) to avoid racing
81 * with another list-mutation primitive, such as list_add_tail_rcu()
82 * or list_del_rcu(), running on this same list.
83 * However, it is perfectly legal to run concurrently with
84 * the _rcu list-traversal primitives, such as
85 * list_for_each_entry_rcu().
87 static __inline__
void list_add_tail_rcu(struct list_head
*new,
88 struct list_head
*head
)
90 __list_add_rcu(new, head
->prev
, head
);
94 * list_del_rcu - deletes entry from list without re-initialization
95 * @entry: the element to delete from the list.
97 * Note: list_empty on entry does not return true after this,
98 * the entry is in an undefined state. It is useful for RCU based
101 * The caller must take whatever precautions are necessary
102 * (such as holding appropriate locks) to avoid racing
103 * with another list-mutation primitive, such as list_del_rcu()
104 * or list_add_rcu(), running on this same list.
105 * However, it is perfectly legal to run concurrently with
106 * the _rcu list-traversal primitives, such as
107 * list_for_each_entry_rcu().
109 * Note that the caller is not permitted to immediately free
110 * the newly deleted entry. Instead, either synchronize_kernel()
111 * or call_rcu() must be used to defer freeing until an RCU
112 * grace period has elapsed.
114 static inline void list_del_rcu(struct list_head
*entry
)
116 __list_del(entry
->prev
, entry
->next
);
120 * list_for_each_rcu - iterate over an rcu-protected list
121 * @pos: the &struct list_head to use as a loop counter.
122 * @head: the head for your list.
124 * This list-traversal primitive may safely run concurrently with
125 * the _rcu list-mutation primitives such as list_add_rcu()
126 * as long as the traversal is guarded by rcu_read_lock().
128 #define list_for_each_rcu(pos, head) \
129 for (pos = rcu_dereference((head)->next); \
130 prefetch(pos->next), pos != (head); \
131 pos = rcu_dereference(pos->next))
133 #define __list_for_each_rcu(pos, head) \
134 for (pos = rcu_dereference((head)->next); \
136 pos = rcu_dereference(pos->next))
139 * list_for_each_entry_rcu - iterate over a rcu-protected list
140 * @pos: the struct type pointer to use as a loop counter
141 * @head: the head for your list
142 * @member: the name of the struct list_head element in your struct type
144 * This list-traversal primitive may safely run concurrently with
145 * the _rcu list-mutation primitives such as list_add_rcu()
146 * as long as the traversal is guarded by rcu_read_lock().
148 #define list_for_each_entry_rcu(pos, head, member) \
149 for (pos = list_entry(rcu_dereference((head)->next), typeof(*pos), \
151 prefetch(pos->member.next), &pos->member != (head); \
152 pos = list_entry(rcu_dereference(pos->member.next),typeof(*pos), \
155 #endif /* _KCOMPAT_RCULIST_H */
This page took 0.05374 seconds and 4 git commands to generate.