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

sys/xtimer: add xtimer_set_timeout_flag()

This commit is contained in:
Kaspar Schleiser 2017-09-01 23:52:56 +02:00
parent 1bb256a308
commit 35f329e05c
2 changed files with 30 additions and 0 deletions

View File

@ -439,6 +439,17 @@ static inline bool xtimer_less64(xtimer_ticks64_t a, xtimer_ticks64_t b);
*/
int xtimer_mutex_lock_timeout(mutex_t *mutex, uint64_t us);
/**
* @brief Set timeout thread flag after @p timeout
*
* This function will set THREAD_FLAG_TIMEOUT on the current thread after @p
* timeout usec have passed.
*
* @param[in] t timer struct to use
* @param[in] timeout timeout in usec
*/
void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout);
/**
* @brief xtimer backoff value
*

View File

@ -30,6 +30,10 @@
#include "timex.h"
#ifdef MODULE_CORE_THREAD_FLAGS
#include "thread_flags.h"
#endif
#define ENABLE_DEBUG 0
#include "debug.h"
@ -257,3 +261,18 @@ int xtimer_mutex_lock_timeout(mutex_t *mutex, uint64_t timeout)
xtimer_remove(&t);
return -mt.timeout;
}
#ifdef MODULE_CORE_THREAD_FLAGS
static void _set_timeout_flag_callback(void* arg)
{
thread_flags_set(arg, THREAD_FLAG_TIMEOUT);
}
void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout)
{
t->callback = _set_timeout_flag_callback;
t->arg = (thread_t *)sched_active_thread;
thread_flags_clear(THREAD_FLAG_TIMEOUT);
xtimer_set(t, timeout);
}
#endif