Skip to content

Commit

Permalink
Speed optimization for LowPowerTickerWrapper
Browse files Browse the repository at this point in the history
Only reschedule the Timeout object in the low power ticker wrapper
if it is not already pending.
  • Loading branch information
c1728p9 committed Aug 17, 2018
1 parent 00b8e24 commit dc2e2c0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions hal/LowPowerTickerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit dc2e2c0

Please sign in to comment.