mirror of
https://github.com/espressif/esp-idf.git
synced 2026-09-22 13:01:16 +03:00
fix(console): join the REPL task before esp_console_stop_repl frees it
This commit is contained in:
@@ -33,6 +33,11 @@ void esp_console_repl_task(void *args)
|
||||
xSemaphoreTake(repl_com->state_mux, portMAX_DELAY);
|
||||
}
|
||||
|
||||
/* Tell esp_console_start_repl() that state_mux is now held. */
|
||||
if (repl_com->task_ready != NULL) {
|
||||
xSemaphoreGive(repl_com->task_ready);
|
||||
}
|
||||
|
||||
/* Change standard input and output of the task if the requested UART is
|
||||
* NOT the default one. This block will replace stdin, stdout and stderr.
|
||||
*/
|
||||
@@ -356,5 +361,10 @@ esp_err_t esp_console_start_repl(esp_console_repl_t *repl)
|
||||
|
||||
repl_com->state = CONSOLE_REPL_STATE_START;
|
||||
xTaskNotifyGive(repl_com->task_hdl);
|
||||
|
||||
/* Return only once the task holds state_mux, so a stop can join it. */
|
||||
if (repl_com->task_ready != NULL) {
|
||||
xSemaphoreTake(repl_com->task_ready, portMAX_DELAY);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -92,6 +92,14 @@ esp_err_t esp_console_internal_set_event_fd(esp_console_repl_com_t *repl_com)
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -123,6 +131,9 @@ esp_err_t esp_console_common_deinit(esp_console_repl_com_t *repl_com)
|
||||
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();
|
||||
|
||||
@@ -42,6 +42,7 @@ typedef struct {
|
||||
TaskHandle_t task_hdl; // REPL task handle
|
||||
size_t max_cmdline_length; // Maximum length of a command line. If 0, default value will be used.
|
||||
size_t max_cmdline_args; // Maximum number of command line arguments to parse. If 0, default value will be used.
|
||||
SemaphoreHandle_t task_ready; // Given once the REPL task holds state_mux
|
||||
} esp_console_repl_com_t;
|
||||
|
||||
typedef struct {
|
||||
|
||||
Reference in New Issue
Block a user