Merge pull request #15061 from pan-/fix-event-queue-background-fn-change

Fix replacement of event queue background.
pull/15077/head
Anna Bridge 2021-09-16 11:34:34 +01:00 committed by GitHub
commit 7feef5981e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -83,12 +83,18 @@ int EventQueue::time_left(int id)
void EventQueue::background(Callback<void(int)> update)
{
// Start by setting the background callback to nullptr
// as equeue_background calls the existing handler with a timeout
// of -1 to indicate to the callback that the tineout process is
// not further required.
// Updating _update before would prevent calling into the
// old callback as the callbacks share the same memory locations.
equeue_background(&_equeue, 0, 0);
_update = update;
if (_update) {
equeue_background(&_equeue, &Callback<void(int)>::thunk, &_update);
} else {
equeue_background(&_equeue, 0, 0);
}
}