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

core/mutex.c _mutex_lock uses an int pointer

_mutex_lock uses a volatile int pointer for the parameter blocking instead of an int.
This commit is contained in:
JulianHolzwarth 2019-05-24 15:24:18 +02:00
parent 267433b006
commit dd6e51b1eb
3 changed files with 9 additions and 6 deletions

View File

@ -23,6 +23,7 @@
#define MUTEX_H
#include <stddef.h>
#include <stdint.h>
#include "list.h"
@ -87,7 +88,7 @@ static inline void mutex_init(mutex_t *mutex)
* @return 1 if mutex was unlocked, now it is locked.
* @return 0 if the mutex was locked.
*/
int _mutex_lock(mutex_t *mutex, int blocking);
int _mutex_lock(mutex_t *mutex, volatile uint8_t *blocking);
/**
* @brief Tries to get a mutex, non-blocking.
@ -100,7 +101,8 @@ int _mutex_lock(mutex_t *mutex, int blocking);
*/
static inline int mutex_trylock(mutex_t *mutex)
{
return _mutex_lock(mutex, 0);
volatile uint8_t blocking = 0;
return _mutex_lock(mutex, &blocking);
}
/**
@ -110,7 +112,8 @@ static inline int mutex_trylock(mutex_t *mutex)
*/
static inline void mutex_lock(mutex_t *mutex)
{
_mutex_lock(mutex, 1);
volatile uint8_t blocking = 1;
_mutex_lock(mutex, &blocking);
}
/**

View File

@ -32,7 +32,7 @@
#define ENABLE_DEBUG (0)
#include "debug.h"
int _mutex_lock(mutex_t *mutex, int blocking)
int _mutex_lock(mutex_t *mutex, volatile uint8_t *blocking)
{
unsigned irqstate = irq_disable();
@ -46,7 +46,7 @@ int _mutex_lock(mutex_t *mutex, int blocking)
irq_restore(irqstate);
return 1;
}
else if (blocking) {
else if (*blocking) {
thread_t *me = (thread_t*)sched_active_thread;
DEBUG("PID[%" PRIkernel_pid "]: Adding node to mutex queue: prio: %"
PRIu32 "\n", sched_active_pid, (uint32_t)me->priority);

View File

@ -262,7 +262,7 @@ int xtimer_mutex_lock_timeout(mutex_t *mutex, uint64_t timeout)
t.arg = (void *)((mutex_thread_t *)&mt);
xtimer_set64(&t, timeout);
}
int ret = _mutex_lock(mutex, mt.blocking);
int ret = _mutex_lock(mutex, &mt.blocking);
if (ret == 0) {
return -1;
}