Skip to content
Snippets Groups Projects
Commit 35f329e0 authored by Kaspar Schleiser's avatar Kaspar Schleiser
Browse files

sys/xtimer: add xtimer_set_timeout_flag()

parent 1bb256a3
No related branches found
No related tags found
No related merge requests found
...@@ -439,6 +439,17 @@ static inline bool xtimer_less64(xtimer_ticks64_t a, xtimer_ticks64_t b); ...@@ -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); 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 * @brief xtimer backoff value
* *
......
...@@ -30,6 +30,10 @@ ...@@ -30,6 +30,10 @@
#include "timex.h" #include "timex.h"
#ifdef MODULE_CORE_THREAD_FLAGS
#include "thread_flags.h"
#endif
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
#include "debug.h" #include "debug.h"
...@@ -257,3 +261,18 @@ int xtimer_mutex_lock_timeout(mutex_t *mutex, uint64_t timeout) ...@@ -257,3 +261,18 @@ int xtimer_mutex_lock_timeout(mutex_t *mutex, uint64_t timeout)
xtimer_remove(&t); xtimer_remove(&t);
return -mt.timeout; 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment