diff --git a/events/source/EventQueue.cpp b/events/source/EventQueue.cpp index 795704914b..b7c779f7bf 100644 --- a/events/source/EventQueue.cpp +++ b/events/source/EventQueue.cpp @@ -83,12 +83,18 @@ int EventQueue::time_left(int id) void EventQueue::background(Callback 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::thunk, &_update); - } else { - equeue_background(&_equeue, 0, 0); } }