aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/list.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/list.h')
-rw-r--r--include/linux/list.h67
1 files changed, 62 insertions, 5 deletions
diff --git a/include/linux/list.h b/include/linux/list.h
index 611059d633f4..f9d71eab05ee 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -161,7 +161,7 @@ static inline void __list_del(struct list_head * prev, struct list_head * next)
161/** 161/**
162 * list_del - deletes entry from list. 162 * list_del - deletes entry from list.
163 * @entry: the element to delete from the list. 163 * @entry: the element to delete from the list.
164 * Note: list_empty on entry does not return true after this, the entry is 164 * Note: list_empty() on entry does not return true after this, the entry is
165 * in an undefined state. 165 * in an undefined state.
166 */ 166 */
167#ifndef CONFIG_DEBUG_LIST 167#ifndef CONFIG_DEBUG_LIST
@@ -179,7 +179,7 @@ extern void list_del(struct list_head *entry);
179 * list_del_rcu - deletes entry from list without re-initialization 179 * list_del_rcu - deletes entry from list without re-initialization
180 * @entry: the element to delete from the list. 180 * @entry: the element to delete from the list.
181 * 181 *
182 * Note: list_empty on entry does not return true after this, 182 * Note: list_empty() on entry does not return true after this,
183 * the entry is in an undefined state. It is useful for RCU based 183 * the entry is in an undefined state. It is useful for RCU based
184 * lockfree traversal. 184 * lockfree traversal.
185 * 185 *
@@ -209,7 +209,8 @@ static inline void list_del_rcu(struct list_head *entry)
209 * list_replace - replace old entry by new one 209 * list_replace - replace old entry by new one
210 * @old : the element to be replaced 210 * @old : the element to be replaced
211 * @new : the new element to insert 211 * @new : the new element to insert
212 * Note: if 'old' was empty, it will be overwritten. 212 *
213 * If @old was empty, it will be overwritten.
213 */ 214 */
214static inline void list_replace(struct list_head *old, 215static inline void list_replace(struct list_head *old,
215 struct list_head *new) 216 struct list_head *new)
@@ -360,6 +361,62 @@ static inline void list_splice_init(struct list_head *list,
360} 361}
361 362
362/** 363/**
364 * list_splice_init_rcu - splice an RCU-protected list into an existing list.
365 * @list: the RCU-protected list to splice
366 * @head: the place in the list to splice the first list into
367 * @sync: function to sync: synchronize_rcu(), synchronize_sched(), ...
368 *
369 * @head can be RCU-read traversed concurrently with this function.
370 *
371 * Note that this function blocks.
372 *
373 * Important note: the caller must take whatever action is necessary to
374 * prevent any other updates to @head. In principle, it is possible
375 * to modify the list as soon as sync() begins execution.
376 * If this sort of thing becomes necessary, an alternative version
377 * based on call_rcu() could be created. But only if -really-
378 * needed -- there is no shortage of RCU API members.
379 */
380static inline void list_splice_init_rcu(struct list_head *list,
381 struct list_head *head,
382 void (*sync)(void))
383{
384 struct list_head *first = list->next;
385 struct list_head *last = list->prev;
386 struct list_head *at = head->next;
387
388 if (list_empty(head))
389 return;
390
391 /* "first" and "last" tracking list, so initialize it. */
392
393 INIT_LIST_HEAD(list);
394
395 /*
396 * At this point, the list body still points to the source list.
397 * Wait for any readers to finish using the list before splicing
398 * the list body into the new list. Any new readers will see
399 * an empty list.
400 */
401
402 sync();
403
404 /*
405 * Readers are finished with the source list, so perform splice.
406 * The order is important if the new list is global and accessible
407 * to concurrent RCU readers. Note that RCU readers are not
408 * permitted to traverse the prev pointers without excluding
409 * this function.
410 */
411
412 last->next = at;
413 smp_wmb();
414 head->next = first;
415 first->prev = head;
416 at->prev = last;
417}
418
419/**
363 * list_entry - get the struct for this entry 420 * list_entry - get the struct for this entry
364 * @ptr: the &struct list_head pointer. 421 * @ptr: the &struct list_head pointer.
365 * @type: the type of the struct this is embedded in. 422 * @type: the type of the struct this is embedded in.
@@ -432,12 +489,12 @@ static inline void list_splice_init(struct list_head *list,
432 pos = list_entry(pos->member.prev, typeof(*pos), member)) 489 pos = list_entry(pos->member.prev, typeof(*pos), member))
433 490
434/** 491/**
435 * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue 492 * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
436 * @pos: the type * to use as a start point 493 * @pos: the type * to use as a start point
437 * @head: the head of the list 494 * @head: the head of the list
438 * @member: the name of the list_struct within the struct. 495 * @member: the name of the list_struct within the struct.
439 * 496 *
440 * Prepares a pos entry for use as a start point in list_for_each_entry_continue. 497 * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
441 */ 498 */
442#define list_prepare_entry(pos, head, member) \ 499#define list_prepare_entry(pos, head, member) \
443 ((pos) ? : list_entry(head, typeof(*pos), member)) 500 ((pos) ? : list_entry(head, typeof(*pos), member))