pthread_cond: refine prvInitializeStaticCond() (#42)

- On v11.1 SMP, pvPortMalloc() should not be called in critical secion.
  vTaskSuspenAll() would trigger assert if in criticalsection.
- The pthread_cond APIs are not ISR safe. Use vTaskSuspendAll() to prevent
  race condition is enough.

Signed-off-by: wangfei_chen <wangfei_chen@realsil.com.cn>
Co-authored-by: wangfei_chen <wangfei_chen@realsil.com.cn>
This commit is contained in:
Saiiijchan
2025-03-31 17:10:19 +08:00
committed by GitHub
parent f1fe687f14
commit 1bb2a0961c

View File

@@ -61,7 +61,7 @@ static bool prvInitializeStaticCond( pthread_cond_internal_t * pxCond )
{ {
/* Cond initialization must be in a critical section to prevent two threads /* Cond initialization must be in a critical section to prevent two threads
* from initializing it at the same time. */ * from initializing it at the same time. */
taskENTER_CRITICAL(); vTaskSuspendAll();
/* Check again that the cond is still uninitialized, i.e. it wasn't /* Check again that the cond is still uninitialized, i.e. it wasn't
* initialized while this function was waiting to enter the critical * initialized while this function was waiting to enter the critical
@@ -82,7 +82,7 @@ static bool prvInitializeStaticCond( pthread_cond_internal_t * pxCond )
} }
/* Exit the critical section. */ /* Exit the critical section. */
taskEXIT_CRITICAL(); xTaskResumeAll();
} }
return pxCond->xIsInitialized; return pxCond->xIsInitialized;