From 5626f8c6d46832b02ce4fdc0bd109516bc812043 Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Mon, 7 Oct 2019 15:36:37 +0100 Subject: rcu: Add automatically released rcu_read_lock variants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RCU_READ_LOCK_GUARD() takes the rcu_read_lock and then uses glib's g_auto infrastructure (and thus whatever the compiler's hooks are) to release it on all exits of the block. WITH_RCU_READ_LOCK_GUARD() is similar but is used as a wrapper for the lock, i.e.: WITH_RCU_READ_LOCK_GUARD() { stuff under lock } Note the 'unused' attribute is needed to work around clang bug: https://bugs.llvm.org/show_bug.cgi?id=43482 Signed-off-by: Dr. David Alan Gilbert Acked-by: Paolo Bonzini Reviewed-by: Daniel P. Berrangé Message-Id: <20191007143642.301445-2-dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- docs/devel/rcu.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'docs') diff --git a/docs/devel/rcu.txt b/docs/devel/rcu.txt index c84e7f4..d83fed2 100644 --- a/docs/devel/rcu.txt +++ b/docs/devel/rcu.txt @@ -187,6 +187,22 @@ The following APIs must be used before RCU is used in a thread: Note that these APIs are relatively heavyweight, and should _not_ be nested. +Convenience macros +================== + +Two macros are provided that automatically release the read lock at the +end of the scope. + + RCU_READ_LOCK_GUARD() + + Takes the lock and will release it at the end of the block it's + used in. + + WITH_RCU_READ_LOCK_GUARD() { code } + + Is used at the head of a block to protect the code within the block. + +Note that 'goto'ing out of the guarded block will also drop the lock. DIFFERENCES WITH LINUX ====================== -- cgit v1.1