From 071dbc17290ea1c9c4fa645fb5a2cee796009ae8 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 17 Feb 2023 11:27:33 -0800 Subject: [PATCH] init: Combine the CheckShutdown() and set_do_shutdown() methods Let the CheckShutdown() method clear the do_shutdown_ member instead of clearing that member separately from calling CheckShutdown(). Bug: 266255006 Change-Id: Ifc1cff2be92a45db7f91be2fdb812930d2fd1ad5 Signed-off-by: Bart Van Assche --- init/init.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/init/init.cpp b/init/init.cpp index a01ae8765..be1ebeed7 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -247,16 +247,15 @@ static class ShutdownState { WakeMainInitThread(); } - std::optional CheckShutdown() { + std::optional CheckShutdown() __attribute__((warn_unused_result)) { auto lock = std::lock_guard{shutdown_command_lock_}; if (do_shutdown_ && !IsShuttingDown()) { + do_shutdown_ = false; return shutdown_command_; } return {}; } - void set_do_shutdown(bool value) { do_shutdown_ = value; } - private: std::mutex shutdown_command_lock_; std::string shutdown_command_ GUARDED_BY(shutdown_command_lock_); @@ -1094,7 +1093,6 @@ int SecondStageMain(int argc, char** argv) { LOG(INFO) << "Got shutdown_command '" << *shutdown_command << "' Calling HandlePowerctlMessage()"; HandlePowerctlMessage(*shutdown_command); - shutdown_state.set_do_shutdown(false); } if (!(prop_waiter_state.MightBeWaiting() || Service::is_exec_service_running())) {