Skip to content

Commit db04aef

Browse files
committed
Merge remote-tracking branch 'origin/dev' into release-candidate
2 parents 9cbd942 + 5b911f5 commit db04aef

3 files changed

Lines changed: 37 additions & 30 deletions

File tree

applications/services/cli/cli_vcp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static void cli_vcp_message_received(FuriEventLoopObject* object, void* context)
164164

165165
switch(message.type) {
166166
case CliVcpMessageTypeEnable:
167-
if(cli_vcp->is_enabled) return;
167+
if(cli_vcp->is_enabled) break;
168168
FURI_LOG_D(TAG, "Enabling");
169169
cli_vcp->is_enabled = true;
170170

@@ -175,7 +175,7 @@ static void cli_vcp_message_received(FuriEventLoopObject* object, void* context)
175175
break;
176176

177177
case CliVcpMessageTypeDisable:
178-
if(!cli_vcp->is_enabled) return;
178+
if(!cli_vcp->is_enabled) break;
179179
FURI_LOG_D(TAG, "Disabling");
180180
cli_vcp->is_enabled = false;
181181

applications/services/loader/loader.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ static void loader_do_unlock(Loader* loader) {
694694
}
695695

696696
static void loader_do_emit_queue_empty_event(Loader* loader) {
697+
if(loader_do_is_locked(loader)) return;
697698
FURI_LOG_I(TAG, "Launch queue empty");
698699
LoaderEvent event;
699700
event.type = LoaderEventTypeNoMoreAppsInQueue;

lib/toolbox/cli/shell/cli_shell.c

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,18 @@ CliShellKeyComboSet* component_key_combo_sets[] = {
3131
static_assert(CliShellComponentMAX == COUNT_OF(component_key_combo_sets));
3232

3333
typedef enum {
34-
CliShellStorageEventMount,
35-
CliShellStorageEventUnmount,
34+
CliShellStorageEventMount = (1 << 0),
35+
CliShellStorageEventUnmount = (1 << 1),
3636
} CliShellStorageEvent;
3737

38+
#define CliShellStorageEventAll (CliShellStorageEventMount | CliShellStorageEventUnmount)
39+
40+
typedef struct {
41+
Storage* storage;
42+
FuriPubSubSubscription* subscription;
43+
FuriEventFlag* event_flag;
44+
} CliShellStorage;
45+
3846
struct CliShell {
3947
// Set and freed by external thread
4048
CliShellMotd motd;
@@ -49,11 +57,7 @@ struct CliShell {
4957
FuriEventLoop* event_loop;
5058
CliAnsiParser* ansi_parser;
5159
FuriEventLoopTimer* ansi_parsing_timer;
52-
53-
Storage* storage;
54-
FuriPubSubSubscription* storage_subscription;
55-
FuriMessageQueue* storage_event_queue;
56-
60+
CliShellStorage storage;
5761
void* components[CliShellComponentMAX];
5862
};
5963

@@ -256,31 +260,32 @@ const char* cli_shell_get_prompt(CliShell* cli_shell) {
256260
// Event handlers
257261
// ==============
258262

263+
static void cli_shell_signal_storage_event(CliShell* cli_shell, CliShellStorageEvent event) {
264+
furi_check(!(furi_event_flag_set(cli_shell->storage.event_flag, event) & FuriFlagError));
265+
}
266+
259267
static void cli_shell_storage_event(const void* message, void* context) {
260268
CliShell* cli_shell = context;
261269
const StorageEvent* event = message;
262270

263271
if(event->type == StorageEventTypeCardMount) {
264-
CliShellStorageEvent cli_event = CliShellStorageEventMount;
265-
furi_check(
266-
furi_message_queue_put(cli_shell->storage_event_queue, &cli_event, 0) == FuriStatusOk);
272+
cli_shell_signal_storage_event(cli_shell, CliShellStorageEventMount);
267273
} else if(event->type == StorageEventTypeCardUnmount) {
268-
CliShellStorageEvent cli_event = CliShellStorageEventUnmount;
269-
furi_check(
270-
furi_message_queue_put(cli_shell->storage_event_queue, &cli_event, 0) == FuriStatusOk);
274+
cli_shell_signal_storage_event(cli_shell, CliShellStorageEventUnmount);
271275
}
272276
}
273277

274278
static void cli_shell_storage_internal_event(FuriEventLoopObject* object, void* context) {
275279
CliShell* cli_shell = context;
276-
FuriMessageQueue* queue = object;
277-
CliShellStorageEvent event;
278-
furi_check(furi_message_queue_get(queue, &event, 0) == FuriStatusOk);
280+
FuriEventFlag* event_flag = object;
281+
CliShellStorageEvent event =
282+
furi_event_flag_wait(event_flag, FuriFlagWaitAll, FuriFlagWaitAny, 0);
283+
furi_check(!(event & FuriFlagError));
279284

280-
if(event == CliShellStorageEventMount) {
281-
cli_registry_reload_external_commands(cli_shell->registry, cli_shell->ext_config);
282-
} else if(event == CliShellStorageEventUnmount) {
285+
if(event & CliShellStorageEventUnmount) {
283286
cli_registry_remove_external_commands(cli_shell->registry);
287+
} else if(event & CliShellStorageEventMount) {
288+
cli_registry_reload_external_commands(cli_shell->registry, cli_shell->ext_config);
284289
} else {
285290
furi_crash();
286291
}
@@ -377,25 +382,26 @@ static void cli_shell_init(CliShell* shell) {
377382
shell->ansi_parsing_timer = furi_event_loop_timer_alloc(
378383
shell->event_loop, cli_shell_timer_expired, FuriEventLoopTimerTypeOnce, shell);
379384

380-
shell->storage_event_queue = furi_message_queue_alloc(1, sizeof(CliShellStorageEvent));
381-
furi_event_loop_subscribe_message_queue(
385+
shell->storage.event_flag = furi_event_flag_alloc();
386+
furi_event_loop_subscribe_event_flag(
382387
shell->event_loop,
383-
shell->storage_event_queue,
388+
shell->storage.event_flag,
384389
FuriEventLoopEventIn,
385390
cli_shell_storage_internal_event,
386391
shell);
387-
shell->storage = furi_record_open(RECORD_STORAGE);
388-
shell->storage_subscription =
389-
furi_pubsub_subscribe(storage_get_pubsub(shell->storage), cli_shell_storage_event, shell);
392+
shell->storage.storage = furi_record_open(RECORD_STORAGE);
393+
shell->storage.subscription = furi_pubsub_subscribe(
394+
storage_get_pubsub(shell->storage.storage), cli_shell_storage_event, shell);
390395

391396
cli_shell_install_pipe(shell);
392397
}
393398

394399
static void cli_shell_deinit(CliShell* shell) {
395-
furi_pubsub_unsubscribe(storage_get_pubsub(shell->storage), shell->storage_subscription);
400+
furi_pubsub_unsubscribe(
401+
storage_get_pubsub(shell->storage.storage), shell->storage.subscription);
396402
furi_record_close(RECORD_STORAGE);
397-
furi_event_loop_unsubscribe(shell->event_loop, shell->storage_event_queue);
398-
furi_message_queue_free(shell->storage_event_queue);
403+
furi_event_loop_unsubscribe(shell->event_loop, shell->storage.event_flag);
404+
furi_event_flag_free(shell->storage.event_flag);
399405

400406
cli_shell_completions_free(shell->components[CliShellComponentCompletions]);
401407
cli_shell_line_free(shell->components[CliShellComponentLine]);

0 commit comments

Comments
 (0)