Skip to content

Commit

Permalink
Correct Timeout rescheduling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kjbracey committed May 7, 2020
1 parent 029109a commit 0a9e1db
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/source/Timeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ namespace mbed {
void TimeoutBase::handler()
{
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) {
sleep_manager_unlock_deep_sleep();
}
_function();
_function = nullptr;
function_to_call();
}
}

Expand Down

0 comments on commit 0a9e1db

Please sign in to comment.