Rev 5056 | Rev 6082 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5056 | Rev 5270 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | 5 | ||
6 | /* |
6 | /* |
7 | * RCU-protected list version |
7 | * RCU-protected list version |
8 | */ |
8 | */ |
9 | #include |
9 | #include |
Line 10... | Line 10... | ||
10 | //#include |
10 | #include |
11 | 11 | ||
12 | /* |
12 | /* |
13 | * Why is there no list_empty_rcu()? Because list_empty() serves this |
13 | * Why is there no list_empty_rcu()? Because list_empty() serves this |
Line 17... | Line 17... | ||
17 | * it is not necessary to use rcu_dereference(), so that list_empty() can |
17 | * it is not necessary to use rcu_dereference(), so that list_empty() can |
18 | * be used anywhere you would want to use a list_empty_rcu(). |
18 | * be used anywhere you would want to use a list_empty_rcu(). |
19 | */ |
19 | */ |
Line 20... | Line 20... | ||
20 | 20 | ||
- | 21 | /* |
|
- | 22 | * INIT_LIST_HEAD_RCU - Initialize a list_head visible to RCU readers |
|
- | 23 | * @list: list to be initialized |
|
- | 24 | * |
|
- | 25 | * You should instead use INIT_LIST_HEAD() for normal initialization and |
|
- | 26 | * cleanup tasks, when readers have no access to the list being initialized. |
|
- | 27 | * However, if the list being initialized is visible to readers, you |
|
- | 28 | * need to keep the compiler from being too mischievous. |
|
- | 29 | */ |
|
- | 30 | static inline void INIT_LIST_HEAD_RCU(struct list_head *list) |
|
- | 31 | { |
|
- | 32 | ACCESS_ONCE(list->next) = list; |
|
- | 33 | ACCESS_ONCE(list->prev) = list; |
|
- | 34 | } |
|
- | 35 | ||
21 | /* |
36 | /* |
22 | * return the ->next pointer of a list_head in an rcu safe |
37 | * return the ->next pointer of a list_head in an rcu safe |
23 | * way, we must not access it directly |
38 | * way, we must not access it directly |
24 | */ |
39 | */ |
Line 195... | Line 210... | ||
195 | * "first" and "last" tracking list, so initialize it. RCU readers |
210 | * "first" and "last" tracking list, so initialize it. RCU readers |
196 | * have access to this list, so we must use INIT_LIST_HEAD_RCU() |
211 | * have access to this list, so we must use INIT_LIST_HEAD_RCU() |
197 | * instead of INIT_LIST_HEAD(). |
212 | * instead of INIT_LIST_HEAD(). |
198 | */ |
213 | */ |
Line 199... | Line 214... | ||
199 | 214 | ||
Line 200... | Line 215... | ||
200 | INIT_LIST_HEAD(list); |
215 | INIT_LIST_HEAD_RCU(list); |
201 | 216 | ||
202 | /* |
217 | /* |
203 | * At this point, the list body still points to the source list. |
218 | * At this point, the list body still points to the source list. |
Line 224... | Line 239... | ||
224 | 239 | ||
225 | /** |
240 | /** |
226 | * list_entry_rcu - get the struct for this entry |
241 | * list_entry_rcu - get the struct for this entry |
227 | * @ptr: the &struct list_head pointer. |
242 | * @ptr: the &struct list_head pointer. |
228 | * @type: the type of the struct this is embedded in. |
243 | * @type: the type of the struct this is embedded in. |
229 | * @member: the name of the list_struct within the struct. |
244 | * @member: the name of the list_head within the struct. |
230 | * |
245 | * |
231 | * This primitive may safely run concurrently with the _rcu list-mutation |
246 | * This primitive may safely run concurrently with the _rcu list-mutation |
232 | * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). |
247 | * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). |
233 | */ |
248 | */ |
Line 261... | Line 276... | ||
261 | 276 | ||
262 | /** |
277 | /** |
263 | * list_first_or_null_rcu - get the first element from a list |
278 | * list_first_or_null_rcu - get the first element from a list |
264 | * @ptr: the list head to take the element from. |
279 | * @ptr: the list head to take the element from. |
265 | * @type: the type of the struct this is embedded in. |
280 | * @type: the type of the struct this is embedded in. |
266 | * @member: the name of the list_struct within the struct. |
281 | * @member: the name of the list_head within the struct. |
267 | * |
282 | * |
268 | * Note that if the list is empty, it returns NULL. |
283 | * Note that if the list is empty, it returns NULL. |
269 | * |
284 | * |
270 | * This primitive may safely run concurrently with the _rcu list-mutation |
285 | * This primitive may safely run concurrently with the _rcu list-mutation |
Line 279... | Line 294... | ||
279 | 294 | ||
280 | /** |
295 | /** |
281 | * list_for_each_entry_rcu - iterate over rcu list of given type |
296 | * list_for_each_entry_rcu - iterate over rcu list of given type |
282 | * @pos: the type * to use as a loop cursor. |
297 | * @pos: the type * to use as a loop cursor. |
283 | * @head: the head for your list. |
298 | * @head: the head for your list. |
284 | * @member: the name of the list_struct within the struct. |
299 | * @member: the name of the list_head within the struct. |
285 | * |
300 | * |
286 | * This list-traversal primitive may safely run concurrently with |
301 | * This list-traversal primitive may safely run concurrently with |
287 | * the _rcu list-mutation primitives such as list_add_rcu() |
302 | * the _rcu list-mutation primitives such as list_add_rcu() |
288 | * as long as the traversal is guarded by rcu_read_lock(). |
303 | * as long as the traversal is guarded by rcu_read_lock(). |
Line 294... | Line 309... | ||
294 | 309 | ||
295 | /** |
310 | /** |
296 | * list_for_each_entry_continue_rcu - continue iteration over list of given type |
311 | * list_for_each_entry_continue_rcu - continue iteration over list of given type |
297 | * @pos: the type * to use as a loop cursor. |
312 | * @pos: the type * to use as a loop cursor. |
298 | * @head: the head for your list. |
313 | * @head: the head for your list. |
299 | * @member: the name of the list_struct within the struct. |
314 | * @member: the name of the list_head within the struct. |
300 | * |
315 | * |
301 | * Continue to iterate over list of given type, continuing after |
316 | * Continue to iterate over list of given type, continuing after |
302 | * the current position. |
317 | * the current position. |
303 | */ |
318 | */ |
Line 525... | Line 540... | ||
525 | typeof(*(pos)), member); \ |
540 | typeof(*(pos)), member); \ |
526 | pos; \ |
541 | pos; \ |
527 | pos = hlist_entry_safe(rcu_dereference_bh((pos)->member.next),\ |
542 | pos = hlist_entry_safe(rcu_dereference_bh((pos)->member.next),\ |
528 | typeof(*(pos)), member)) |
543 | typeof(*(pos)), member)) |
Line -... | Line 544... | ||
- | 544 | ||
- | 545 | /** |
|
- | 546 | * hlist_for_each_entry_from_rcu - iterate over a hlist continuing from current point |
|
- | 547 | * @pos: the type * to use as a loop cursor. |
|
- | 548 | * @member: the name of the hlist_node within the struct. |
|
- | 549 | */ |
|
- | 550 | #define hlist_for_each_entry_from_rcu(pos, member) \ |
|
- | 551 | for (; pos; \ |
|
- | 552 | pos = hlist_entry_safe(rcu_dereference((pos)->member.next),\ |
|
Line 529... | Line 553... | ||
529 | 553 | typeof(*(pos)), member)) |
|
530 | 554 |