diff --git a/events/EventQueue.cpp b/events/EventQueue.cpp index 3cd89a6b23..4ed980f139 100644 --- a/events/EventQueue.cpp +++ b/events/EventQueue.cpp @@ -16,6 +16,7 @@ */ #include "events/EventQueue.h" #include "events/mbed_events.h" +#include "platform/mbed_assert.h" using mbed::Callback; @@ -74,9 +75,9 @@ void EventQueue::background(Callback update) void EventQueue::chain(EventQueue *target) { if (target) { - equeue_chain(&_equeue, &target->_equeue); + MBED_ASSERT(equeue_chain(&_equeue, &target->_equeue) == 0); } else { - equeue_chain(&_equeue, 0); + MBED_ASSERT(equeue_chain(&_equeue, 0) == 0); } } } diff --git a/events/equeue/equeue.c b/events/equeue/equeue.c index 4d985539da..38f9e7e6b3 100644 --- a/events/equeue/equeue.c +++ b/events/equeue/equeue.c @@ -605,19 +605,23 @@ static void equeue_chain_update(void *p, int ms) } } -void equeue_chain(equeue_t *q, equeue_t *target) +int equeue_chain(equeue_t *q, equeue_t *target) { if (!target) { equeue_background(q, 0, 0); - return; + return 0; } struct equeue_chain_context *c = equeue_alloc(q, sizeof(struct equeue_chain_context)); + if (!c) { + return -1; + } c->q = q; c->target = target; c->id = 0; equeue_background(q, equeue_chain_update, c); + return 0; } diff --git a/events/equeue/equeue.h b/events/equeue/equeue.h index 37013b3130..a2c56e3fc8 100644 --- a/events/equeue/equeue.h +++ b/events/equeue/equeue.h @@ -220,7 +220,10 @@ void equeue_background(equeue_t *queue, // // The equeue_chain function allows multiple equeues to be composed, sharing // the context of a dispatch loop while still being managed independently. -void equeue_chain(equeue_t *queue, equeue_t *target); +// +// If the event queue chaining fails, equeue_chain returns a negative, +// platform-specific error code. +int equeue_chain(equeue_t *queue, equeue_t *target); #ifdef __cplusplus