Skip to content

Commit a63fc6b

Browse files
committed
rcu: Upgrade rcu_swap_protected() to rcu_replace_pointer()
Although the rcu_swap_protected() macro follows the example of swap(), the interactions with RCU make its update of its argument somewhat counter-intuitive. This commit therefore introduces an rcu_replace_pointer() that returns the old value of the RCU pointer instead of doing the argument update. Once all the uses of rcu_swap_protected() are updated to instead use rcu_replace_pointer(), rcu_swap_protected() will be removed. Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/ Reported-by: Linus Torvalds <[email protected]> [ paulmck: From rcu_replace() to rcu_replace_pointer() per Ingo Molnar. ] Signed-off-by: Paul E. McKenney <[email protected]> Cc: Bart Van Assche <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Hannes Reinecke <[email protected]> Cc: Johannes Thumshirn <[email protected]> Cc: Shane M Seymour <[email protected]> Cc: Martin K. Petersen <[email protected]>
1 parent 54ecb8f commit a63fc6b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

include/linux/rcupdate.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,24 @@ do { \
382382
smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
383383
} while (0)
384384

385+
/**
386+
* rcu_replace_pointer() - replace an RCU pointer, returning its old value
387+
* @rcu_ptr: RCU pointer, whose old value is returned
388+
* @ptr: regular pointer
389+
* @c: the lockdep conditions under which the dereference will take place
390+
*
391+
* Perform a replacement, where @rcu_ptr is an RCU-annotated
392+
* pointer and @c is the lockdep argument that is passed to the
393+
* rcu_dereference_protected() call used to read that pointer. The old
394+
* value of @rcu_ptr is returned, and @rcu_ptr is set to @ptr.
395+
*/
396+
#define rcu_replace_pointer(rcu_ptr, ptr, c) \
397+
({ \
398+
typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c)); \
399+
rcu_assign_pointer((rcu_ptr), (ptr)); \
400+
__tmp; \
401+
})
402+
385403
/**
386404
* rcu_swap_protected() - swap an RCU and a regular pointer
387405
* @rcu_ptr: RCU pointer

0 commit comments

Comments
 (0)