mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:32:45 +01:00
sys/xtimer/xtimer.c: new function xtimer_rmutex_lock_timeout()
function tries to acquire a mutex within a timeout
This commit is contained in:
parent
dbab3a6075
commit
6d6b93afdc
@ -24,6 +24,7 @@
|
||||
|
||||
#include "xtimer.h"
|
||||
#include "mutex.h"
|
||||
#include "rmutex.h"
|
||||
#include "thread.h"
|
||||
#include "irq.h"
|
||||
#include "div.h"
|
||||
@ -270,6 +271,20 @@ int xtimer_mutex_lock_timeout(mutex_t *mutex, uint64_t timeout)
|
||||
return -mt.dequeued;
|
||||
}
|
||||
|
||||
int xtimer_rmutex_lock_timeout(rmutex_t *rmutex, uint64_t timeout)
|
||||
{
|
||||
if (rmutex_trylock(rmutex)) {
|
||||
return 0;
|
||||
}
|
||||
if (xtimer_mutex_lock_timeout(&rmutex->mutex, timeout) == 0) {
|
||||
atomic_store_explicit(&rmutex->owner,
|
||||
thread_getpid(), memory_order_relaxed);
|
||||
rmutex->refcount++;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef MODULE_CORE_THREAD_FLAGS
|
||||
static void _set_timeout_flag_callback(void* arg)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user