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 attach_absolute(Callback<void()> func, TickerDataClock::time_point abs_time);
void handler() override; 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. */ Callback<void()> _function; /**< Callback. */
bool _lock_deepsleep; /**< Flag which indicates if deep sleep should be disabled. */ bool _lock_deepsleep; /**< Flag which indicates if deep sleep should be disabled. */
#endif #endif

View File

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

View File

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