From dc2e2c0ce01c355422bc18d07a65df75542f30ad Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Sat, 11 Aug 2018 15:45:43 -0500 Subject: [PATCH] Speed optimization for LowPowerTickerWrapper Only reschedule the Timeout object in the low power ticker wrapper if it is not already pending. --- hal/LowPowerTickerWrapper.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hal/LowPowerTickerWrapper.cpp b/hal/LowPowerTickerWrapper.cpp index fdbdf2c01f..70b5190d4b 100644 --- a/hal/LowPowerTickerWrapper.cpp +++ b/hal/LowPowerTickerWrapper.cpp @@ -251,9 +251,14 @@ void LowPowerTickerWrapper::_schedule_match(timestamp_t current) if (!_set_interrupt_allowed) { // Can't use _intf->set_interrupt so use microsecond Timeout instead - uint32_t ticks = cycles_until_match < _min_count_until_match ? cycles_until_match : _min_count_until_match; - _timeout.attach_us(mbed::callback(this, &LowPowerTickerWrapper::_timeout_handler), _lp_ticks_to_us(ticks)); - _pending_timeout = true; + + // Speed optimization - if a timer has already been scheduled + // then don't schedule it again. + if (!_pending_timeout) { + uint32_t ticks = cycles_until_match < _min_count_until_match ? cycles_until_match : _min_count_until_match; + _timeout.attach_us(mbed::callback(this, &LowPowerTickerWrapper::_timeout_handler), _lp_ticks_to_us(ticks)); + _pending_timeout = true; + } return; }