Speed optimization for LowPowerTickerWrapper

Only reschedule the Timeout object in the low power ticker wrapper
if it is not already pending.
pull/7524/head
Russ Butler 2018-08-11 15:45:43 -05:00
parent 00b8e24446
commit dc2e2c0ce0
1 changed files with 8 additions and 3 deletions

View File

@ -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;
}