diff options
author | William A. Kennington III <wak@google.com> | 2018-02-27 18:59:58 -0800 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2018-03-07 11:16:15 +0000 |
commit | 5e3f877179a5b56d098173afb60753b1d1e6c9af (patch) | |
tree | dbfff33a50e58568015095e6be774dd7a39edc0a | |
parent | 1c9515f8ab0d387911544bb5f7049942291f6cc4 (diff) | |
download | phosphor-watchdog-5e3f877179a5b56d098173afb60753b1d1e6c9af.tar.gz phosphor-watchdog-5e3f877179a5b56d098173afb60753b1d1e6c9af.zip |
watchdog: Refactor timeRemaining
This function also depends only on the state of the timer.
This patch introduces no functional changes but will make
future changes shorter.
Change-Id: Id9b5825faf6c4795ca5b862f140afe06ca51e1cf
Signed-off-by: William A. Kennington III <wak@google.com>
-rw-r--r-- | watchdog.cpp | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/watchdog.cpp b/watchdog.cpp index 4a87a0d..b5cae66 100644 --- a/watchdog.cpp +++ b/watchdog.cpp @@ -71,24 +71,18 @@ uint64_t Watchdog::timeRemaining() const // Reset the timer to a new expiration value uint64_t Watchdog::timeRemaining(uint64_t value) { - if (this->enabled()) + if (timer.getEnabled() == SD_EVENT_OFF) { - // Disable the timer - timer.setEnabled<std::false_type>(); - - // Timer handles all in microseconds and hence converting - auto usec = duration_cast<microseconds>( - milliseconds(value)); - // Update new expiration - timer.start(usec); + // We don't need to update the timer because it is off + return 0; + } - // Enable the timer. - timer.setEnabled<std::true_type>(); + // Update new expiration + auto usec = duration_cast<microseconds>(milliseconds(value)); + timer.start(usec); - // Update Base class data. - return WatchdogInherits::timeRemaining(value); - } - return 0; + // Update Base class data. + return WatchdogInherits::timeRemaining(value); } // Optional callback function on timer expiration |