Skip to content

Commit

Permalink
Fix race condition in Mutex::lock
Browse files Browse the repository at this point in the history
Fixes this problem:
* defaultTask is stuck on xSemaphoreTake
* PP triggers
* the delay gets interrupted
* we're still in the non-PP branch of the mutex::lock

BFW-6418
  • Loading branch information
CZDanol authored and danopernis committed Dec 13, 2024
1 parent b6d3f24 commit e5d9113
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/freertos/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,9 @@ bool Mutex::try_lock() {
}

void Mutex::lock() {
// REMOVEME BFW-6418
if (power_panic_mode_removeme) {
// In power panic mode, the defaultTask gets delays periodically aborted, which can result in mutexes takes failing
xSemaphoreTake(handle_cast(mutex_storage), portMAX_DELAY);

} else {
if (xSemaphoreTake(handle_cast(mutex_storage), portMAX_DELAY) != pdTRUE) {
if (xSemaphoreTake(handle_cast(mutex_storage), portMAX_DELAY) != pdTRUE) {
// REMOVEME BFW-6418
if (!power_panic_mode_removeme) {
static_assert(INCLUDE_vTaskSuspend);
// Since we are waiting forever and have task suspension, this should never happen.
std::abort();
Expand Down

0 comments on commit e5d9113

Please sign in to comment.