Skip to content

Commit dc2e2c0

Browse files
committed
Speed optimization for LowPowerTickerWrapper
Only reschedule the Timeout object in the low power ticker wrapper if it is not already pending.
1 parent 00b8e24 commit dc2e2c0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

hal/LowPowerTickerWrapper.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,14 @@ void LowPowerTickerWrapper::_schedule_match(timestamp_t current)
251251
if (!_set_interrupt_allowed) {
252252

253253
// Can't use _intf->set_interrupt so use microsecond Timeout instead
254-
uint32_t ticks = cycles_until_match < _min_count_until_match ? cycles_until_match : _min_count_until_match;
255-
_timeout.attach_us(mbed::callback(this, &LowPowerTickerWrapper::_timeout_handler), _lp_ticks_to_us(ticks));
256-
_pending_timeout = true;
254+
255+
// Speed optimization - if a timer has already been scheduled
256+
// then don't schedule it again.
257+
if (!_pending_timeout) {
258+
uint32_t ticks = cycles_until_match < _min_count_until_match ? cycles_until_match : _min_count_until_match;
259+
_timeout.attach_us(mbed::callback(this, &LowPowerTickerWrapper::_timeout_handler), _lp_ticks_to_us(ticks));
260+
_pending_timeout = true;
261+
}
257262
return;
258263
}
259264

0 commit comments

Comments
 (0)