1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/event: ensure that a queue has a waiter before waiting for flags

Document and enforce that a queue has a waiter (i.e. it is claimed)
before waiting for thread flags.
This commit is contained in:
Leandro Lanzieri 2022-04-14 17:10:24 +02:00
parent d3ee32fe97
commit b3b76bf6f3
No known key found for this signature in database
GPG Key ID: F4E9A721761C7593
2 changed files with 22 additions and 0 deletions

View File

@ -80,6 +80,7 @@ event_t *event_wait_multi(event_queue_t *queues, size_t n_queues)
do {
unsigned state = irq_disable();
for (size_t i = 0; i < n_queues; i++) {
assert(queues[i].waiter);
result = container_of(clist_lpop(&queues[i].event_list),
event_t, list_node);
if (result) {
@ -100,6 +101,7 @@ event_t *event_wait_multi(event_queue_t *queues, size_t n_queues)
static event_t *_wait_timeout(event_queue_t *queue)
{
assert(queue);
assert(queue->waiter);
event_t *result;
thread_flags_t flags = 0;

View File

@ -312,6 +312,8 @@ event_t *event_get(event_queue_t *queue);
* the strictest requirements.
*
* @pre 0 < @p n_queues (expect blowing `assert()` otherwise)
* @pre The queue must have a waiter (i.e. it should have been claimed, or
* initialized using @ref event_queue_init, @ref event_queues_init)
*
* @param[in] queues Array of event queues to get event from
* @param[in] n_queues Number of event queues passed in @p queues
@ -330,6 +332,9 @@ event_t *event_wait_multi(event_queue_t *queues, size_t n_queues);
*
* @warning There can only be a single waiter on a queue!
*
* @pre The queue must have a waiter (i.e. it should have been claimed, or
* initialized using @ref event_queue_init, @ref event_queues_init)
*
* @param[in] queue event queue to get event from
*
* @returns pointer to next event
@ -343,6 +348,9 @@ static inline event_t *event_wait(event_queue_t *queue)
/**
* @brief Get next event from event queue, blocking until timeout expires
*
* @pre The queue must have a waiter (i.e. it should have been claimed, or
* initialized using @ref event_queue_init, @ref event_queues_init)
*
* @param[in] queue queue to query for an event
* @param[in] timeout maximum time to wait for an event to be posted in us
*
@ -354,6 +362,9 @@ event_t *event_wait_timeout(event_queue_t *queue, uint32_t timeout);
/**
* @brief Get next event from event queue, blocking until timeout expires
*
* @pre The queue must have a waiter (i.e. it should have been claimed, or
* initialized using @ref event_queue_init, @ref event_queues_init)
*
* @param[in] queue queue to query for an event
* @param[in] timeout maximum time to wait for an event to be posted in us
*
@ -370,6 +381,9 @@ event_t *event_wait_timeout64(event_queue_t *queue, uint64_t timeout);
* This function is the same as event_wait_timeout() with the difference that it
* uses ztimer instead of xtimer as timer backend.
*
* @pre The queue must have a waiter (i.e. it should have been claimed, or
* initialized using @ref event_queue_init, @ref event_queues_init)
*
* @param[in] queue queue to query for an event
* @param[in] clock ztimer clock to use
* @param[in] timeout maximum time to wait for an event, time unit depends
@ -400,6 +414,9 @@ event_t *event_wait_timeout_ztimer(event_queue_t *queue,
*
* @see event_wait_multi
*
* @pre The queue must have a waiter (i.e. it should have been claimed, or
* initialized using @ref event_queue_init, @ref event_queues_init)
*
* @param[in] queues Event queues to process
* @param[in] n_queues Number of queues passed with @p queues
*/
@ -426,6 +443,9 @@ static inline void event_loop_multi(event_queue_t *queues, size_t n_queues)
* }
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* @pre The queue must have a waiter (i.e. it should have been claimed, or
* initialized using @ref event_queue_init, @ref event_queues_init)
*
* @param[in] queue event queue to process
*/
static inline void event_loop(event_queue_t *queue)