diff --git a/sys/event/event.c b/sys/event/event.c index 4287d3eb02..c9a615de51 100644 --- a/sys/event/event.c +++ b/sys/event/event.c @@ -22,7 +22,7 @@ */ #include - +#include #include #include "event.h" @@ -60,6 +60,17 @@ void event_cancel(event_queue_t *queue, event_t *event) irq_restore(state); } +bool event_is_queued(const event_queue_t *queue, const event_t *event) +{ + assert(queue); + assert(event); + + unsigned state = irq_disable(); + bool result = clist_find(&queue->event_list, &event->list_node); + irq_restore(state); + return result; +} + event_t *event_get(event_queue_t *queue) { unsigned state = irq_disable(); diff --git a/sys/include/event.h b/sys/include/event.h index 2d519decf5..ff77559127 100644 --- a/sys/include/event.h +++ b/sys/include/event.h @@ -97,6 +97,7 @@ #define EVENT_H #include +#include #include #include "assert.h" @@ -276,6 +277,17 @@ void event_post(event_queue_t *queue, event_t *event); */ void event_cancel(event_queue_t *queue, event_t *event); +/** + * @brief Check if an event is already queued + * + * @param[in] queue event queue to check + * @param[in] event event to check + * + * @returns true if @p event is in @p queue + * @returns false otherwise + */ +bool event_is_queued(const event_queue_t *queue, const event_t *event); + /** * @brief Get next event from event queue, non-blocking *