diff options
Diffstat (limited to 'include/linux/rculist.h')
-rw-r--r-- | include/linux/rculist.h | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/include/linux/rculist.h b/include/linux/rculist.h index d079290843a9..e0f0fab20415 100644 --- a/include/linux/rculist.h +++ b/include/linux/rculist.h | |||
@@ -30,6 +30,7 @@ | |||
30 | * This is only for internal list manipulation where we know | 30 | * This is only for internal list manipulation where we know |
31 | * the prev/next entries already! | 31 | * the prev/next entries already! |
32 | */ | 32 | */ |
33 | #ifndef CONFIG_DEBUG_LIST | ||
33 | static inline void __list_add_rcu(struct list_head *new, | 34 | static inline void __list_add_rcu(struct list_head *new, |
34 | struct list_head *prev, struct list_head *next) | 35 | struct list_head *prev, struct list_head *next) |
35 | { | 36 | { |
@@ -38,6 +39,10 @@ static inline void __list_add_rcu(struct list_head *new, | |||
38 | rcu_assign_pointer(list_next_rcu(prev), new); | 39 | rcu_assign_pointer(list_next_rcu(prev), new); |
39 | next->prev = new; | 40 | next->prev = new; |
40 | } | 41 | } |
42 | #else | ||
43 | extern void __list_add_rcu(struct list_head *new, | ||
44 | struct list_head *prev, struct list_head *next); | ||
45 | #endif | ||
41 | 46 | ||
42 | /** | 47 | /** |
43 | * list_add_rcu - add a new entry to rcu-protected list | 48 | * list_add_rcu - add a new entry to rcu-protected list |
@@ -108,7 +113,7 @@ static inline void list_add_tail_rcu(struct list_head *new, | |||
108 | */ | 113 | */ |
109 | static inline void list_del_rcu(struct list_head *entry) | 114 | static inline void list_del_rcu(struct list_head *entry) |
110 | { | 115 | { |
111 | __list_del(entry->prev, entry->next); | 116 | __list_del_entry(entry); |
112 | entry->prev = LIST_POISON2; | 117 | entry->prev = LIST_POISON2; |
113 | } | 118 | } |
114 | 119 | ||
@@ -228,18 +233,43 @@ static inline void list_splice_init_rcu(struct list_head *list, | |||
228 | }) | 233 | }) |
229 | 234 | ||
230 | /** | 235 | /** |
231 | * list_first_entry_rcu - get the first element from a list | 236 | * Where are list_empty_rcu() and list_first_entry_rcu()? |
237 | * | ||
238 | * Implementing those functions following their counterparts list_empty() and | ||
239 | * list_first_entry() is not advisable because they lead to subtle race | ||
240 | * conditions as the following snippet shows: | ||
241 | * | ||
242 | * if (!list_empty_rcu(mylist)) { | ||
243 | * struct foo *bar = list_first_entry_rcu(mylist, struct foo, list_member); | ||
244 | * do_something(bar); | ||
245 | * } | ||
246 | * | ||
247 | * The list may not be empty when list_empty_rcu checks it, but it may be when | ||
248 | * list_first_entry_rcu rereads the ->next pointer. | ||
249 | * | ||
250 | * Rereading the ->next pointer is not a problem for list_empty() and | ||
251 | * list_first_entry() because they would be protected by a lock that blocks | ||
252 | * writers. | ||
253 | * | ||
254 | * See list_first_or_null_rcu for an alternative. | ||
255 | */ | ||
256 | |||
257 | /** | ||
258 | * list_first_or_null_rcu - get the first element from a list | ||
232 | * @ptr: the list head to take the element from. | 259 | * @ptr: the list head to take the element from. |
233 | * @type: the type of the struct this is embedded in. | 260 | * @type: the type of the struct this is embedded in. |
234 | * @member: the name of the list_struct within the struct. | 261 | * @member: the name of the list_struct within the struct. |
235 | * | 262 | * |
236 | * Note, that list is expected to be not empty. | 263 | * Note that if the list is empty, it returns NULL. |
237 | * | 264 | * |
238 | * This primitive may safely run concurrently with the _rcu list-mutation | 265 | * This primitive may safely run concurrently with the _rcu list-mutation |
239 | * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). | 266 | * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). |
240 | */ | 267 | */ |
241 | #define list_first_entry_rcu(ptr, type, member) \ | 268 | #define list_first_or_null_rcu(ptr, type, member) \ |
242 | list_entry_rcu((ptr)->next, type, member) | 269 | ({struct list_head *__ptr = (ptr); \ |
270 | struct list_head __rcu *__next = list_next_rcu(__ptr); \ | ||
271 | likely(__ptr != __next) ? container_of(__next, type, member) : NULL; \ | ||
272 | }) | ||
243 | 273 | ||
244 | /** | 274 | /** |
245 | * list_for_each_entry_rcu - iterate over rcu list of given type | 275 | * list_for_each_entry_rcu - iterate over rcu list of given type |