Mutex owned and owner were not initialized by mutex_init. Combined owned and owner as they had no separate value any more
This commit is contained in:
parent
e95df76a19
commit
90ce1faa14
@ -31,8 +31,7 @@ extern "C" {
|
|||||||
|
|
||||||
typedef struct __packed_aligned mutex {
|
typedef struct __packed_aligned mutex {
|
||||||
lock_core_t core;
|
lock_core_t core;
|
||||||
bool owned;
|
int8_t owner; //! core number or -1 for unowned
|
||||||
int8_t owner;
|
|
||||||
} mutex_t;
|
} mutex_t;
|
||||||
|
|
||||||
/*! \brief Initialise a mutex structure
|
/*! \brief Initialise a mutex structure
|
||||||
|
@ -13,6 +13,7 @@ static_assert(sizeof(mutex_t) == 8, "");
|
|||||||
|
|
||||||
void mutex_init(mutex_t *mtx) {
|
void mutex_init(mutex_t *mtx) {
|
||||||
lock_init(&mtx->core, next_striped_spin_lock_num());
|
lock_init(&mtx->core, next_striped_spin_lock_num());
|
||||||
|
mtx->owner = -1;
|
||||||
__mem_fence_release();
|
__mem_fence_release();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,8 +22,7 @@ void __time_critical_func(mutex_enter_blocking)(mutex_t *mtx) {
|
|||||||
bool block = true;
|
bool block = true;
|
||||||
do {
|
do {
|
||||||
uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
|
uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
|
||||||
if (!mtx->owned) {
|
if (mtx->owner < 0) {
|
||||||
mtx->owned = true;
|
|
||||||
mtx->owner = get_core_num();
|
mtx->owner = get_core_num();
|
||||||
block = false;
|
block = false;
|
||||||
}
|
}
|
||||||
@ -36,8 +36,7 @@ void __time_critical_func(mutex_enter_blocking)(mutex_t *mtx) {
|
|||||||
bool __time_critical_func(mutex_try_enter)(mutex_t *mtx, uint32_t *owner_out) {
|
bool __time_critical_func(mutex_try_enter)(mutex_t *mtx, uint32_t *owner_out) {
|
||||||
bool entered;
|
bool entered;
|
||||||
uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
|
uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
|
||||||
if (!mtx->owned) {
|
if (mtx->owner < 0) {
|
||||||
mtx->owned = true;
|
|
||||||
mtx->owner = get_core_num();
|
mtx->owner = get_core_num();
|
||||||
entered = true;
|
entered = true;
|
||||||
} else {
|
} else {
|
||||||
@ -57,8 +56,7 @@ bool __time_critical_func(mutex_enter_block_until)(mutex_t *mtx, absolute_time_t
|
|||||||
bool block = true;
|
bool block = true;
|
||||||
do {
|
do {
|
||||||
uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
|
uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
|
||||||
if (!mtx->owned) {
|
if (mtx->owner < 0) {
|
||||||
mtx->owned = true;
|
|
||||||
mtx->owner = get_core_num();
|
mtx->owner = get_core_num();
|
||||||
block = false;
|
block = false;
|
||||||
}
|
}
|
||||||
@ -75,10 +73,7 @@ bool __time_critical_func(mutex_enter_block_until)(mutex_t *mtx, absolute_time_t
|
|||||||
void __time_critical_func(mutex_exit)(mutex_t *mtx) {
|
void __time_critical_func(mutex_exit)(mutex_t *mtx) {
|
||||||
uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
|
uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
|
||||||
assert(mtx->owned);
|
assert(mtx->owned);
|
||||||
mtx->owned = 0;
|
|
||||||
#ifndef NDEBUG
|
|
||||||
mtx->owner = -1;
|
mtx->owner = -1;
|
||||||
#endif
|
|
||||||
__sev();
|
__sev();
|
||||||
spin_unlock(mtx->core.spin_lock, save);
|
spin_unlock(mtx->core.spin_lock, save);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user