From ee3e0fa53729d420a36462d53365438d6c6a3827 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 3 Aug 2020 19:52:53 -0700 Subject: [PATCH] fatal: use TimeSpan for timing --- stratosphere/fatal/source/fatal_config.cpp | 14 +++++---- stratosphere/fatal/source/fatal_config.hpp | 30 +++++++++---------- .../fatal/source/fatal_task_power.cpp | 10 +++---- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/stratosphere/fatal/source/fatal_config.cpp b/stratosphere/fatal/source/fatal_config.cpp index 38889fb2e..8b144a4be 100644 --- a/stratosphere/fatal/source/fatal_config.cpp +++ b/stratosphere/fatal/source/fatal_config.cpp @@ -57,9 +57,6 @@ namespace ams::fatal::srv { } FatalConfig::FatalConfig() { - /* Clear this. */ - std::memset(this, 0, sizeof(*this)); - /* Get information from set. */ settings::system::GetSerialNumber(std::addressof(this->serial_number)); settings::system::GetFirmwareVersion(std::addressof(this->firmware_version)); @@ -69,11 +66,16 @@ namespace ams::fatal::srv { /* Read information from settings. */ settings::fwdbg::GetSettingsItemValue(&this->transition_to_fatal, sizeof(this->transition_to_fatal), "fatal", "transition_to_fatal"); settings::fwdbg::GetSettingsItemValue(&this->show_extra_info, sizeof(this->show_extra_info), "fatal", "show_extra_info"); - settings::fwdbg::GetSettingsItemValue(&this->quest_reboot_interval_second, sizeof(this->quest_reboot_interval_second), "fatal", "quest_reboot_interval_second"); + + u64 quest_interval_second; + settings::fwdbg::GetSettingsItemValue(&quest_interval_second, sizeof(quest_interval_second), "fatal", "quest_reboot_interval_second"); + this->quest_reboot_interval = TimeSpan::FromSeconds(quest_interval_second); /* Atmosphere extension for automatic reboot. */ - if (settings::fwdbg::GetSettingsItemValue(&this->fatal_auto_reboot_interval, sizeof(this->fatal_auto_reboot_interval), "atmosphere", "fatal_auto_reboot_interval") == sizeof(this->fatal_auto_reboot_interval)) { - this->fatal_auto_reboot_enabled = this->fatal_auto_reboot_interval != 0; + u64 auto_reboot_ms; + if (settings::fwdbg::GetSettingsItemValue(&auto_reboot_ms, sizeof(auto_reboot_ms), "atmosphere", "fatal_auto_reboot_interval") == sizeof(auto_reboot_ms)) { + this->fatal_auto_reboot_interval = TimeSpan::FromMilliSeconds(auto_reboot_ms); + this->fatal_auto_reboot_enabled = auto_reboot_ms != 0; } /* Setup messages. */ diff --git a/stratosphere/fatal/source/fatal_config.hpp b/stratosphere/fatal/source/fatal_config.hpp index 38f2c0785..2e0941c68 100644 --- a/stratosphere/fatal/source/fatal_config.hpp +++ b/stratosphere/fatal/source/fatal_config.hpp @@ -20,18 +20,18 @@ namespace ams::fatal::srv { class FatalConfig { private: - settings::system::SerialNumber serial_number; - settings::system::FirmwareVersion firmware_version; - u64 language_code; - u64 quest_reboot_interval_second; - bool transition_to_fatal; - bool show_extra_info; - bool quest_flag; - const char *error_msg; - const char *error_desc; - const char *quest_desc; - u64 fatal_auto_reboot_interval; - bool fatal_auto_reboot_enabled; + settings::system::SerialNumber serial_number{}; + settings::system::FirmwareVersion firmware_version{}; + u64 language_code{}; + TimeSpan quest_reboot_interval{}; + bool transition_to_fatal{}; + bool show_extra_info{}; + bool quest_flag{}; + const char *error_msg{}; + const char *error_desc{}; + const char *quest_desc{}; + TimeSpan fatal_auto_reboot_interval{}; + bool fatal_auto_reboot_enabled{}; public: FatalConfig(); @@ -67,11 +67,11 @@ namespace ams::fatal::srv { return this->fatal_auto_reboot_enabled; } - u64 GetQuestRebootTimeoutInterval() const { - return this->quest_reboot_interval_second * 1'000ul; + TimeSpan GetQuestRebootTimeoutInterval() const { + return this->quest_reboot_interval; } - u64 GetFatalRebootTimeoutInterval() const { + TimeSpan GetFatalRebootTimeoutInterval() const { return this->fatal_auto_reboot_interval; } diff --git a/stratosphere/fatal/source/fatal_task_power.cpp b/stratosphere/fatal/source/fatal_task_power.cpp index 7c2a082b5..4d70a35d5 100644 --- a/stratosphere/fatal/source/fatal_task_power.cpp +++ b/stratosphere/fatal/source/fatal_task_power.cpp @@ -54,16 +54,16 @@ namespace ams::fatal::srv { class RebootTimingObserver { private: os::Tick start_tick; + TimeSpan interval; bool flag; - s64 interval; public: - RebootTimingObserver(bool flag, s64 interval) : start_tick(os::GetSystemTick()), flag(flag), interval(interval) { + RebootTimingObserver(bool flag, TimeSpan iv) : start_tick(os::GetSystemTick()), interval(iv), flag(flag) { /* ... */ } bool IsRebootTiming() const { auto current_tick = os::GetSystemTick(); - return this->flag && (current_tick - this->start_tick).ToTimeSpan().GetMilliSeconds() >= this->interval; + return this->flag && (current_tick - this->start_tick).ToTimeSpan() >= this->interval; } }; @@ -75,7 +75,7 @@ namespace ams::fatal::srv { /* Task Implementations. */ bool PowerControlTask::TryShutdown() { /* Set a timeout of 30 seconds. */ - constexpr s32 MaxShutdownWaitSeconds = 30; + constexpr auto MaxShutdownWaitInterval = TimeSpan::FromSeconds(30); auto start_tick = os::GetSystemTick(); @@ -84,7 +84,7 @@ namespace ams::fatal::srv { while (true) { auto cur_tick = os::GetSystemTick(); - if ((cur_tick - start_tick).ToTimeSpan().GetSeconds() > MaxShutdownWaitSeconds) { + if ((cur_tick - start_tick).ToTimeSpan() > MaxShutdownWaitInterval) { break; }