mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-31 11:17:20 +02:00
Merge branch 'bugfix/pthread_once' into 'master'
[pthread] Perform init_routine execution outside of the mutex See merge request !1453
This commit is contained in:
@ -347,6 +347,7 @@ int pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
|
|||||||
}
|
}
|
||||||
|
|
||||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||||
|
uint8_t do_execute = 0;
|
||||||
// do not take mutex if OS is not running yet
|
// do not take mutex if OS is not running yet
|
||||||
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED ||
|
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED ||
|
||||||
// init_routine can call pthread_once for another objects, so use recursive mutex
|
// init_routine can call pthread_once for another objects, so use recursive mutex
|
||||||
@ -354,13 +355,16 @@ int pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
|
|||||||
!cur_task || xSemaphoreTakeRecursive(s_once_mux, portMAX_DELAY) == pdTRUE)
|
!cur_task || xSemaphoreTakeRecursive(s_once_mux, portMAX_DELAY) == pdTRUE)
|
||||||
{
|
{
|
||||||
if (!once_control->init_executed) {
|
if (!once_control->init_executed) {
|
||||||
ESP_LOGV(TAG, "%s: call init_routine %p", __FUNCTION__, once_control);
|
do_execute = 1;
|
||||||
init_routine();
|
|
||||||
once_control->init_executed = 1;
|
once_control->init_executed = 1;
|
||||||
}
|
}
|
||||||
if (cur_task) {
|
if (cur_task) {
|
||||||
xSemaphoreGiveRecursive(s_once_mux);
|
xSemaphoreGiveRecursive(s_once_mux);
|
||||||
}
|
}
|
||||||
|
if (do_execute) {
|
||||||
|
ESP_LOGV(TAG, "%s: call init_routine %p", __FUNCTION__, once_control);
|
||||||
|
init_routine();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user