Skip to content

Commit 6add979

Browse files
authored
Merge pull request #10750 from jarvte/eventqueue_cancel_return
Changed EventQueue::cancel to return boolean value
2 parents 7e179f5 + 719117e commit 6add979

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

UNITTESTS/stubs/EventQueue_stub.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ unsigned EventQueue::tick()
4747
return EventQueue_stub::unsigned_value;
4848
}
4949

50-
void EventQueue::cancel(int id)
50+
bool EventQueue::cancel(int id)
5151
{
52+
return true;
5253
}
5354

5455
int EventQueue::time_left(int id)
@@ -62,6 +63,7 @@ void EventQueue::background(Callback<void(int)> update)
6263

6364
int EventQueue::chain(EventQueue *target)
6465
{
66+
return 0;
6567
}
6668

6769
} // namespace events

UNITTESTS/stubs/equeue_stub.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ int equeue_post(equeue_t *queue, void (*cb)(void *), void *event)
9292
return 0;
9393
}
9494

95-
void equeue_cancel(equeue_t *queue, int id)
95+
bool equeue_cancel(equeue_t *queue, int id)
9696
{
97-
97+
return true;
9898
}
9999

100100
void equeue_background(equeue_t *queue,

events/EventQueue.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,16 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
128128
*
129129
* The cancel function is IRQ safe.
130130
*
131-
* If called while the event queue's dispatch loop is active, the cancel
132-
* function does not guarantee that the event will not execute after it
133-
* returns, as the event may have already begun executing.
131+
* If called while the event queue's dispatch loop is active in another thread,
132+
* the cancel function does not guarantee that the event will not execute after it
133+
* returns, as the event may have already begun executing. A call made from
134+
* the same thread as the dispatch loop will always succeed with a valid id.
134135
*
135136
* @param id Unique id of the event
137+
* @return true if event was successfully cancelled
138+
* false if event was not cancelled (invalid id or executing already begun)
136139
*/
137-
void cancel(int id);
140+
bool cancel(int id);
138141

139142
/** Query how much time is left for delayed event
140143
*

events/equeue.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,12 @@ int equeue_post(equeue_t *queue, void (*cb)(void *), void *event);
184184
//
185185
// The equeue_cancel function is irq safe.
186186
//
187-
// If called while the event queue's dispatch loop is active, equeue_cancel
188-
// does not guarantee that the event will not not execute after it returns as
187+
// If called while the event queue's dispatch loop is active in another thread,
188+
// equeue_cancel does not guarantee that the event will not execute after it returns as
189189
// the event may have already begun executing.
190-
void equeue_cancel(equeue_t *queue, int id);
190+
// Returning true guarantees that cancel succeeded and event will not execute.
191+
// Returning false if invalid id or already started executing.
192+
bool equeue_cancel(equeue_t *queue, int id);
191193

192194
// Query how much time is left for delayed event
193195
//

events/source/EventQueue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ unsigned EventQueue::tick()
5050
return equeue_tick();
5151
}
5252

53-
void EventQueue::cancel(int id)
53+
bool EventQueue::cancel(int id)
5454
{
5555
return equeue_cancel(&_equeue, id);
5656
}

events/source/equeue.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,18 @@ int equeue_post(equeue_t *q, void (*cb)(void *), void *p)
374374
return id;
375375
}
376376

377-
void equeue_cancel(equeue_t *q, int id)
377+
bool equeue_cancel(equeue_t *q, int id)
378378
{
379379
if (!id) {
380-
return;
380+
return false;
381381
}
382382

383383
struct equeue_event *e = equeue_unqueue(q, id);
384384
if (e) {
385385
equeue_dealloc(q, e + 1);
386+
return true;
387+
} else {
388+
return false;
386389
}
387390
}
388391

@@ -603,7 +606,7 @@ static void equeue_chain_dispatch(void *p)
603606
static void equeue_chain_update(void *p, int ms)
604607
{
605608
struct equeue_chain_context *c = (struct equeue_chain_context *)p;
606-
equeue_cancel(c->target, c->id);
609+
(void)equeue_cancel(c->target, c->id);
607610

608611
if (ms >= 0) {
609612
c->id = equeue_call_in(c->target, ms, equeue_chain_dispatch, c->q);

0 commit comments

Comments
 (0)