Check is allocation in event queue was success or not, and

report error / assert when allocation fails.
pull/9066/head
deepikabhavnani 2018-12-11 16:24:57 -06:00
parent f5fdbffbe7
commit 5f0912276b
3 changed files with 13 additions and 5 deletions

View File

@ -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<void(int)> 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);
}
}
}

View File

@ -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;
}

View File

@ -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