[FL-1880] Dialogs: fix semaphore lock (#722)

* Dialogs: fix queued message lock
* Dialogs: file select, fix queued message lock
* Dialogs: file select, free context after freeing callback holder
* Dialogs: better lock, separated wait and free

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
SG
2021-09-25 02:36:53 +10:00
committed by GitHub
parent d3b58f732f
commit acb8508249
6 changed files with 40 additions and 27 deletions

View File

@@ -3,7 +3,7 @@
#include <gui/modules/file_select.h>
typedef struct {
osSemaphoreId_t semaphore;
FuriApiLock lock;
bool result;
} DialogsAppFileSelectContext;
@@ -11,14 +11,14 @@ static void dialogs_app_file_select_back_callback(void* context) {
furi_assert(context);
DialogsAppFileSelectContext* file_select_context = context;
file_select_context->result = false;
API_LOCK_UNLOCK(file_select_context->semaphore);
API_LOCK_UNLOCK(file_select_context->lock);
}
static void dialogs_app_file_select_callback(bool result, void* context) {
furi_assert(context);
DialogsAppFileSelectContext* file_select_context = context;
file_select_context->result = result;
API_LOCK_UNLOCK(file_select_context->semaphore);
API_LOCK_UNLOCK(file_select_context->lock);
}
bool dialogs_app_process_module_file_select(const DialogsAppMessageDataFileSelect* data) {
@@ -27,7 +27,7 @@ bool dialogs_app_process_module_file_select(const DialogsAppMessageDataFileSelec
DialogsAppFileSelectContext* file_select_context =
furi_alloc(sizeof(DialogsAppFileSelectContext));
file_select_context->semaphore = API_LOCK_INIT_LOCKED();
file_select_context->lock = API_LOCK_INIT_LOCKED();
ViewHolder* view_holder = view_holder_alloc();
view_holder_attach_to_gui(view_holder, gui);
@@ -45,14 +45,15 @@ bool dialogs_app_process_module_file_select(const DialogsAppMessageDataFileSelec
view_holder_set_view(view_holder, file_select_get_view(file_select));
view_holder_start(view_holder);
API_LOCK_WAIT_UNTIL_UNLOCK_AND_FREE(file_select_context->semaphore);
API_LOCK_WAIT_UNTIL_UNLOCK(file_select_context->lock);
ret = file_select_context->result;
free(file_select_context);
view_holder_stop(view_holder);
view_holder_free(view_holder);
file_select_free(file_select);
API_LOCK_FREE(file_select_context->lock);
free(file_select_context);
furi_record_close("gui");
return ret;