1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-28 07:51:19 +01:00

ztimer: introduce ztimer_mutex_unlock_after()

This commit is contained in:
Benjamin Valentin 2022-11-15 10:58:11 +01:00 committed by Benjamin Valentin
parent 75c909b813
commit 94f9f11596
2 changed files with 25 additions and 0 deletions

View File

@ -776,6 +776,19 @@ void ztimer_set_wakeup(ztimer_clock_t *clock, ztimer_t *timer, uint32_t offset,
void ztimer_set_timeout_flag(ztimer_clock_t *clock, ztimer_t *timer,
uint32_t timeout);
/**
* @brief Unlock mutex after @p timeout
*
* This function will unlock the given mutex after the timeout has passed.
*
* @param[in] clock ztimer clock to operate on
* @param[in] timer timer struct to use
* @param[in] timeout timeout in ztimer_clock's ticks
* @param[in] mutex mutex to unlock after timeout
*/
void ztimer_mutex_unlock(ztimer_clock_t *clock, ztimer_t *timer,
uint32_t timeout, mutex_t *mutex);
/**
* @brief Try to lock the given mutex, but give up after @p timeout
*

View File

@ -144,6 +144,18 @@ void ztimer_set_timeout_flag(ztimer_clock_t *clock, ztimer_t *t,
}
#endif
void ztimer_mutex_unlock(ztimer_clock_t *clock, ztimer_t *timer, uint32_t offset,
mutex_t *mutex)
{
unsigned state = irq_disable();
timer->callback = _callback_unlock_mutex;
timer->arg = (void *)mutex;
irq_restore(state);
ztimer_set(clock, timer, offset);
}
static void _callback_wakeup(void *arg)
{
thread_wakeup((kernel_pid_t)((intptr_t)arg));