Correct Timeout rescheduling

Chrono changes "optimised" `Timeout::handler` in a way that broke users
who rescheduled the timeout during their attached callback.

Attempted optimisation is less necessary now that
`platform.callback-nontrivial` is set to false by default - that
setting reduces overhead of copying the `Callback` to almost nothing.
pull/12941/head
Kevin Bracey 2020-05-07 16:41:35 +03:00
parent 029109a2f0
commit 0a9e1db181
1 changed files with 6 additions and 2 deletions

View File

@ -27,11 +27,15 @@ namespace mbed {
void TimeoutBase::handler() void TimeoutBase::handler()
{ {
if (_function) { if (_function) {
Callback<void()> function_to_call = _function;
// Clean up state to "detached" before calling callback; it may attach
// a new callback. Equivalent to detach(), but skips the remove();
// it's unnecessary because we're in the ticker's handler.
_function = nullptr;
if (_lock_deepsleep) { if (_lock_deepsleep) {
sleep_manager_unlock_deep_sleep(); sleep_manager_unlock_deep_sleep();
} }
_function(); function_to_call();
_function = nullptr;
} }
} }