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:
graham sanderson 2021-01-28 09:05:36 -06:00 committed by Luke Wren
parent 70240c2508
commit eb19e49522
2 changed files with 5 additions and 11 deletions

View File

@ -31,8 +31,7 @@ extern "C" {
typedef struct __packed_aligned mutex {
lock_core_t core;
bool owned;
int8_t owner;
int8_t owner; //! core number or -1 for unowned
} mutex_t;
/*! \brief Initialise a mutex structure

View File

@ -13,6 +13,7 @@ static_assert(sizeof(mutex_t) == 8, "");
void mutex_init(mutex_t *mtx) {
lock_init(&mtx->core, next_striped_spin_lock_num());
mtx->owner = -1;
__mem_fence_release();
}
@ -21,8 +22,7 @@ void __time_critical_func(mutex_enter_blocking)(mutex_t *mtx) {
bool block = true;
do {
uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
if (!mtx->owned) {
mtx->owned = true;
if (mtx->owner < 0) {
mtx->owner = get_core_num();
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 entered;
uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
if (!mtx->owned) {
mtx->owned = true;
if (mtx->owner < 0) {
mtx->owner = get_core_num();
entered = true;
} else {
@ -57,8 +56,7 @@ bool __time_critical_func(mutex_enter_block_until)(mutex_t *mtx, absolute_time_t
bool block = true;
do {
uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
if (!mtx->owned) {
mtx->owned = true;
if (mtx->owner < 0) {
mtx->owner = get_core_num();
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) {
uint32_t save = spin_lock_blocking(mtx->core.spin_lock);
assert(mtx->owned);
mtx->owned = 0;
#ifndef NDEBUG
mtx->owner = -1;
#endif
__sev();
spin_unlock(mtx->core.spin_lock, save);
}