From 5b911f5405f104ad3e3051aa70e2a50a5b2a6d16 Mon Sep 17 00:00:00 2001 From: Anna Antonenko Date: Fri, 18 Apr 2025 16:41:13 +0400 Subject: [PATCH] RC fixes (#4192) * cli_shell: fix FL-3983 * fix formatting and submodules * loader: fix FL-3986 * fix submodules --------- Co-authored-by: hedger --- applications/services/loader/loader.c | 1 + lib/toolbox/cli/shell/cli_shell.c | 62 +++++++++++++++------------ 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/applications/services/loader/loader.c b/applications/services/loader/loader.c index 136b3c20b6..7b37f2510f 100644 --- a/applications/services/loader/loader.c +++ b/applications/services/loader/loader.c @@ -694,6 +694,7 @@ static void loader_do_unlock(Loader* loader) { } static void loader_do_emit_queue_empty_event(Loader* loader) { + if(loader_do_is_locked(loader)) return; FURI_LOG_I(TAG, "Launch queue empty"); LoaderEvent event; event.type = LoaderEventTypeNoMoreAppsInQueue; diff --git a/lib/toolbox/cli/shell/cli_shell.c b/lib/toolbox/cli/shell/cli_shell.c index 8aa7c387a7..7a4c7ec1fb 100644 --- a/lib/toolbox/cli/shell/cli_shell.c +++ b/lib/toolbox/cli/shell/cli_shell.c @@ -31,10 +31,18 @@ CliShellKeyComboSet* component_key_combo_sets[] = { static_assert(CliShellComponentMAX == COUNT_OF(component_key_combo_sets)); typedef enum { - CliShellStorageEventMount, - CliShellStorageEventUnmount, + CliShellStorageEventMount = (1 << 0), + CliShellStorageEventUnmount = (1 << 1), } CliShellStorageEvent; +#define CliShellStorageEventAll (CliShellStorageEventMount | CliShellStorageEventUnmount) + +typedef struct { + Storage* storage; + FuriPubSubSubscription* subscription; + FuriEventFlag* event_flag; +} CliShellStorage; + struct CliShell { // Set and freed by external thread CliShellMotd motd; @@ -49,11 +57,7 @@ struct CliShell { FuriEventLoop* event_loop; CliAnsiParser* ansi_parser; FuriEventLoopTimer* ansi_parsing_timer; - - Storage* storage; - FuriPubSubSubscription* storage_subscription; - FuriMessageQueue* storage_event_queue; - + CliShellStorage storage; void* components[CliShellComponentMAX]; }; @@ -256,31 +260,32 @@ const char* cli_shell_get_prompt(CliShell* cli_shell) { // Event handlers // ============== +static void cli_shell_signal_storage_event(CliShell* cli_shell, CliShellStorageEvent event) { + furi_check(!(furi_event_flag_set(cli_shell->storage.event_flag, event) & FuriFlagError)); +} + static void cli_shell_storage_event(const void* message, void* context) { CliShell* cli_shell = context; const StorageEvent* event = message; if(event->type == StorageEventTypeCardMount) { - CliShellStorageEvent cli_event = CliShellStorageEventMount; - furi_check( - furi_message_queue_put(cli_shell->storage_event_queue, &cli_event, 0) == FuriStatusOk); + cli_shell_signal_storage_event(cli_shell, CliShellStorageEventMount); } else if(event->type == StorageEventTypeCardUnmount) { - CliShellStorageEvent cli_event = CliShellStorageEventUnmount; - furi_check( - furi_message_queue_put(cli_shell->storage_event_queue, &cli_event, 0) == FuriStatusOk); + cli_shell_signal_storage_event(cli_shell, CliShellStorageEventUnmount); } } static void cli_shell_storage_internal_event(FuriEventLoopObject* object, void* context) { CliShell* cli_shell = context; - FuriMessageQueue* queue = object; - CliShellStorageEvent event; - furi_check(furi_message_queue_get(queue, &event, 0) == FuriStatusOk); + FuriEventFlag* event_flag = object; + CliShellStorageEvent event = + furi_event_flag_wait(event_flag, FuriFlagWaitAll, FuriFlagWaitAny, 0); + furi_check(!(event & FuriFlagError)); - if(event == CliShellStorageEventMount) { - cli_registry_reload_external_commands(cli_shell->registry, cli_shell->ext_config); - } else if(event == CliShellStorageEventUnmount) { + if(event & CliShellStorageEventUnmount) { cli_registry_remove_external_commands(cli_shell->registry); + } else if(event & CliShellStorageEventMount) { + cli_registry_reload_external_commands(cli_shell->registry, cli_shell->ext_config); } else { furi_crash(); } @@ -377,25 +382,26 @@ static void cli_shell_init(CliShell* shell) { shell->ansi_parsing_timer = furi_event_loop_timer_alloc( shell->event_loop, cli_shell_timer_expired, FuriEventLoopTimerTypeOnce, shell); - shell->storage_event_queue = furi_message_queue_alloc(1, sizeof(CliShellStorageEvent)); - furi_event_loop_subscribe_message_queue( + shell->storage.event_flag = furi_event_flag_alloc(); + furi_event_loop_subscribe_event_flag( shell->event_loop, - shell->storage_event_queue, + shell->storage.event_flag, FuriEventLoopEventIn, cli_shell_storage_internal_event, shell); - shell->storage = furi_record_open(RECORD_STORAGE); - shell->storage_subscription = - furi_pubsub_subscribe(storage_get_pubsub(shell->storage), cli_shell_storage_event, shell); + shell->storage.storage = furi_record_open(RECORD_STORAGE); + shell->storage.subscription = furi_pubsub_subscribe( + storage_get_pubsub(shell->storage.storage), cli_shell_storage_event, shell); cli_shell_install_pipe(shell); } static void cli_shell_deinit(CliShell* shell) { - furi_pubsub_unsubscribe(storage_get_pubsub(shell->storage), shell->storage_subscription); + furi_pubsub_unsubscribe( + storage_get_pubsub(shell->storage.storage), shell->storage.subscription); furi_record_close(RECORD_STORAGE); - furi_event_loop_unsubscribe(shell->event_loop, shell->storage_event_queue); - furi_message_queue_free(shell->storage_event_queue); + furi_event_loop_unsubscribe(shell->event_loop, shell->storage.event_flag); + furi_event_flag_free(shell->storage.event_flag); cli_shell_completions_free(shell->components[CliShellComponentCompletions]); cli_shell_line_free(shell->components[CliShellComponentLine]);