From f46ebd5984401c50ce809b58375d81f093453e08 Mon Sep 17 00:00:00 2001 From: Xorboo Date: Thu, 1 Jun 2023 22:49:34 +0200 Subject: [PATCH] Replace legacy ValueMutex with Furi mutex ValueMutex is obsolete since https://github.com/flipperdevices/flipperzero-firmware/pull/2467 --- roots_of_life_game.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/roots_of_life_game.c b/roots_of_life_game.c index d1624f7..aa5c613 100644 --- a/roots_of_life_game.c +++ b/roots_of_life_game.c @@ -84,6 +84,8 @@ typedef struct { int rerolls; int score; + + FuriMutex* mutex; } GameState; typedef struct { @@ -565,10 +567,9 @@ static void draw_end_ui(Canvas* canvas, GameState* state) { } static void roots_draw_callback(Canvas* const canvas, void* ctx) { - GameState* state = acquire_mutex((ValueMutex*)ctx, 25); - if(state == NULL) { - return; - } + furi_assert(ctx); + GameState* state = ctx; + furi_mutex_acquire(state->mutex, FuriWaitForever); if(!state->initialDraw) { state->initialDraw = true; @@ -600,7 +601,7 @@ static void roots_draw_callback(Canvas* const canvas, void* ctx) { break; } - release_mutex((ValueMutex*)ctx, state); + furi_mutex_release(state->mutex); } static void roots_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { @@ -678,8 +679,8 @@ int32_t roots_of_life_game_app(void* p) { GameState* state = malloc(sizeof(GameState)); game_state_init(state); - ValueMutex state_mutex; - if(!init_mutex(&state_mutex, state, sizeof(GameState))) { + state->mutex = furi_mutex_alloc(FuriMutexTypeNormal); + if(!state->mutex) { FURI_LOG_E(TAG, "Cannot create mutex\r\n"); return_code = 255; goto free_and_exit; @@ -687,7 +688,7 @@ int32_t roots_of_life_game_app(void* p) { // Set system callbacks ViewPort* view_port = view_port_alloc(); - view_port_draw_callback_set(view_port, roots_draw_callback, &state_mutex); + view_port_draw_callback_set(view_port, roots_draw_callback, state); view_port_input_callback_set(view_port, roots_input_callback, event_queue); FuriTimer* timer = @@ -702,7 +703,7 @@ int32_t roots_of_life_game_app(void* p) { GameEvent event; for(bool processing = true; processing;) { FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); - GameState* state = (GameState*)acquire_mutex_block(&state_mutex); + furi_mutex_acquire(state->mutex, FuriWaitForever); if(event_status == FuriStatusOk) { // Key events @@ -733,7 +734,7 @@ int32_t roots_of_life_game_app(void* p) { } view_port_update(view_port); - release_mutex(&state_mutex, state); + furi_mutex_release(state->mutex); } furi_timer_free(timer); @@ -742,7 +743,7 @@ int32_t roots_of_life_game_app(void* p) { furi_record_close(RECORD_GUI); furi_record_close(RECORD_NOTIFICATION); view_port_free(view_port); - delete_mutex(&state_mutex); + furi_mutex_free(state->mutex); free_and_exit: FURI_LOG_D(TAG, "Quitting game...");