Merge "init: Combine the CheckShutdown() and set_do_shutdown() methods"

This commit is contained in:
Bart Van Assche 2023-03-06 18:09:09 +00:00 committed by Gerrit Code Review
commit 42908c45e5
1 changed files with 2 additions and 4 deletions

View File

@ -247,16 +247,15 @@ static class ShutdownState {
WakeMainInitThread(); WakeMainInitThread();
} }
std::optional<std::string> CheckShutdown() { std::optional<std::string> CheckShutdown() __attribute__((warn_unused_result)) {
auto lock = std::lock_guard{shutdown_command_lock_}; auto lock = std::lock_guard{shutdown_command_lock_};
if (do_shutdown_ && !IsShuttingDown()) { if (do_shutdown_ && !IsShuttingDown()) {
do_shutdown_ = false;
return shutdown_command_; return shutdown_command_;
} }
return {}; return {};
} }
void set_do_shutdown(bool value) { do_shutdown_ = value; }
private: private:
std::mutex shutdown_command_lock_; std::mutex shutdown_command_lock_;
std::string shutdown_command_ GUARDED_BY(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 LOG(INFO) << "Got shutdown_command '" << *shutdown_command
<< "' Calling HandlePowerctlMessage()"; << "' Calling HandlePowerctlMessage()";
HandlePowerctlMessage(*shutdown_command); HandlePowerctlMessage(*shutdown_command);
shutdown_state.set_do_shutdown(false);
} }
if (!(prop_waiter_state.MightBeWaiting() || Service::is_exec_service_running())) { if (!(prop_waiter_state.MightBeWaiting() || Service::is_exec_service_running())) {