Skip to content

Commit 5f09122

Browse files
author
deepikabhavnani
committed
Check is allocation in event queue was success or not, and
report error / assert when allocation fails.
1 parent f5fdbff commit 5f09122

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

events/EventQueue.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
#include "events/EventQueue.h"
1818
#include "events/mbed_events.h"
19+
#include "platform/mbed_assert.h"
1920

2021
using mbed::Callback;
2122

@@ -74,9 +75,9 @@ void EventQueue::background(Callback<void(int)> update)
7475
void EventQueue::chain(EventQueue *target)
7576
{
7677
if (target) {
77-
equeue_chain(&_equeue, &target->_equeue);
78+
MBED_ASSERT(equeue_chain(&_equeue, &target->_equeue) == 0);
7879
} else {
79-
equeue_chain(&_equeue, 0);
80+
MBED_ASSERT(equeue_chain(&_equeue, 0) == 0);
8081
}
8182
}
8283
}

events/equeue/equeue.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,19 +605,23 @@ static void equeue_chain_update(void *p, int ms)
605605
}
606606
}
607607

608-
void equeue_chain(equeue_t *q, equeue_t *target)
608+
int equeue_chain(equeue_t *q, equeue_t *target)
609609
{
610610
if (!target) {
611611
equeue_background(q, 0, 0);
612-
return;
612+
return 0;
613613
}
614614

615615
struct equeue_chain_context *c = equeue_alloc(q,
616616
sizeof(struct equeue_chain_context));
617+
if (!c) {
618+
return -1;
619+
}
617620

618621
c->q = q;
619622
c->target = target;
620623
c->id = 0;
621624

622625
equeue_background(q, equeue_chain_update, c);
626+
return 0;
623627
}

events/equeue/equeue.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ void equeue_background(equeue_t *queue,
220220
//
221221
// The equeue_chain function allows multiple equeues to be composed, sharing
222222
// the context of a dispatch loop while still being managed independently.
223-
void equeue_chain(equeue_t *queue, equeue_t *target);
223+
//
224+
// If the event queue chaining fails, equeue_chain returns a negative,
225+
// platform-specific error code.
226+
int equeue_chain(equeue_t *queue, equeue_t *target);
224227

225228

226229
#ifdef __cplusplus

0 commit comments

Comments
 (0)