Skip to content

Commit

Permalink
Do not blindly restore lock state, but depend on the current state (#109
Browse files Browse the repository at this point in the history
)

The scheduler state checking has been removed as the scheduler being locked out
could still be valid due to the nesting.
  • Loading branch information
pakluba authored and VladimirUmek committed Aug 19, 2024
1 parent ba82e7e commit 533ca44
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions CMSIS/RTOS2/FreeRTOS/Source/cmsis_os2.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,18 @@ int32_t osKernelRestoreLock (int32_t lock) {
else {
switch (xTaskGetSchedulerState()) {
case taskSCHEDULER_SUSPENDED:
if (lock == 0) {
if (xTaskResumeAll() != pdTRUE) {
lock = (int32_t)osError;
}
}
else {
if (lock != 1) {
lock = (int32_t)osError;
}
}
break;

case taskSCHEDULER_RUNNING:
if (lock == 1) {
vTaskSuspendAll();
Expand All @@ -403,13 +415,6 @@ int32_t osKernelRestoreLock (int32_t lock) {
if (lock != 0) {
lock = (int32_t)osError;
}
else {
if (xTaskResumeAll() != pdTRUE) {
if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) {
lock = (int32_t)osError;
}
}
}
}
break;

Expand Down

0 comments on commit 533ca44

Please sign in to comment.