From b6b7ccc24f087cffad77be9c2687fbcfb89bb4f2 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 17 Feb 2023 12:27:57 -0800 Subject: [PATCH] init: Document the locking strategy used in class PropWaiterState Let the compiler verify that lock_ is held when any of the data members are accessed. Bug: 266255006 Change-Id: I71b341815d84ab530627d934ad4d4681b652b9d8 Signed-off-by: Bart Van Assche --- init/init.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/init/init.cpp b/init/init.cpp index 9312f2670..c965fe635 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -212,16 +212,16 @@ static class PropWaiterState { } private: - void ResetWaitForPropLocked() { + void ResetWaitForPropLocked() EXCLUSIVE_LOCKS_REQUIRED(lock_) { wait_prop_name_.clear(); wait_prop_value_.clear(); waiting_for_prop_.reset(); } std::mutex lock_; - std::unique_ptr waiting_for_prop_{nullptr}; - std::string wait_prop_name_; - std::string wait_prop_value_; + GUARDED_BY(lock_) std::unique_ptr waiting_for_prop_{nullptr}; + GUARDED_BY(lock_) std::string wait_prop_name_; + GUARDED_BY(lock_) std::string wait_prop_value_; } prop_waiter_state;