Durations don't always zero init

In a couple of places I assumed that durations and time_points always
zero-initialised. This is incorrect - they act as if they were their
representation, so integer durations only zero-init when static.

You can zero init (like integers) by having `{}` initialisation.
pull/12425/head
Kevin Bracey 2020-04-03 16:39:31 +03:00
parent 58388b7e5e
commit b614bd3113
3 changed files with 4 additions and 4 deletions

View File

@ -149,7 +149,7 @@ protected:
void attach_absolute(Callback<void()> func, TickerDataClock::time_point abs_time);
void handler() override;
std::chrono::microseconds _delay; /**< Time delay (in microseconds) for resetting the multishot callback. */
std::chrono::microseconds _delay{0}; /**< Time delay (in microseconds) for resetting the multishot callback. */
Callback<void()> _function; /**< Callback. */
bool _lock_deepsleep; /**< Flag which indicates if deep sleep should be disabled. */
#endif

View File

@ -111,8 +111,8 @@ protected:
TimerBase(const ticker_data_t *data, bool lock_deepsleep);
~TimerBase();
std::chrono::microseconds slicetime() const;
TickerDataClock::time_point _start; // the start time of the latest slice
std::chrono::microseconds _time; // any accumulated time from previous slices
TickerDataClock::time_point _start{}; // the start time of the latest slice
std::chrono::microseconds _time{}; // any accumulated time from previous slices
TickerDataClock _ticker_data;
bool _lock_deepsleep; // flag that indicates if deep sleep should be disabled
bool _running = false; // whether the timer is running

View File

@ -100,7 +100,7 @@ microseconds TimerBase::elapsed_time() const
microseconds TimerBase::slicetime() const
{
CriticalSectionLock lock;
microseconds ret;
microseconds ret = 0us;
if (_running) {
ret = _ticker_data.now() - _start;
}