summaryrefslogtreecommitdiff
path: root/include/linux/rcupdate.h
diff options
context:
space:
mode:
authorBart Van Assche <bart.vanassche@wdc.com>2017-08-29 08:50:11 -0700
committerMartin K. Petersen <martin.petersen@oracle.com>2017-08-29 21:51:41 -0400
commit26e3e3cb05604073f2e9969fb0f06f35eb3b3313 (patch)
treefbdb1b52fa018e2dde35c9956aacfbd3636dfc1b /include/linux/rcupdate.h
parentfbf252335f8e2bd39d4ce59b1db0836a40ab227b (diff)
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>
Diffstat (limited to 'include/linux/rcupdate.h')
-rw-r--r--include/linux/rcupdate.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index f816fc72b51e..8e920f0ecb07 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -408,6 +408,22 @@ static inline void rcu_preempt_sleep_check(void) { }
})
/**
+ * rcu_swap_protected() - swap an RCU and a regular pointer
+ * @rcu_ptr: RCU pointer
+ * @ptr: regular pointer
+ * @c: the conditions under which the dereference will take place
+ *
+ * Perform swap(@rcu_ptr, @ptr) where @rcu_ptr is an RCU-annotated pointer and
+ * @c is the argument that is passed to the rcu_dereference_protected() call
+ * used to read that pointer.
+ */
+#define rcu_swap_protected(rcu_ptr, ptr, c) do { \
+ typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c)); \
+ rcu_assign_pointer((rcu_ptr), (ptr)); \
+ (ptr) = __tmp; \
+} while (0)
+
+/**
* rcu_access_pointer() - fetch RCU pointer with no dereferencing
* @p: The pointer to read
*