Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: rcu: Introduce rcu_swap_protected()

A common pattern in RCU code is to assign a new value to an RCU pointer
after having read and stored the old value. Introduce a macro for this
pattern.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Shane M Seymour <shane.seymour@hpe.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Bart Van Assche and committed by
Martin K. Petersen
26e3e3cb fbf25233

+16
+16
include/linux/rcupdate.h
··· 408 408 }) 409 409 410 410 /** 411 + * rcu_swap_protected() - swap an RCU and a regular pointer 412 + * @rcu_ptr: RCU pointer 413 + * @ptr: regular pointer 414 + * @c: the conditions under which the dereference will take place 415 + * 416 + * Perform swap(@rcu_ptr, @ptr) where @rcu_ptr is an RCU-annotated pointer and 417 + * @c is the argument that is passed to the rcu_dereference_protected() call 418 + * used to read that pointer. 419 + */ 420 + #define rcu_swap_protected(rcu_ptr, ptr, c) do { \ 421 + typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c)); \ 422 + rcu_assign_pointer((rcu_ptr), (ptr)); \ 423 + (ptr) = __tmp; \ 424 + } while (0) 425 + 426 + /** 411 427 * rcu_access_pointer() - fetch RCU pointer with no dereferencing 412 428 * @p: The pointer to read 413 429 *