mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/event: add event_wait_timeout()
This commit is contained in:
parent
d07acbe876
commit
63d85ad1b5
@ -29,6 +29,10 @@
|
||||
#include "clist.h"
|
||||
#include "thread.h"
|
||||
|
||||
#ifdef MODULE_XTIMER
|
||||
#include "xtimer.h"
|
||||
#endif
|
||||
|
||||
void event_queue_init_detached(event_queue_t *queue)
|
||||
{
|
||||
assert(queue);
|
||||
@ -110,6 +114,30 @@ event_t *event_wait(event_queue_t *queue)
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef MODULE_XTIMER
|
||||
event_t *event_wait_timeout(event_queue_t *queue, uint32_t timeout)
|
||||
{
|
||||
assert(queue);
|
||||
event_t *result;
|
||||
xtimer_t timer;
|
||||
thread_flags_t flags = 0;
|
||||
|
||||
xtimer_set_timeout_flag(&timer, timeout);
|
||||
do {
|
||||
result = event_get(queue);
|
||||
if (result == NULL) {
|
||||
flags = thread_flags_wait_any(THREAD_FLAG_EVENT | THREAD_FLAG_TIMEOUT);
|
||||
}
|
||||
} while ((result == NULL) && (flags & THREAD_FLAG_EVENT));
|
||||
|
||||
if (result) {
|
||||
xtimer_remove(&timer);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
void event_loop(event_queue_t *queue)
|
||||
{
|
||||
event_t *event;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Inria
|
||||
* 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* 2018 Freie Universität Berlin
|
||||
* 2018-2019 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
@ -231,6 +231,19 @@ event_t *event_get(event_queue_t *queue);
|
||||
*/
|
||||
event_t *event_wait(event_queue_t *queue);
|
||||
|
||||
#if defined(MODULE_XTIMER) || defined(DOXYGEN)
|
||||
/**
|
||||
* @brief Get next event from event queue, blocking until timeout expires
|
||||
*
|
||||
* @param[in] queue queue to query for an event
|
||||
* @param[in] timeout maximum time to wait for an event to be posted in us
|
||||
*
|
||||
* @return pointer to next event if event was taken from the queue
|
||||
* @return NULL if timeout expired before an event was posted
|
||||
*/
|
||||
event_t *event_wait_timeout(event_queue_t *queue, uint32_t timeout);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Simple event loop
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user