Unverified Commit db4f7944 authored by hreintke's avatar hreintke Committed by GitHub

CoreMutex freeRTOS Mutex acquire properly (#1481)

Since FreeRTOS has real tasks and mutexes with support for priority bumping, actually always try and take a `CoreMutex` instead of seeing if someone else already has it and aborting immediately.

This fix helps ensure things like Serial output in a multi-task system won't get lost.
parent 45bbcca2
...@@ -30,13 +30,10 @@ CoreMutex::CoreMutex(mutex_t *mutex, uint8_t option) { ...@@ -30,13 +30,10 @@ CoreMutex::CoreMutex(mutex_t *mutex, uint8_t option) {
_option = option; _option = option;
if (__isFreeRTOS) { if (__isFreeRTOS) {
auto m = __get_freertos_mutex_for_ptr(mutex); auto m = __get_freertos_mutex_for_ptr(mutex);
if (__freertos_check_if_in_isr()) { if (__freertos_check_if_in_isr() && !__freertos_mutex_take_from_isr(m)) {
__freertos_mutex_take_from_isr(m); return;
} else {
if (!__freertos_mutex_try_take(m)) {
return;
}
} }
__freertos_mutex_take(m);
} else { } else {
uint32_t owner; uint32_t owner;
if (!mutex_try_enter(_mutex, &owner)) { if (!mutex_try_enter(_mutex, &owner)) {
......
...@@ -43,7 +43,7 @@ extern "C" { ...@@ -43,7 +43,7 @@ extern "C" {
extern SemaphoreHandle_t _freertos_recursive_mutex_create() __attribute__((weak)); extern SemaphoreHandle_t _freertos_recursive_mutex_create() __attribute__((weak));
extern void __freertos_mutex_take(SemaphoreHandle_t mtx) __attribute__((weak)); extern void __freertos_mutex_take(SemaphoreHandle_t mtx) __attribute__((weak));
extern void __freertos_mutex_take_from_isr(SemaphoreHandle_t mtx) __attribute__((weak)); extern int __freertos_mutex_take_from_isr(SemaphoreHandle_t mtx) __attribute__((weak));
extern int __freertos_mutex_try_take(SemaphoreHandle_t mtx) __attribute__((weak)); extern int __freertos_mutex_try_take(SemaphoreHandle_t mtx) __attribute__((weak));
extern void __freertos_mutex_give(SemaphoreHandle_t mtx) __attribute__((weak)); extern void __freertos_mutex_give(SemaphoreHandle_t mtx) __attribute__((weak));
extern void __freertos_mutex_give_from_isr(SemaphoreHandle_t mtx) __attribute__((weak)); extern void __freertos_mutex_give_from_isr(SemaphoreHandle_t mtx) __attribute__((weak));
......
...@@ -58,8 +58,8 @@ extern "C" { ...@@ -58,8 +58,8 @@ extern "C" {
xSemaphoreTake(mtx, portMAX_DELAY); xSemaphoreTake(mtx, portMAX_DELAY);
} }
void __freertos_mutex_take_from_isr(SemaphoreHandle_t mtx) { int __freertos_mutex_take_from_isr(SemaphoreHandle_t mtx) {
xSemaphoreTakeFromISR(mtx, NULL); return xSemaphoreTakeFromISR(mtx, NULL);
} }
int __freertos_mutex_try_take(SemaphoreHandle_t mtx) { int __freertos_mutex_try_take(SemaphoreHandle_t mtx) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment