fix(console): join with an empty semaphore instead of a given mutex

This commit is contained in:
Yogesh Mantri
2026-09-10 10:12:00 +00:00
parent cd1a5fc1f3
commit 4532e7e8c8
4 changed files with 8 additions and 29 deletions
+7 -14
View File
@@ -85,20 +85,13 @@ esp_err_t esp_console_internal_set_event_fd(esp_console_repl_com_t *repl_com)
return ESP_FAIL;
}
repl_com->state_mux = xSemaphoreCreateMutex();
/* Empty on purpose, and the task only ever gives it, never takes it: a
* mutex created given lets a stop take it before the task has run. */
repl_com->state_mux = xSemaphoreCreateBinary();
if (repl_com->state_mux == NULL) {
ESP_LOGE(TAG, "state_mux create error");
return ESP_ERR_NO_MEM;
}
xSemaphoreGive(repl_com->state_mux);
repl_com->task_ready = xSemaphoreCreateBinary();
if (repl_com->task_ready == NULL) {
ESP_LOGE(TAG, "task_ready create error");
vSemaphoreDelete(repl_com->state_mux);
repl_com->state_mux = NULL;
return ESP_ERR_NO_MEM;
}
return ESP_OK;
}
@@ -111,6 +104,7 @@ esp_err_t esp_console_common_deinit(esp_console_repl_com_t *repl_com)
{
// set the state to deinit to force the while loop in
// esp_console_repl_task to break
const bool was_started = (repl_com->state == CONSOLE_REPL_STATE_START);
repl_com->state = CONSOLE_REPL_STATE_DEINIT;
if (s_interrupt_reading_fd == -1) {
@@ -125,15 +119,14 @@ esp_err_t esp_console_common_deinit(esp_console_repl_com_t *repl_com)
// wait for the task to notify that
// esp_console_repl_task returned
assert(repl_com->state_mux != NULL);
xSemaphoreTake(repl_com->state_mux, portMAX_DELAY);
if (was_started) {
xSemaphoreTake(repl_com->state_mux, portMAX_DELAY);
}
// delete the semaphore for the repl state
vSemaphoreDelete(repl_com->state_mux);
repl_com->state_mux = NULL;
vSemaphoreDelete(repl_com->task_ready);
repl_com->task_ready = NULL;
/* Unregister the heap function to avoid memory leak, since it is created
* every time a console init is called. */
esp_err_t ret = esp_console_deregister_help_command();