Merge pull request #10750 from jarvte/eventqueue_cancel_return

Changed EventQueue::cancel to return boolean value
pull/11370/head
Martin Kojtal 2019-08-27 20:50:03 +02:00 committed by GitHub
commit 6add979210
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 14 deletions

View File

@ -47,8 +47,9 @@ unsigned EventQueue::tick()
return EventQueue_stub::unsigned_value; return EventQueue_stub::unsigned_value;
} }
void EventQueue::cancel(int id) bool EventQueue::cancel(int id)
{ {
return true;
} }
int EventQueue::time_left(int id) int EventQueue::time_left(int id)
@ -62,6 +63,7 @@ void EventQueue::background(Callback<void(int)> update)
int EventQueue::chain(EventQueue *target) int EventQueue::chain(EventQueue *target)
{ {
return 0;
} }
} // namespace events } // namespace events

View File

@ -92,9 +92,9 @@ int equeue_post(equeue_t *queue, void (*cb)(void *), void *event)
return 0; return 0;
} }
void equeue_cancel(equeue_t *queue, int id) bool equeue_cancel(equeue_t *queue, int id)
{ {
return true;
} }
void equeue_background(equeue_t *queue, void equeue_background(equeue_t *queue,

View File

@ -128,13 +128,16 @@ public:
* *
* The cancel function is IRQ safe. * The cancel function is IRQ safe.
* *
* If called while the event queue's dispatch loop is active, the cancel * If called while the event queue's dispatch loop is active in another thread,
* function does not guarantee that the event will not execute after it * the cancel function does not guarantee that the event will not execute after it
* returns, as the event may have already begun executing. * returns, as the event may have already begun executing. A call made from
* the same thread as the dispatch loop will always succeed with a valid id.
* *
* @param id Unique id of the event * @param id Unique id of the event
* @return true if event was successfully cancelled
* false if event was not cancelled (invalid id or executing already begun)
*/ */
void cancel(int id); bool cancel(int id);
/** Query how much time is left for delayed event /** Query how much time is left for delayed event
* *

View File

@ -184,10 +184,12 @@ int equeue_post(equeue_t *queue, void (*cb)(void *), void *event);
// //
// The equeue_cancel function is irq safe. // The equeue_cancel function is irq safe.
// //
// If called while the event queue's dispatch loop is active, equeue_cancel // If called while the event queue's dispatch loop is active in another thread,
// does not guarantee that the event will not not execute after it returns as // equeue_cancel does not guarantee that the event will not execute after it returns as
// the event may have already begun executing. // the event may have already begun executing.
void equeue_cancel(equeue_t *queue, int id); // Returning true guarantees that cancel succeeded and event will not execute.
// Returning false if invalid id or already started executing.
bool equeue_cancel(equeue_t *queue, int id);
// Query how much time is left for delayed event // Query how much time is left for delayed event
// //

View File

@ -50,7 +50,7 @@ unsigned EventQueue::tick()
return equeue_tick(); return equeue_tick();
} }
void EventQueue::cancel(int id) bool EventQueue::cancel(int id)
{ {
return equeue_cancel(&_equeue, id); return equeue_cancel(&_equeue, id);
} }

View File

@ -374,15 +374,18 @@ int equeue_post(equeue_t *q, void (*cb)(void *), void *p)
return id; return id;
} }
void equeue_cancel(equeue_t *q, int id) bool equeue_cancel(equeue_t *q, int id)
{ {
if (!id) { if (!id) {
return; return false;
} }
struct equeue_event *e = equeue_unqueue(q, id); struct equeue_event *e = equeue_unqueue(q, id);
if (e) { if (e) {
equeue_dealloc(q, e + 1); equeue_dealloc(q, e + 1);
return true;
} else {
return false;
} }
} }
@ -603,7 +606,7 @@ static void equeue_chain_dispatch(void *p)
static void equeue_chain_update(void *p, int ms) static void equeue_chain_update(void *p, int ms)
{ {
struct equeue_chain_context *c = (struct equeue_chain_context *)p; struct equeue_chain_context *c = (struct equeue_chain_context *)p;
equeue_cancel(c->target, c->id); (void)equeue_cancel(c->target, c->id);
if (ms >= 0) { if (ms >= 0) {
c->id = equeue_call_in(c->target, ms, equeue_chain_dispatch, c->q); c->id = equeue_call_in(c->target, ms, equeue_chain_dispatch, c->q);