From 68a59e1c720871277b01131edb3b64908ad03cbf Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 17 Feb 2023 11:28:14 -0800 Subject: [PATCH 1/2] init: Document the locking strategy in class ShutdownState Let the compiler verify that shutdown_command_lock_ is held when shutdown_command_ is accessed. Bug: 266255006 Change-Id: Ibd05137ab65e20f247f35bbb2bb1865e05f51f41 Signed-off-by: Bart Van Assche --- init/init.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/init/init.cpp b/init/init.cpp index f964c605d..9312f2670 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -259,7 +260,7 @@ static class ShutdownState { private: std::mutex shutdown_command_lock_; - std::string shutdown_command_; + std::string shutdown_command_ GUARDED_BY(shutdown_command_lock_); bool do_shutdown_ = false; } shutdown_state; From b6b7ccc24f087cffad77be9c2687fbcfb89bb4f2 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 17 Feb 2023 12:27:57 -0800 Subject: [PATCH 2/2] 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;