From b98631c633d62eb5d1384b8101a3ce738ff53031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=81=8F?= Date: Thu, 21 Sep 2023 23:34:48 +0900 Subject: [PATCH] Gui: handle view port lockup and notify developer about it (#3102) * Gui: handle view port lockup and notify developer about it * Gui: fix more viewport deadlock cases and add proper notification --- applications/services/gui/view_port.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/applications/services/gui/view_port.c b/applications/services/gui/view_port.c index 6723a777bbb..25f670a7c15 100644 --- a/applications/services/gui/view_port.c +++ b/applications/services/gui/view_port.c @@ -6,6 +6,8 @@ #include "gui.h" #include "gui_i.h" +#define TAG "ViewPort" + _Static_assert(ViewPortOrientationMAX == 4, "Incorrect ViewPortOrientation count"); _Static_assert( (ViewPortOrientationHorizontal == 0 && ViewPortOrientationHorizontalFlip == 1 && @@ -174,9 +176,15 @@ void view_port_input_callback_set( void view_port_update(ViewPort* view_port) { furi_assert(view_port); - furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk); + + // We are not going to lockup system, but will notify you instead + // Make sure that you don't call viewport methods inside of another mutex, especially one that is used in draw call + if(furi_mutex_acquire(view_port->mutex, 2) != FuriStatusOk) { + FURI_LOG_W(TAG, "ViewPort lockup: see %s:%d", __FILE__, __LINE__ - 3); + } + if(view_port->gui && view_port->is_enabled) gui_update(view_port->gui); - furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk); + furi_mutex_release(view_port->mutex); } void view_port_gui_set(ViewPort* view_port, Gui* gui) { @@ -189,14 +197,21 @@ void view_port_gui_set(ViewPort* view_port, Gui* gui) { void view_port_draw(ViewPort* view_port, Canvas* canvas) { furi_assert(view_port); furi_assert(canvas); - furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk); + + // We are not going to lockup system, but will notify you instead + // Make sure that you don't call viewport methods inside of another mutex, especially one that is used in draw call + if(furi_mutex_acquire(view_port->mutex, 2) != FuriStatusOk) { + FURI_LOG_W(TAG, "ViewPort lockup: see %s:%d", __FILE__, __LINE__ - 3); + } + furi_check(view_port->gui); if(view_port->draw_callback) { view_port_setup_canvas_orientation(view_port, canvas); view_port->draw_callback(canvas, view_port->draw_callback_context); } - furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk); + + furi_mutex_release(view_port->mutex); } void view_port_input(ViewPort* view_port, InputEvent* event) {