Skip to content

Commit 7b896f1

Browse files
author
Teppo Järvelin
committed
Changed EventQueue::cancel to return boolean value
It's important in some cases to know wether the cancel succeeded. Now Cancel method return boolean value to indicate did the cancel succeed.
1 parent f18e336 commit 7b896f1

File tree

7 files changed

+18
-11
lines changed

7 files changed

+18
-11
lines changed

TESTS/events/queue/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ void cancel_test1()
166166
}
167167

168168
for (int i = N - 1; i >= 0; i--) {
169-
queue.cancel(ids[i]);
169+
TEST_ASSERT_TRUE(queue.cancel(ids[i]));
170170
}
171171

172+
TEST_ASSERT_FALSE(queue.cancel(-9999));
173+
172174
queue.dispatch(0);
173175
}
174176

UNITTESTS/stubs/EventQueue_stub.cpp

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

50-
void EventQueue::cancel(int id)
50+
bool EventQueue::cancel(int id)
5151
{
5252
}
5353

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.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/EventQueue.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
127127
* returns, as the event may have already begun executing.
128128
*
129129
* @param id Unique id of the event
130+
* @return true if event was successfully cancelled
131+
* false if event was not cancelled (invalid id or executing already begun)
130132
*/
131-
void cancel(int id);
133+
bool cancel(int id);
132134

133135
/** Query how much time is left for delayed event
134136
*

events/equeue/equeue.c

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

376-
void equeue_cancel(equeue_t *q, int id)
376+
bool equeue_cancel(equeue_t *q, int id)
377377
{
378378
if (!id) {
379-
return;
379+
return false;
380380
}
381381

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

@@ -602,7 +605,7 @@ static void equeue_chain_dispatch(void *p)
602605
static void equeue_chain_update(void *p, int ms)
603606
{
604607
struct equeue_chain_context *c = (struct equeue_chain_context *)p;
605-
equeue_cancel(c->target, c->id);
608+
(void)equeue_cancel(c->target, c->id);
606609

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

events/equeue/equeue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ int equeue_post(equeue_t *queue, void (*cb)(void *), void *event);
183183
// The equeue_cancel function is irq safe.
184184
//
185185
// If called while the event queue's dispatch loop is active, equeue_cancel
186-
// does not guarantee that the event will not not execute after it returns as
186+
// does not guarantee that the event will not execute after it returns as
187187
// the event may have already begun executing.
188-
void equeue_cancel(equeue_t *queue, int id);
188+
bool equeue_cancel(equeue_t *queue, int id);
189189

190190
// Query how much time is left for delayed event
191191
//

0 commit comments

Comments
 (0)