esp32/ble: Lock the scheduler before creating pinned thread

This ensures that the thread that has been just created doesn't
run before its affinity is set, avoiding it to be scheduled in the
wrong CPU core.
This commit is contained in:
Tiago Medicci Serrano 2023-10-23 15:40:09 +02:00 committed by Xiang Xiao
parent 9997a858e2
commit fae075a749

View File

@ -772,6 +772,15 @@ static int32_t esp_task_create_pinned_to_core(void *entry,
DEBUGASSERT(task_handle != NULL);
#ifdef CONFIG_SMP
ret = sched_lock();
if (ret)
{
wlerr("Failed to lock scheduler before creating pinned thread\n");
return false;
}
#endif
pid = kthread_create(name, prio, stack_depth, entry,
(char * const *)param);
if (pid > 0)
@ -800,6 +809,15 @@ static int32_t esp_task_create_pinned_to_core(void *entry,
wlerr("Failed to create task, error %d\n", pid);
}
#ifdef CONFIG_SMP
ret = sched_unlock();
if (ret)
{
wlerr("Failed to unlock scheduler after creating pinned thread\n");
return false;
}
#endif
return pid > 0;
}