Massive plugins refactoring

Not full refactoring, only small issues is fixed and moved all plugins to furi mutex instead of valuemutex

Many small issues was found and fixed due mutex upgrade

OFW removed 60 lines of code and it was painful
This commit is contained in:
MX 2023-03-08 00:18:23 +03:00
parent f0471a62e5
commit 28eb4d1060
No known key found for this signature in database
GPG key ID: 7CCC66B7DBDD1C83
37 changed files with 362 additions and 346 deletions

View file

@ -38,6 +38,7 @@ typedef struct {
} BallState; } BallState;
typedef struct { typedef struct {
FuriMutex* mutex;
BallState ball_state; BallState ball_state;
BrickState brick_state; BrickState brick_state;
NotificationApp* notify; NotificationApp* notify;
@ -310,10 +311,9 @@ static void arkanoid_state_init(ArkanoidState* arkanoid_state) {
} }
static void arkanoid_draw_callback(Canvas* const canvas, void* ctx) { static void arkanoid_draw_callback(Canvas* const canvas, void* ctx) {
ArkanoidState* arkanoid_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(arkanoid_state == NULL) { ArkanoidState* arkanoid_state = ctx;
return; furi_mutex_acquire(arkanoid_state->mutex, FuriWaitForever);
}
//Initial level draw //Initial level draw
if(!arkanoid_state->initialDraw) { if(!arkanoid_state->initialDraw) {
@ -352,7 +352,7 @@ static void arkanoid_draw_callback(Canvas* const canvas, void* ctx) {
arkanoid_state->score = 0; arkanoid_state->score = 0;
} }
release_mutex((ValueMutex*)ctx, arkanoid_state); furi_mutex_release(arkanoid_state->mutex);
} }
static void arkanoid_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void arkanoid_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -378,8 +378,8 @@ int32_t arkanoid_game_app(void* p) {
ArkanoidState* arkanoid_state = malloc(sizeof(ArkanoidState)); ArkanoidState* arkanoid_state = malloc(sizeof(ArkanoidState));
arkanoid_state_init(arkanoid_state); arkanoid_state_init(arkanoid_state);
ValueMutex state_mutex; arkanoid_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, arkanoid_state, sizeof(ArkanoidState))) { if(!arkanoid_state->mutex) {
FURI_LOG_E(TAG, "Cannot create mutex\r\n"); FURI_LOG_E(TAG, "Cannot create mutex\r\n");
return_code = 255; return_code = 255;
goto free_and_exit; goto free_and_exit;
@ -387,7 +387,7 @@ int32_t arkanoid_game_app(void* p) {
// Set system callbacks // Set system callbacks
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, arkanoid_draw_callback, &state_mutex); view_port_draw_callback_set(view_port, arkanoid_draw_callback, arkanoid_state);
view_port_input_callback_set(view_port, arkanoid_input_callback, event_queue); view_port_input_callback_set(view_port, arkanoid_input_callback, event_queue);
FuriTimer* timer = FuriTimer* timer =
@ -404,7 +404,7 @@ int32_t arkanoid_game_app(void* p) {
GameEvent event; GameEvent event;
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
ArkanoidState* arkanoid_state = (ArkanoidState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(arkanoid_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
// Key events // Key events
@ -461,7 +461,7 @@ int32_t arkanoid_game_app(void* p) {
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, arkanoid_state); furi_mutex_release(arkanoid_state->mutex);
} }
furi_timer_free(timer); furi_timer_free(timer);
view_port_enabled_set(view_port, false); view_port_enabled_set(view_port, false);
@ -469,7 +469,7 @@ int32_t arkanoid_game_app(void* p) {
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
furi_record_close(RECORD_NOTIFICATION); furi_record_close(RECORD_NOTIFICATION);
view_port_free(view_port); view_port_free(view_port);
delete_mutex(&state_mutex); furi_mutex_free(arkanoid_state->mutex);
free_and_exit: free_and_exit:
free(arkanoid_state); free(arkanoid_state);

View file

@ -130,10 +130,9 @@ int calculate_check_digit(PluginState* plugin_state, BarcodeType* type) {
} }
static void render_callback(Canvas* const canvas, void* ctx) { static void render_callback(Canvas* const canvas, void* ctx) {
PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(plugin_state == NULL) { PluginState* plugin_state = ctx;
return; furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
}
if(plugin_state->mode == MenuMode) { if(plugin_state->mode == MenuMode) {
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
@ -239,7 +238,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
canvas_draw_box(canvas, (endSafetyPosition + 2), BARCODE_Y_START, 1, BARCODE_HEIGHT + 2); canvas_draw_box(canvas, (endSafetyPosition + 2), BARCODE_Y_START, 1, BARCODE_HEIGHT + 2);
} }
release_mutex((ValueMutex*)ctx, plugin_state); furi_mutex_release(plugin_state->mutex);
} }
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -387,8 +386,9 @@ int32_t barcode_generator_app(void* p) {
PluginState* plugin_state = malloc(sizeof(PluginState)); PluginState* plugin_state = malloc(sizeof(PluginState));
barcode_generator_state_init(plugin_state); barcode_generator_state_init(plugin_state);
ValueMutex state_mutex;
if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) { plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!plugin_state->mutex) {
FURI_LOG_E("barcode_generator", "cannot create mutex\r\n"); FURI_LOG_E("barcode_generator", "cannot create mutex\r\n");
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
free(plugin_state); free(plugin_state);
@ -397,7 +397,7 @@ int32_t barcode_generator_app(void* p) {
// Set system callbacks // Set system callbacks
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &state_mutex); view_port_draw_callback_set(view_port, render_callback, plugin_state);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
// Open GUI and register view_port // Open GUI and register view_port
@ -407,7 +407,7 @@ int32_t barcode_generator_app(void* p) {
PluginEvent event; PluginEvent event;
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
PluginState* plugin_state = (PluginState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
// press events // press events
@ -430,7 +430,7 @@ int32_t barcode_generator_app(void* p) {
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, plugin_state); furi_mutex_release(plugin_state->mutex);
} }
view_port_enabled_set(view_port, false); view_port_enabled_set(view_port, false);
@ -438,6 +438,7 @@ int32_t barcode_generator_app(void* p) {
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
view_port_free(view_port); view_port_free(view_port);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
furi_mutex_free(plugin_state->mutex);
// save settings // save settings
SAVE_BARCODE_SETTINGS(&plugin_state->barcode_state); SAVE_BARCODE_SETTINGS(&plugin_state->barcode_state);
free(plugin_state); free(plugin_state);

View file

@ -81,6 +81,7 @@ typedef struct {
} BarcodeState; } BarcodeState;
typedef struct { typedef struct {
FuriMutex* mutex;
BarcodeState barcode_state; BarcodeState barcode_state;
int editingIndex; //The index of the editing symbol int editingIndex; //The index of the editing symbol
int menuIndex; //The index of the menu cursor int menuIndex; //The index of the menu cursor

View file

@ -33,11 +33,9 @@ static void draw_ui(Canvas* const canvas, const GameState* game_state) {
} }
static void render_callback(Canvas* const canvas, void* ctx) { static void render_callback(Canvas* const canvas, void* ctx) {
const GameState* game_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
const GameState* game_state = ctx;
if(game_state == NULL) { furi_mutex_acquire(game_state->mutex, FuriWaitForever);
return;
}
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
canvas_draw_frame(canvas, 0, 0, 128, 64); canvas_draw_frame(canvas, 0, 0, 128, 64);
@ -60,7 +58,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
settings_page(canvas, game_state); settings_page(canvas, game_state);
} }
release_mutex((ValueMutex*)ctx, game_state); furi_mutex_release(game_state->mutex);
} }
//region card draw //region card draw
@ -553,21 +551,21 @@ int32_t blackjack_app(void* p) {
game_state->state = GameStateStart; game_state->state = GameStateStart;
ValueMutex state_mutex; game_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, game_state, sizeof(GameState))) { if(!game_state->mutex) {
FURI_LOG_E(APP_NAME, "cannot create mutex\r\n"); FURI_LOG_E(APP_NAME, "cannot create mutex\r\n");
return_code = 255; return_code = 255;
goto free_and_exit; goto free_and_exit;
} }
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &state_mutex); view_port_draw_callback_set(view_port, render_callback, game_state);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
FuriTimer* timer = furi_timer_alloc(update_timer_callback, FuriTimerTypePeriodic, event_queue); FuriTimer* timer = furi_timer_alloc(update_timer_callback, FuriTimerTypePeriodic, event_queue);
furi_timer_start(timer, furi_kernel_get_tick_frequency() / 25); furi_timer_start(timer, furi_kernel_get_tick_frequency() / 25);
Gui* gui = furi_record_open("gui"); Gui* gui = furi_record_open(RECORD_GUI);
gui_add_view_port(gui, view_port, GuiLayerFullscreen); gui_add_view_port(gui, view_port, GuiLayerFullscreen);
AppEvent event; AppEvent event;
@ -577,47 +575,44 @@ int32_t blackjack_app(void* p) {
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
GameState* localstate = (GameState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(game_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
if(event.type == EventTypeKey) { if(event.type == EventTypeKey) {
if(event.input.type == InputTypePress) { if(event.input.type == InputTypePress) {
switch(event.input.key) { switch(event.input.key) {
case InputKeyUp: case InputKeyUp:
localstate->selectDirection = DirectionUp; game_state->selectDirection = DirectionUp;
break; break;
case InputKeyDown: case InputKeyDown:
localstate->selectDirection = DirectionDown; game_state->selectDirection = DirectionDown;
break; break;
case InputKeyRight: case InputKeyRight:
localstate->selectDirection = DirectionRight; game_state->selectDirection = DirectionRight;
break; break;
case InputKeyLeft: case InputKeyLeft:
localstate->selectDirection = DirectionLeft; game_state->selectDirection = DirectionLeft;
break; break;
case InputKeyBack: case InputKeyBack:
if(localstate->state == GameStateSettings) { if(game_state->state == GameStateSettings) {
localstate->state = GameStateStart; game_state->state = GameStateStart;
save_settings(localstate->settings); save_settings(game_state->settings);
} else } else
processing = false; processing = false;
break; break;
case InputKeyOk: case InputKeyOk:
localstate->selectDirection = Select; game_state->selectDirection = Select;
break; break;
default: default:
break; break;
} }
} }
} else if(event.type == EventTypeTick) { } else if(event.type == EventTypeTick) {
tick(localstate); tick(game_state);
processing = localstate->processing; processing = game_state->processing;
} }
} else {
//FURI_LOG_D(APP_NAME, "osMessageQueue: event timeout");
// event timeout
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, localstate); furi_mutex_release(game_state->mutex);
} }
furi_timer_free(timer); furi_timer_free(timer);
@ -625,7 +620,7 @@ int32_t blackjack_app(void* p) {
gui_remove_view_port(gui, view_port); gui_remove_view_port(gui, view_port);
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
view_port_free(view_port); view_port_free(view_port);
delete_mutex(&state_mutex); furi_mutex_free(game_state->mutex);
free_and_exit: free_and_exit:
free(game_state->deck.cards); free(game_state->deck.cards);

View file

@ -54,6 +54,7 @@ typedef enum {
} Direction; } Direction;
typedef struct { typedef struct {
FuriMutex* mutex;
Card player_cards[21]; Card player_cards[21];
Card dealer_cards[21]; Card dealer_cards[21];
uint8_t player_card_count; uint8_t player_card_count;

View file

@ -38,6 +38,7 @@ typedef struct {
} PluginEvent; } PluginEvent;
typedef struct { typedef struct {
FuriMutex* mutex;
Player player; Player player;
Entity entity[MAX_ENTITIES]; Entity entity[MAX_ENTITIES];
StaticEntity static_entity[MAX_STATIC_ENTITIES]; StaticEntity static_entity[MAX_STATIC_ENTITIES];
@ -765,10 +766,9 @@ void loopIntro(Canvas* const canvas) {
} }
static void render_callback(Canvas* const canvas, void* ctx) { static void render_callback(Canvas* const canvas, void* ctx) {
PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(plugin_state == NULL) { PluginState* plugin_state = ctx;
return; furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
}
if(plugin_state->init) setupDisplay(canvas); if(plugin_state->init) setupDisplay(canvas);
canvas_set_font(canvas, FontPrimary); canvas_set_font(canvas, FontPrimary);
@ -792,7 +792,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
break; break;
} }
} }
release_mutex((ValueMutex*)ctx, plugin_state); furi_mutex_release(plugin_state->mutex);
} }
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -962,8 +962,8 @@ int32_t doom_app() {
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
PluginState* plugin_state = malloc(sizeof(PluginState)); PluginState* plugin_state = malloc(sizeof(PluginState));
doom_state_init(plugin_state); doom_state_init(plugin_state);
ValueMutex state_mutex; plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) { if(!plugin_state->mutex) {
FURI_LOG_E("Doom_game", "cannot create mutex\r\n"); FURI_LOG_E("Doom_game", "cannot create mutex\r\n");
furi_record_close(RECORD_NOTIFICATION); furi_record_close(RECORD_NOTIFICATION);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
@ -975,11 +975,11 @@ int32_t doom_app() {
furi_timer_start(timer, furi_kernel_get_tick_frequency() / 12); furi_timer_start(timer, furi_kernel_get_tick_frequency() / 12);
// Set system callbacks // Set system callbacks
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &state_mutex); view_port_draw_callback_set(view_port, render_callback, plugin_state);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
// Open GUI and register view_port // Open GUI and register view_port
Gui* gui = furi_record_open("gui"); Gui* gui = furi_record_open(RECORD_GUI);
gui_add_view_port(gui, view_port, GuiLayerFullscreen); gui_add_view_port(gui, view_port, GuiLayerFullscreen);
////////////////////////////////// //////////////////////////////////
@ -995,7 +995,7 @@ int32_t doom_app() {
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
PluginState* plugin_state = (PluginState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
#ifdef SOUND #ifdef SOUND
furi_check( furi_check(
furi_mutex_acquire(plugin_state->music_instance->model_mutex, FuriWaitForever) == furi_mutex_acquire(plugin_state->music_instance->model_mutex, FuriWaitForever) ==
@ -1085,7 +1085,7 @@ int32_t doom_app() {
furi_mutex_release(plugin_state->music_instance->model_mutex); furi_mutex_release(plugin_state->music_instance->model_mutex);
#endif #endif
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, plugin_state); furi_mutex_release(plugin_state->mutex);
} }
#ifdef SOUND #ifdef SOUND
music_player_worker_free(plugin_state->music_instance->worker); music_player_worker_free(plugin_state->music_instance->worker);
@ -1097,8 +1097,9 @@ int32_t doom_app() {
furi_timer_free(timer); furi_timer_free(timer);
view_port_enabled_set(view_port, false); view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port); gui_remove_view_port(gui, view_port);
furi_record_close("gui"); furi_record_close(RECORD_GUI);
view_port_free(view_port); view_port_free(view_port);
furi_mutex_free(plugin_state->mutex);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
free(plugin_state); free(plugin_state);
return 0; return 0;

View file

@ -62,6 +62,7 @@ typedef struct SGpioButtons {
} SGpioButtons; } SGpioButtons;
typedef struct SWiFiDeauthApp { typedef struct SWiFiDeauthApp {
FuriMutex* mutex;
Gui* m_gui; Gui* m_gui;
FuriThread* m_worker_thread; FuriThread* m_worker_thread;
//NotificationApp* m_notification; //NotificationApp* m_notification;
@ -121,10 +122,9 @@ static void esp8266_deauth_app_init(SWiFiDeauthApp* const app) {
} }
static void esp8266_deauth_module_render_callback(Canvas* const canvas, void* ctx) { static void esp8266_deauth_module_render_callback(Canvas* const canvas, void* ctx) {
SWiFiDeauthApp* app = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(app == NULL) { SWiFiDeauthApp* app = ctx;
return; furi_mutex_acquire(app->mutex, FuriWaitForever);
}
//if(app->m_needUpdateGUI) //if(app->m_needUpdateGUI)
//{ //{
@ -206,7 +206,7 @@ static void esp8266_deauth_module_render_callback(Canvas* const canvas, void* ct
break; break;
} }
release_mutex((ValueMutex*)ctx, app); furi_mutex_release(app->mutex);
} }
static void static void
@ -235,14 +235,15 @@ static int32_t uart_worker(void* context) {
furi_assert(context); furi_assert(context);
DEAUTH_APP_LOG_I("[UART] Worker thread init"); DEAUTH_APP_LOG_I("[UART] Worker thread init");
SWiFiDeauthApp* app = acquire_mutex((ValueMutex*)context, 25); SWiFiDeauthApp* app = context;
furi_mutex_acquire(app->mutex, FuriWaitForever);
if(app == NULL) { if(app == NULL) {
return 1; return 1;
} }
FuriStreamBuffer* rx_stream = app->m_rx_stream; FuriStreamBuffer* rx_stream = app->m_rx_stream;
release_mutex((ValueMutex*)context, app); furi_mutex_release(app->mutex);
#if ENABLE_MODULE_POWER #if ENABLE_MODULE_POWER
bool initialized = false; bool initialized = false;
@ -259,7 +260,8 @@ static int32_t uart_worker(void* context) {
if(events & WorkerEventStop) break; if(events & WorkerEventStop) break;
if(events & WorkerEventRx) { if(events & WorkerEventRx) {
DEAUTH_APP_LOG_I("[UART] Received data"); DEAUTH_APP_LOG_I("[UART] Received data");
SWiFiDeauthApp* app = acquire_mutex((ValueMutex*)context, 25); SWiFiDeauthApp* app = context;
furi_mutex_acquire(app->mutex, FuriWaitForever);
if(app == NULL) { if(app == NULL) {
return 1; return 1;
} }
@ -307,7 +309,7 @@ static int32_t uart_worker(void* context) {
} }
#endif // ENABLE_MODULE_POWER #endif // ENABLE_MODULE_POWER
release_mutex((ValueMutex*)context, app); furi_mutex_release(app->mutex);
} }
} }
@ -356,8 +358,8 @@ int32_t esp8266_deauth_app(void* p) {
#endif #endif
#endif // ENABLE_MODULE_DETECTION #endif // ENABLE_MODULE_DETECTION
ValueMutex app_data_mutex; app->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&app_data_mutex, app, sizeof(SWiFiDeauthApp))) { if(!app->mutex) {
DEAUTH_APP_LOG_E("cannot create mutex\r\n"); DEAUTH_APP_LOG_E("cannot create mutex\r\n");
free(app); free(app);
return 255; return 255;
@ -365,10 +367,10 @@ int32_t esp8266_deauth_app(void* p) {
DEAUTH_APP_LOG_I("Mutex created"); DEAUTH_APP_LOG_I("Mutex created");
//app->m_notification = furi_record_open("notification"); //app->m_notification = furi_record_open(RECORD_NOTIFICATION);
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, esp8266_deauth_module_render_callback, &app_data_mutex); view_port_draw_callback_set(view_port, esp8266_deauth_module_render_callback, app);
view_port_input_callback_set(view_port, esp8266_deauth_module_input_callback, event_queue); view_port_input_callback_set(view_port, esp8266_deauth_module_input_callback, event_queue);
// Open GUI and register view_port // Open GUI and register view_port
@ -382,7 +384,7 @@ int32_t esp8266_deauth_app(void* p) {
app->m_worker_thread = furi_thread_alloc(); app->m_worker_thread = furi_thread_alloc();
furi_thread_set_name(app->m_worker_thread, "WiFiDeauthModuleUARTWorker"); furi_thread_set_name(app->m_worker_thread, "WiFiDeauthModuleUARTWorker");
furi_thread_set_stack_size(app->m_worker_thread, 1 * 1024); furi_thread_set_stack_size(app->m_worker_thread, 1 * 1024);
furi_thread_set_context(app->m_worker_thread, &app_data_mutex); furi_thread_set_context(app->m_worker_thread, app);
furi_thread_set_callback(app->m_worker_thread, uart_worker); furi_thread_set_callback(app->m_worker_thread, uart_worker);
furi_thread_start(app->m_worker_thread); furi_thread_start(app->m_worker_thread);
DEAUTH_APP_LOG_I("UART thread allocated"); DEAUTH_APP_LOG_I("UART thread allocated");
@ -398,7 +400,7 @@ int32_t esp8266_deauth_app(void* p) {
SPluginEvent event; SPluginEvent event;
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
SWiFiDeauthApp* app = (SWiFiDeauthApp*)acquire_mutex_block(&app_data_mutex); furi_mutex_acquire(app->mutex, FuriWaitForever);
#if ENABLE_MODULE_DETECTION #if ENABLE_MODULE_DETECTION
if(!app->m_wifiDeauthModuleAttached) { if(!app->m_wifiDeauthModuleAttached) {
@ -484,7 +486,7 @@ int32_t esp8266_deauth_app(void* p) {
#endif #endif
view_port_update(view_port); view_port_update(view_port);
release_mutex(&app_data_mutex, app); furi_mutex_release(app->mutex);
} }
DEAUTH_APP_LOG_I("Start exit app"); DEAUTH_APP_LOG_I("Start exit app");
@ -514,7 +516,7 @@ int32_t esp8266_deauth_app(void* p) {
// Close gui record // Close gui record
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
furi_record_close("notification"); //furi_record_close(RECORD_NOTIFICATION);
app->m_gui = NULL; app->m_gui = NULL;
view_port_free(view_port); view_port_free(view_port);
@ -523,7 +525,7 @@ int32_t esp8266_deauth_app(void* p) {
furi_stream_buffer_free(app->m_rx_stream); furi_stream_buffer_free(app->m_rx_stream);
delete_mutex(&app_data_mutex); furi_mutex_free(app->mutex);
// Free rest // Free rest
free(app); free(app);

View file

@ -60,6 +60,7 @@ typedef struct {
PILAR pilars[FLAPPY_PILAR_MAX]; PILAR pilars[FLAPPY_PILAR_MAX];
bool debug; bool debug;
State state; State state;
FuriMutex* mutex;
} GameState; } GameState;
typedef struct { typedef struct {
@ -175,10 +176,9 @@ static void flappy_game_flap(GameState* const game_state) {
} }
static void flappy_game_render_callback(Canvas* const canvas, void* ctx) { static void flappy_game_render_callback(Canvas* const canvas, void* ctx) {
const GameState* game_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(game_state == NULL) { const GameState* game_state = ctx;
return; furi_mutex_acquire(game_state->mutex, FuriWaitForever);
}
canvas_draw_frame(canvas, 0, 0, 128, 64); canvas_draw_frame(canvas, 0, 0, 128, 64);
@ -262,7 +262,7 @@ static void flappy_game_render_callback(Canvas* const canvas, void* ctx) {
canvas_draw_str_aligned(canvas, 64, 41, AlignCenter, AlignBottom, buffer); canvas_draw_str_aligned(canvas, 64, 41, AlignCenter, AlignBottom, buffer);
} }
release_mutex((ValueMutex*)ctx, game_state); furi_mutex_release(game_state->mutex);
} }
static void flappy_game_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void flappy_game_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -288,8 +288,8 @@ int32_t flappy_game_app(void* p) {
GameState* game_state = malloc(sizeof(GameState)); GameState* game_state = malloc(sizeof(GameState));
flappy_game_state_init(game_state); flappy_game_state_init(game_state);
ValueMutex state_mutex; game_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, game_state, sizeof(GameState))) { if(!game_state->mutex) {
FURI_LOG_E(TAG, "cannot create mutex\r\n"); FURI_LOG_E(TAG, "cannot create mutex\r\n");
return_code = 255; return_code = 255;
goto free_and_exit; goto free_and_exit;
@ -297,7 +297,7 @@ int32_t flappy_game_app(void* p) {
// Set system callbacks // Set system callbacks
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, flappy_game_render_callback, &state_mutex); view_port_draw_callback_set(view_port, flappy_game_render_callback, game_state);
view_port_input_callback_set(view_port, flappy_game_input_callback, event_queue); view_port_input_callback_set(view_port, flappy_game_input_callback, event_queue);
FuriTimer* timer = FuriTimer* timer =
@ -314,7 +314,7 @@ int32_t flappy_game_app(void* p) {
GameEvent event; GameEvent event;
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
GameState* game_state = (GameState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(game_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
// press events // press events
@ -356,7 +356,7 @@ int32_t flappy_game_app(void* p) {
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, game_state); furi_mutex_release(game_state->mutex);
} }
furi_timer_free(timer); furi_timer_free(timer);
@ -364,7 +364,7 @@ int32_t flappy_game_app(void* p) {
gui_remove_view_port(gui, view_port); gui_remove_view_port(gui, view_port);
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
view_port_free(view_port); view_port_free(view_port);
delete_mutex(&state_mutex); furi_mutex_free(game_state->mutex);
free_and_exit: free_and_exit:
flappy_game_state_free(game_state); flappy_game_state_free(game_state);

View file

@ -9,11 +9,9 @@
#define RFIDFUZZER_APP_FOLDER "/ext/rfidfuzzer" #define RFIDFUZZER_APP_FOLDER "/ext/rfidfuzzer"
static void flipfrid_draw_callback(Canvas* const canvas, void* ctx) { static void flipfrid_draw_callback(Canvas* const canvas, void* ctx) {
FlipFridState* flipfrid_state = (FlipFridState*)acquire_mutex((ValueMutex*)ctx, 100); furi_assert(ctx);
FlipFridState* flipfrid_state = ctx;
if(flipfrid_state == NULL) { furi_mutex_acquire(flipfrid_state->mutex, FuriWaitForever);
return;
}
// Draw correct Canvas // Draw correct Canvas
switch(flipfrid_state->current_scene) { switch(flipfrid_state->current_scene) {
@ -35,7 +33,7 @@ static void flipfrid_draw_callback(Canvas* const canvas, void* ctx) {
break; break;
} }
release_mutex((ValueMutex*)ctx, flipfrid_state); furi_mutex_release(flipfrid_state->mutex);
} }
void flipfrid_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { void flipfrid_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -116,11 +114,9 @@ int32_t flipfrid_start(void* p) {
FURI_LOG_I(TAG, "Initializing input"); FURI_LOG_I(TAG, "Initializing input");
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(FlipFridEvent)); FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(FlipFridEvent));
FlipFridState* flipfrid_state = flipfrid_alloc(); FlipFridState* flipfrid_state = flipfrid_alloc();
ValueMutex flipfrid_state_mutex;
// Mutex flipfrid_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
FURI_LOG_I(TAG, "Initializing flipfrid mutex"); if(!flipfrid_state->mutex) {
if(!init_mutex(&flipfrid_state_mutex, flipfrid_state, sizeof(FlipFridState))) {
FURI_LOG_E(TAG, "cannot create mutex\r\n"); FURI_LOG_E(TAG, "cannot create mutex\r\n");
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
furi_record_close(RECORD_NOTIFICATION); furi_record_close(RECORD_NOTIFICATION);
@ -137,7 +133,7 @@ int32_t flipfrid_start(void* p) {
// Configure view port // Configure view port
FURI_LOG_I(TAG, "Initializing viewport"); FURI_LOG_I(TAG, "Initializing viewport");
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, flipfrid_draw_callback, &flipfrid_state_mutex); view_port_draw_callback_set(view_port, flipfrid_draw_callback, flipfrid_state);
view_port_input_callback_set(view_port, flipfrid_input_callback, event_queue); view_port_input_callback_set(view_port, flipfrid_input_callback, event_queue);
// Configure timer // Configure timer
@ -258,6 +254,7 @@ int32_t flipfrid_start(void* p) {
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
furi_record_close(RECORD_NOTIFICATION); furi_record_close(RECORD_NOTIFICATION);
furi_mutex_free(flipfrid_state->mutex);
flipfrid_free(flipfrid_state); flipfrid_free(flipfrid_state);
return 0; return 0;

View file

@ -58,6 +58,7 @@ typedef struct {
// STRUCTS // STRUCTS
typedef struct { typedef struct {
FuriMutex* mutex;
bool is_running; bool is_running;
bool is_attacking; bool is_attacking;
FlipFridScene current_scene; FlipFridScene current_scene;

View file

@ -1,7 +1,9 @@
#include "i2ctools_i.h" #include "i2ctools_i.h"
void i2ctools_draw_callback(Canvas* canvas, void* ctx) { void i2ctools_draw_callback(Canvas* canvas, void* ctx) {
i2cTools* i2ctools = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
i2cTools* i2ctools = ctx;
furi_mutex_acquire(i2ctools->mutex, FuriWaitForever);
switch(i2ctools->main_view->current_view) { switch(i2ctools->main_view->current_view) {
case MAIN_VIEW: case MAIN_VIEW:
@ -23,7 +25,7 @@ void i2ctools_draw_callback(Canvas* canvas, void* ctx) {
default: default:
break; break;
} }
release_mutex((ValueMutex*)ctx, i2ctools); furi_mutex_release(i2ctools->mutex);
} }
void i2ctools_input_callback(InputEvent* input_event, void* ctx) { void i2ctools_input_callback(InputEvent* input_event, void* ctx) {
@ -38,8 +40,8 @@ int32_t i2ctools_app(void* p) {
// Alloc i2ctools // Alloc i2ctools
i2cTools* i2ctools = malloc(sizeof(i2cTools)); i2cTools* i2ctools = malloc(sizeof(i2cTools));
ValueMutex i2ctools_mutex; i2ctools->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&i2ctools_mutex, i2ctools, sizeof(i2cTools))) { if(!i2ctools->mutex) {
FURI_LOG_E(APP_NAME, "cannot create mutex\r\n"); FURI_LOG_E(APP_NAME, "cannot create mutex\r\n");
free(i2ctools); free(i2ctools);
return -1; return -1;
@ -47,7 +49,7 @@ int32_t i2ctools_app(void* p) {
// Alloc viewport // Alloc viewport
i2ctools->view_port = view_port_alloc(); i2ctools->view_port = view_port_alloc();
view_port_draw_callback_set(i2ctools->view_port, i2ctools_draw_callback, &i2ctools_mutex); view_port_draw_callback_set(i2ctools->view_port, i2ctools_draw_callback, i2ctools);
view_port_input_callback_set(i2ctools->view_port, i2ctools_input_callback, event_queue); view_port_input_callback_set(i2ctools->view_port, i2ctools_input_callback, event_queue);
// Register view port in GUI // Register view port in GUI
@ -216,6 +218,7 @@ int32_t i2ctools_app(void* p) {
i2c_scanner_free(i2ctools->scanner); i2c_scanner_free(i2ctools->scanner);
i2c_sender_free(i2ctools->sender); i2c_sender_free(i2ctools->sender);
i2c_main_view_free(i2ctools->main_view); i2c_main_view_free(i2ctools->main_view);
furi_mutex_free(i2ctools->mutex);
free(i2ctools); free(i2ctools);
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
return 0; return 0;

View file

@ -13,6 +13,7 @@
// App datas // App datas
typedef struct { typedef struct {
FuriMutex* mutex;
ViewPort* view_port; ViewPort* view_port;
i2cMainView* main_view; i2cMainView* main_view;

View file

@ -34,6 +34,7 @@ typedef enum {
} State; } State;
typedef struct { typedef struct {
FuriMutex* mutex;
State state; State state;
uint8_t table[CELLS_COUNT][CELLS_COUNT]; uint8_t table[CELLS_COUNT][CELLS_COUNT];
uint32_t score; uint32_t score;
@ -104,8 +105,9 @@ static void gray_canvas(Canvas* const canvas) {
} }
static void draw_callback(Canvas* const canvas, void* ctx) { static void draw_callback(Canvas* const canvas, void* ctx) {
const GameState* game_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(game_state == NULL) return; const GameState* game_state = ctx;
furi_mutex_acquire(game_state->mutex, FuriWaitForever);
canvas_clear(canvas); canvas_clear(canvas);
@ -181,7 +183,7 @@ static void draw_callback(Canvas* const canvas, void* ctx) {
canvas_draw_str_aligned(canvas, 64, 48, AlignCenter, AlignBottom, buf); canvas_draw_str_aligned(canvas, 64, 48, AlignCenter, AlignBottom, buf);
} }
release_mutex((ValueMutex*)ctx, game_state); furi_mutex_release(game_state->mutex);
} }
void calculate_move_to_left(uint8_t arr[], MoveResult* const move_result) { void calculate_move_to_left(uint8_t arr[], MoveResult* const move_result) {
@ -381,8 +383,8 @@ int32_t game_2048_app() {
MoveResult* move_result = malloc(sizeof(MoveResult)); MoveResult* move_result = malloc(sizeof(MoveResult));
ValueMutex state_mutex; game_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, game_state, sizeof(GameState))) { if(!game_state->mutex) {
FURI_LOG_E("2048Game", "cannot create mutex\r\n"); FURI_LOG_E("2048Game", "cannot create mutex\r\n");
free(game_state); free(game_state);
return 255; return 255;
@ -392,7 +394,7 @@ int32_t game_2048_app() {
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, draw_callback, &state_mutex); view_port_draw_callback_set(view_port, draw_callback, game_state);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
Gui* gui = furi_record_open(RECORD_GUI); Gui* gui = furi_record_open(RECORD_GUI);
@ -408,7 +410,7 @@ int32_t game_2048_app() {
// handle only press event, ignore repeat/release events // handle only press event, ignore repeat/release events
if(input.type != InputTypePress) continue; if(input.type != InputTypePress) continue;
GameState* game_state = (GameState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(game_state->mutex, FuriWaitForever);
switch(game_state->state) { switch(game_state->state) {
case GameStateMenu: case GameStateMenu:
@ -493,7 +495,7 @@ int32_t game_2048_app() {
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, game_state); furi_mutex_release(game_state->mutex);
} }
} }
@ -504,7 +506,7 @@ int32_t game_2048_app() {
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
delete_mutex(&state_mutex); furi_mutex_free(game_state->mutex);
free(game_state); free(game_state);
free(move_result); free(move_result);

View file

@ -15,10 +15,9 @@ typedef struct {
} PluginEvent; } PluginEvent;
static void render_callback(Canvas* const canvas, void* context) { static void render_callback(Canvas* const canvas, void* context) {
const GpsUart* gps_uart = acquire_mutex((ValueMutex*)context, 25); furi_assert(context);
if(gps_uart == NULL) { const GpsUart* gps_uart = context;
return; furi_mutex_acquire(gps_uart->mutex, FuriWaitForever);
}
canvas_set_font(canvas, FontPrimary); canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 32, 8, AlignCenter, AlignBottom, "Latitude"); canvas_draw_str_aligned(canvas, 32, 8, AlignCenter, AlignBottom, "Latitude");
@ -57,7 +56,7 @@ static void render_callback(Canvas* const canvas, void* context) {
gps_uart->status.time_seconds); gps_uart->status.time_seconds);
canvas_draw_str_aligned(canvas, 96, 62, AlignCenter, AlignBottom, buffer); canvas_draw_str_aligned(canvas, 96, 62, AlignCenter, AlignBottom, buffer);
release_mutex((ValueMutex*)context, gps_uart); furi_mutex_release(gps_uart->mutex);
} }
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -74,8 +73,8 @@ int32_t gps_app(void* p) {
GpsUart* gps_uart = gps_uart_enable(); GpsUart* gps_uart = gps_uart_enable();
ValueMutex gps_uart_mutex; gps_uart->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&gps_uart_mutex, gps_uart, sizeof(GpsUart))) { if(!gps_uart->mutex) {
FURI_LOG_E("GPS", "cannot create mutex\r\n"); FURI_LOG_E("GPS", "cannot create mutex\r\n");
free(gps_uart); free(gps_uart);
return 255; return 255;
@ -83,18 +82,18 @@ int32_t gps_app(void* p) {
// set system callbacks // set system callbacks
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &gps_uart_mutex); view_port_draw_callback_set(view_port, render_callback, gps_uart);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
// open GUI and register view_port // open GUI and register view_port
Gui* gui = furi_record_open("gui"); Gui* gui = furi_record_open(RECORD_GUI);
gui_add_view_port(gui, view_port, GuiLayerFullscreen); gui_add_view_port(gui, view_port, GuiLayerFullscreen);
PluginEvent event; PluginEvent event;
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
GpsUart* gps_uart = (GpsUart*)acquire_mutex_block(&gps_uart_mutex); furi_mutex_acquire(gps_uart->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
// press events // press events
@ -118,15 +117,15 @@ int32_t gps_app(void* p) {
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&gps_uart_mutex, gps_uart); furi_mutex_release(gps_uart->mutex);
} }
view_port_enabled_set(view_port, false); view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port); gui_remove_view_port(gui, view_port);
furi_record_close("gui"); furi_record_close(RECORD_GUI);
view_port_free(view_port); view_port_free(view_port);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
delete_mutex(&gps_uart_mutex); furi_mutex_free(gps_uart->mutex);
gps_uart_disable(gps_uart); gps_uart_disable(gps_uart);
return 0; return 0;

View file

@ -22,6 +22,7 @@ typedef struct {
} GpsStatus; } GpsStatus;
typedef struct { typedef struct {
FuriMutex* mutex;
FuriThread* thread; FuriThread* thread;
FuriStreamBuffer* rx_stream; FuriStreamBuffer* rx_stream;
uint8_t rx_buf[RX_BUF_SIZE]; uint8_t rx_buf[RX_BUF_SIZE];

View file

@ -24,6 +24,7 @@ typedef struct {
} PluginEvent; } PluginEvent;
typedef struct { typedef struct {
FuriMutex* mutex;
NotificationApp* notification; NotificationApp* notification;
bool have_5v; bool have_5v;
bool measurement_made; bool measurement_made;
@ -41,10 +42,10 @@ const NotificationSequence sequence_done = {
}; };
static void render_callback(Canvas* const canvas, void* ctx) { static void render_callback(Canvas* const canvas, void* ctx) {
const PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(plugin_state == NULL) { const PluginState* plugin_state = ctx;
return; furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
}
// border around the edge of the screen // border around the edge of the screen
// canvas_draw_frame(canvas, 0, 0, 128, 64); // canvas_draw_frame(canvas, 0, 0, 128, 64);
@ -85,7 +86,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
} }
} }
release_mutex((ValueMutex*)ctx, plugin_state); furi_mutex_release(plugin_state->mutex);
} }
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -184,8 +185,8 @@ int32_t hc_sr04_app() {
furi_hal_console_disable(); furi_hal_console_disable();
ValueMutex state_mutex; plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) { if(!plugin_state->mutex) {
FURI_LOG_E("hc_sr04", "cannot create mutex\r\n"); FURI_LOG_E("hc_sr04", "cannot create mutex\r\n");
if(furi_hal_power_is_otg_enabled()) { if(furi_hal_power_is_otg_enabled()) {
furi_hal_power_disable_otg(); furi_hal_power_disable_otg();
@ -201,7 +202,7 @@ int32_t hc_sr04_app() {
// Set system callbacks // Set system callbacks
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &state_mutex); view_port_draw_callback_set(view_port, render_callback, plugin_state);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
// Open GUI and register view_port // Open GUI and register view_port
@ -212,7 +213,7 @@ int32_t hc_sr04_app() {
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
PluginState* plugin_state = (PluginState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
// press events // press events
@ -238,7 +239,7 @@ int32_t hc_sr04_app() {
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, plugin_state); furi_mutex_release(plugin_state->mutex);
} }
if(furi_hal_power_is_otg_enabled()) { if(furi_hal_power_is_otg_enabled()) {
@ -267,7 +268,8 @@ int32_t hc_sr04_app() {
furi_record_close(RECORD_NOTIFICATION); furi_record_close(RECORD_NOTIFICATION);
view_port_free(view_port); view_port_free(view_port);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
delete_mutex(&state_mutex); furi_mutex_free(plugin_state->mutex);
free(plugin_state);
return 0; return 0;
} }

View file

@ -87,6 +87,7 @@ typedef struct {
Person* person; Person* person;
Animations animation; Animations animation;
GameStatuses game_status; GameStatuses game_status;
FuriMutex* mutex;
} GameState; } GameState;
typedef Box** Field; typedef Box** Field;
@ -433,15 +434,15 @@ static void draw_box(Canvas* canvas, Box* box, int x, int y) {
static void heap_defense_render_callback(Canvas* const canvas, void* mutex) { static void heap_defense_render_callback(Canvas* const canvas, void* mutex) {
furi_assert(mutex); furi_assert(mutex);
const GameState* game = mutex;
const GameState* game = acquire_mutex((ValueMutex*)mutex, 25); furi_mutex_acquire(game->mutex, FuriWaitForever);
///Draw GameOver or Pause ///Draw GameOver or Pause
if(!(game->game_status & GameStatusInProgress)) { if(!(game->game_status & GameStatusInProgress)) {
FURI_LOG_W(TAG, "[DAED_DRAW]func: [%s] line: %d ", __FUNCTION__, __LINE__); FURI_LOG_W(TAG, "[DAED_DRAW]func: [%s] line: %d ", __FUNCTION__, __LINE__);
canvas_draw_icon_animation(canvas, 0, 0, animations[game->animation]); canvas_draw_icon_animation(canvas, 0, 0, animations[game->animation]);
release_mutex((ValueMutex*)mutex, game); furi_mutex_release(game->mutex);
return; return;
} }
@ -481,7 +482,7 @@ static void heap_defense_render_callback(Canvas* const canvas, void* mutex) {
} }
} }
release_mutex((ValueMutex*)mutex, game); furi_mutex_release(game->mutex);
} }
static void heap_defense_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void heap_defense_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -506,25 +507,25 @@ int32_t heap_defence_app(void* p) {
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(GameEvent)); FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(GameEvent));
GameState* game = allocGameState(); GameState* game = allocGameState();
ValueMutex state_mutex; game->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, game, sizeof(GameState))) { if(!game->mutex) {
game_destroy(game); game_destroy(game);
return 1; return 1;
} }
assets_load(); assets_load();
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, heap_defense_render_callback, &state_mutex); view_port_draw_callback_set(view_port, heap_defense_render_callback, game);
view_port_input_callback_set(view_port, heap_defense_input_callback, event_queue); view_port_input_callback_set(view_port, heap_defense_input_callback, event_queue);
FuriTimer* timer = FuriTimer* timer =
furi_timer_alloc(heap_defense_timer_callback, FuriTimerTypePeriodic, event_queue); furi_timer_alloc(heap_defense_timer_callback, FuriTimerTypePeriodic, event_queue);
furi_timer_start(timer, furi_kernel_get_tick_frequency() / TIMER_UPDATE_FREQ); furi_timer_start(timer, furi_kernel_get_tick_frequency() / TIMER_UPDATE_FREQ);
Gui* gui = furi_record_open("gui"); Gui* gui = furi_record_open(RECORD_GUI);
gui_add_view_port(gui, view_port, GuiLayerFullscreen); gui_add_view_port(gui, view_port, GuiLayerFullscreen);
NotificationApp* notification = furi_record_open("notification"); NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
memset(game->field[Y_LAST], 128, ROW_BYTE_SIZE); memset(game->field[Y_LAST], 128, ROW_BYTE_SIZE);
game->person->p.y -= 2; game->person->p.y -= 2;
@ -540,7 +541,7 @@ int32_t heap_defence_app(void* p) {
continue; continue;
} }
game = (GameState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(game->mutex, FuriWaitForever);
//unset vibration //unset vibration
if(game->game_status & GameStatusVibro) { if(game->game_status & GameStatusVibro) {
@ -577,7 +578,7 @@ int32_t heap_defence_app(void* p) {
notification_message(notification, &sequence_error); notification_message(notification, &sequence_error);
} }
} }
release_mutex(&state_mutex, game); furi_mutex_release(game->mutex);
view_port_update(view_port); view_port_update(view_port);
} }
@ -585,11 +586,11 @@ int32_t heap_defence_app(void* p) {
view_port_enabled_set(view_port, false); view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port); gui_remove_view_port(gui, view_port);
view_port_free(view_port); view_port_free(view_port);
furi_record_close("gui"); furi_record_close(RECORD_GUI);
furi_record_close("notification"); furi_record_close(RECORD_NOTIFICATION);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
assets_clear(); assets_clear();
delete_mutex(&state_mutex); furi_mutex_free(game->mutex);
game_destroy(game); game_destroy(game);
return 0; return 0;

View file

@ -9,11 +9,9 @@
#define IBTNFUZZER_APP_FOLDER "/ext/ibtnfuzzer" #define IBTNFUZZER_APP_FOLDER "/ext/ibtnfuzzer"
static void ibtnfuzzer_draw_callback(Canvas* const canvas, void* ctx) { static void ibtnfuzzer_draw_callback(Canvas* const canvas, void* ctx) {
iBtnFuzzerState* ibtnfuzzer_state = (iBtnFuzzerState*)acquire_mutex((ValueMutex*)ctx, 100); furi_assert(ctx);
iBtnFuzzerState* ibtnfuzzer_state = ctx;
if(ibtnfuzzer_state == NULL) { furi_mutex_acquire(ibtnfuzzer_state->mutex, FuriWaitForever);
return;
}
// Draw correct Canvas // Draw correct Canvas
switch(ibtnfuzzer_state->current_scene) { switch(ibtnfuzzer_state->current_scene) {
@ -35,7 +33,7 @@ static void ibtnfuzzer_draw_callback(Canvas* const canvas, void* ctx) {
break; break;
} }
release_mutex((ValueMutex*)ctx, ibtnfuzzer_state); furi_mutex_release(ibtnfuzzer_state->mutex);
} }
void ibtnfuzzer_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { void ibtnfuzzer_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -120,11 +118,9 @@ int32_t ibtnfuzzer_start(void* p) {
FURI_LOG_I(TAG, "Initializing input"); FURI_LOG_I(TAG, "Initializing input");
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(iBtnFuzzerEvent)); FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(iBtnFuzzerEvent));
iBtnFuzzerState* ibtnfuzzer_state = ibtnfuzzer_alloc(); iBtnFuzzerState* ibtnfuzzer_state = ibtnfuzzer_alloc();
ValueMutex ibtnfuzzer_state_mutex;
// Mutex ibtnfuzzer_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
FURI_LOG_I(TAG, "Initializing ibtnfuzzer mutex"); if(!ibtnfuzzer_state->mutex) {
if(!init_mutex(&ibtnfuzzer_state_mutex, ibtnfuzzer_state, sizeof(iBtnFuzzerState))) {
FURI_LOG_E(TAG, "cannot create mutex\r\n"); FURI_LOG_E(TAG, "cannot create mutex\r\n");
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
furi_record_close(RECORD_NOTIFICATION); furi_record_close(RECORD_NOTIFICATION);
@ -141,7 +137,7 @@ int32_t ibtnfuzzer_start(void* p) {
// Configure view port // Configure view port
FURI_LOG_I(TAG, "Initializing viewport"); FURI_LOG_I(TAG, "Initializing viewport");
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, ibtnfuzzer_draw_callback, &ibtnfuzzer_state_mutex); view_port_draw_callback_set(view_port, ibtnfuzzer_draw_callback, ibtnfuzzer_state);
view_port_input_callback_set(view_port, ibtnfuzzer_input_callback, event_queue); view_port_input_callback_set(view_port, ibtnfuzzer_input_callback, event_queue);
// Configure timer // Configure timer
@ -160,6 +156,7 @@ int32_t ibtnfuzzer_start(void* p) {
while(ibtnfuzzer_state->is_running) { while(ibtnfuzzer_state->is_running) {
// Get next event // Get next event
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 25); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 25);
//furi_mutex_acquire(ibtnfuzzer_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
if(event.evt_type == EventTypeKey) { if(event.evt_type == EventTypeKey) {
//Handle event key //Handle event key
@ -250,6 +247,7 @@ int32_t ibtnfuzzer_start(void* p) {
view_port_update(view_port); view_port_update(view_port);
} }
} }
//furi_mutex_release(ibtnfuzzer_state->mutex);
} }
// Cleanup // Cleanup
@ -262,6 +260,7 @@ int32_t ibtnfuzzer_start(void* p) {
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
furi_record_close(RECORD_NOTIFICATION); furi_record_close(RECORD_NOTIFICATION);
furi_mutex_free(ibtnfuzzer_state->mutex);
ibtnfuzzer_free(ibtnfuzzer_state); ibtnfuzzer_free(ibtnfuzzer_state);
return 0; return 0;

View file

@ -56,6 +56,7 @@ typedef struct {
// STRUCTS // STRUCTS
typedef struct { typedef struct {
FuriMutex* mutex;
bool is_running; bool is_running;
bool is_attacking; bool is_attacking;
iBtnFuzzerScene current_scene; iBtnFuzzerScene current_scene;

View file

@ -1,7 +1,6 @@
#include <furi.h> #include <furi.h>
#include <furi_hal.h> #include <furi_hal.h>
#include <input/input.h> #include <input/input.h>
#include <m-string.h>
#include <stdlib.h> #include <stdlib.h>
#include <gui/gui.h> #include <gui/gui.h>
@ -50,31 +49,33 @@ typedef struct {
enum OutputMode output_mode; enum OutputMode output_mode;
FuriTimer* timer; FuriTimer* timer;
NotificationApp* notifications; NotificationApp* notifications;
FuriMutex* mutex;
} MetronomeState; } MetronomeState;
static void render_callback(Canvas* const canvas, void* ctx) { static void render_callback(Canvas* const canvas, void* ctx) {
const MetronomeState* metronome_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(metronome_state == NULL) { const MetronomeState* metronome_state = ctx;
return; furi_mutex_acquire(metronome_state->mutex, FuriWaitForever);
}
string_t tempStr; FuriString* tempStr = furi_string_alloc();
string_init(tempStr);
canvas_draw_frame(canvas, 0, 0, 128, 64); canvas_draw_frame(canvas, 0, 0, 128, 64);
canvas_set_font(canvas, FontPrimary); canvas_set_font(canvas, FontPrimary);
// draw bars/beat // draw bars/beat
string_printf(tempStr, "%d/%d", metronome_state->beats_per_bar, metronome_state->note_length); furi_string_printf(
canvas_draw_str_aligned(canvas, 64, 8, AlignCenter, AlignCenter, string_get_cstr(tempStr)); tempStr, "%d/%d", metronome_state->beats_per_bar, metronome_state->note_length);
string_reset(tempStr); canvas_draw_str_aligned(
canvas, 64, 8, AlignCenter, AlignCenter, furi_string_get_cstr(tempStr));
furi_string_reset(tempStr);
// draw BPM value // draw BPM value
string_printf(tempStr, "%.2f", metronome_state->bpm); furi_string_printf(tempStr, "%.2f", metronome_state->bpm);
canvas_set_font(canvas, FontBigNumbers); canvas_set_font(canvas, FontBigNumbers);
canvas_draw_str_aligned(canvas, 64, 24, AlignCenter, AlignCenter, string_get_cstr(tempStr)); canvas_draw_str_aligned(
string_reset(tempStr); canvas, 64, 24, AlignCenter, AlignCenter, furi_string_get_cstr(tempStr));
furi_string_reset(tempStr);
// draw volume indicator // draw volume indicator
// always draw first waves // always draw first waves
@ -126,8 +127,8 @@ static void render_callback(Canvas* const canvas, void* ctx) {
canvas, 8, 36, 112, (float)metronome_state->current_beat / metronome_state->beats_per_bar); canvas, 8, 36, 112, (float)metronome_state->current_beat / metronome_state->beats_per_bar);
// cleanup // cleanup
string_clear(tempStr); furi_string_free(tempStr);
release_mutex((ValueMutex*)ctx, metronome_state); furi_mutex_release(metronome_state->mutex);
} }
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -139,7 +140,10 @@ static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queu
static void timer_callback(void* ctx) { static void timer_callback(void* ctx) {
// this is where we go BEEP! // this is where we go BEEP!
MetronomeState* metronome_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
MetronomeState* metronome_state = ctx;
furi_mutex_acquire(metronome_state->mutex, FuriWaitForever);
metronome_state->current_beat++; metronome_state->current_beat++;
if(metronome_state->current_beat > metronome_state->beats_per_bar) { if(metronome_state->current_beat > metronome_state->beats_per_bar) {
metronome_state->current_beat = 1; metronome_state->current_beat = 1;
@ -200,7 +204,7 @@ static void timer_callback(void* ctx) {
} }
notification_message(metronome_state->notifications, &sequence_reset_rgb); notification_message(metronome_state->notifications, &sequence_reset_rgb);
release_mutex((ValueMutex*)ctx, metronome_state); furi_mutex_release(metronome_state->mutex);
} }
static uint32_t state_to_sleep_ticks(MetronomeState* metronome_state) { static uint32_t state_to_sleep_ticks(MetronomeState* metronome_state) {
@ -273,8 +277,8 @@ int32_t metronome_app() {
MetronomeState* metronome_state = malloc(sizeof(MetronomeState)); MetronomeState* metronome_state = malloc(sizeof(MetronomeState));
metronome_state_init(metronome_state); metronome_state_init(metronome_state);
ValueMutex state_mutex; metronome_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, metronome_state, sizeof(MetronomeState))) { if(!metronome_state->mutex) {
FURI_LOG_E("Metronome", "cannot create mutex\r\n"); FURI_LOG_E("Metronome", "cannot create mutex\r\n");
free(metronome_state); free(metronome_state);
return 255; return 255;
@ -282,19 +286,20 @@ int32_t metronome_app() {
// Set system callbacks // Set system callbacks
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &state_mutex); view_port_draw_callback_set(view_port, render_callback, metronome_state);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
metronome_state->timer = furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, &state_mutex); metronome_state->timer =
furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, metronome_state);
// Open GUI and register view_port // Open GUI and register view_port
Gui* gui = furi_record_open("gui"); Gui* gui = furi_record_open(RECORD_GUI);
gui_add_view_port(gui, view_port, GuiLayerFullscreen); gui_add_view_port(gui, view_port, GuiLayerFullscreen);
PluginEvent event; PluginEvent event;
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
MetronomeState* metronome_state = (MetronomeState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(metronome_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
if(event.type == EventTypeKey) { if(event.type == EventTypeKey) {
@ -373,21 +378,18 @@ int32_t metronome_app() {
} }
} }
} }
} else {
FURI_LOG_D("Metronome", "FuriMessageQueue: event timeout");
// event timeout
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, metronome_state); furi_mutex_release(metronome_state->mutex);
} }
view_port_enabled_set(view_port, false); view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port); gui_remove_view_port(gui, view_port);
furi_record_close("gui"); furi_record_close(RECORD_GUI);
view_port_free(view_port); view_port_free(view_port);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
delete_mutex(&state_mutex); furi_mutex_free(metronome_state->mutex);
furi_timer_free(metronome_state->timer); furi_timer_free(metronome_state->timer);
furi_record_close(RECORD_NOTIFICATION); furi_record_close(RECORD_NOTIFICATION);
free(metronome_state); free(metronome_state);

View file

@ -57,6 +57,7 @@ typedef struct {
int flags_set; int flags_set;
bool game_started; bool game_started;
uint32_t game_started_tick; uint32_t game_started_tick;
FuriMutex* mutex;
} Minesweeper; } Minesweeper;
static void timer_callback(void* ctx) { static void timer_callback(void* ctx) {
@ -74,10 +75,10 @@ static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queu
} }
static void render_callback(Canvas* const canvas, void* ctx) { static void render_callback(Canvas* const canvas, void* ctx) {
const Minesweeper* minesweeper_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(minesweeper_state == NULL) { const Minesweeper* minesweeper_state = ctx;
return; furi_mutex_acquire(minesweeper_state->mutex, FuriWaitForever);
}
FuriString* mineStr; FuriString* mineStr;
FuriString* timeStr; FuriString* timeStr;
mineStr = furi_string_alloc(); mineStr = furi_string_alloc();
@ -162,7 +163,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
furi_string_free(mineStr); furi_string_free(mineStr);
furi_string_free(timeStr); furi_string_free(timeStr);
release_mutex((ValueMutex*)ctx, minesweeper_state); furi_mutex_release(minesweeper_state->mutex);
} }
static void setup_playfield(Minesweeper* minesweeper_state) { static void setup_playfield(Minesweeper* minesweeper_state) {
@ -396,8 +397,8 @@ int32_t minesweeper_app(void* p) {
// setup // setup
minesweeper_state_init(minesweeper_state); minesweeper_state_init(minesweeper_state);
ValueMutex state_mutex; minesweeper_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, minesweeper_state, sizeof(minesweeper_state))) { if(!minesweeper_state->mutex) {
FURI_LOG_E("Minesweeper", "cannot create mutex\r\n"); FURI_LOG_E("Minesweeper", "cannot create mutex\r\n");
free(minesweeper_state); free(minesweeper_state);
return 255; return 255;
@ -406,12 +407,13 @@ int32_t minesweeper_app(void* p) {
// Set system callbacks // Set system callbacks
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &state_mutex); view_port_draw_callback_set(view_port, render_callback, minesweeper_state);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
minesweeper_state->timer = furi_timer_alloc(timer_callback, FuriTimerTypeOnce, &state_mutex); minesweeper_state->timer =
furi_timer_alloc(timer_callback, FuriTimerTypeOnce, minesweeper_state);
// Open GUI and register view_port // Open GUI and register view_port
Gui* gui = furi_record_open("gui"); Gui* gui = furi_record_open(RECORD_GUI);
gui_add_view_port(gui, view_port, GuiLayerFullscreen); gui_add_view_port(gui, view_port, GuiLayerFullscreen);
// Call dolphin deed on game start // Call dolphin deed on game start
@ -420,7 +422,7 @@ int32_t minesweeper_app(void* p) {
PluginEvent event; PluginEvent event;
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
Minesweeper* minesweeper_state = (Minesweeper*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(minesweeper_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
// press events // press events
if(event.type == EventTypeKey) { if(event.type == EventTypeKey) {
@ -508,19 +510,16 @@ int32_t minesweeper_app(void* p) {
} }
} }
} }
} else {
// event timeout
;
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, minesweeper_state); furi_mutex_release(minesweeper_state->mutex);
} }
view_port_enabled_set(view_port, false); view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port); gui_remove_view_port(gui, view_port);
furi_record_close("gui"); furi_record_close(RECORD_GUI);
view_port_free(view_port); view_port_free(view_port);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
delete_mutex(&state_mutex); furi_mutex_free(minesweeper_state->mutex);
furi_timer_free(minesweeper_state->timer); furi_timer_free(minesweeper_state->timer);
free(minesweeper_state); free(minesweeper_state);

View file

@ -40,10 +40,10 @@ char target_address_str[12] = "None";
char target_text[30]; char target_text[30];
static void render_callback(Canvas* const canvas, void* ctx) { static void render_callback(Canvas* const canvas, void* ctx) {
const PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(plugin_state == NULL) { const PluginState* plugin_state = ctx;
return; furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
}
// border around the edge of the screen // border around the edge of the screen
canvas_draw_frame(canvas, 0, 0, 128, 64); canvas_draw_frame(canvas, 0, 0, 128, 64);
@ -82,7 +82,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
canvas_draw_str_aligned(canvas, 3, 30, AlignLeft, AlignBottom, "to exit"); canvas_draw_str_aligned(canvas, 3, 30, AlignLeft, AlignBottom, "to exit");
} }
release_mutex((ValueMutex*)ctx, plugin_state); furi_mutex_release(plugin_state->mutex);
} }
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -289,8 +289,8 @@ int32_t mousejacker_app(void* p) {
PluginState* plugin_state = malloc(sizeof(PluginState)); PluginState* plugin_state = malloc(sizeof(PluginState));
mousejacker_state_init(plugin_state); mousejacker_state_init(plugin_state);
ValueMutex state_mutex; plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) { if(!plugin_state->mutex) {
FURI_LOG_E("mousejacker", "cannot create mutex\r\n"); FURI_LOG_E("mousejacker", "cannot create mutex\r\n");
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
free(plugin_state); free(plugin_state);
@ -299,7 +299,7 @@ int32_t mousejacker_app(void* p) {
// Set system callbacks // Set system callbacks
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &state_mutex); view_port_draw_callback_set(view_port, render_callback, plugin_state);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
// Open GUI and register view_port // Open GUI and register view_port
@ -330,7 +330,7 @@ int32_t mousejacker_app(void* p) {
PluginEvent event; PluginEvent event;
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
PluginState* plugin_state = (PluginState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
// press events // press events
@ -380,7 +380,7 @@ int32_t mousejacker_app(void* p) {
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, plugin_state); furi_mutex_release(plugin_state->mutex);
} }
furi_thread_free(plugin_state->mjthread); furi_thread_free(plugin_state->mjthread);
@ -391,6 +391,7 @@ int32_t mousejacker_app(void* p) {
furi_record_close(RECORD_STORAGE); furi_record_close(RECORD_STORAGE);
view_port_free(view_port); view_port_free(view_port);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
furi_mutex_free(plugin_state->mutex);
free(plugin_state); free(plugin_state);
return 0; return 0;

View file

@ -21,6 +21,7 @@ typedef struct {
} MJDuckyKey; } MJDuckyKey;
typedef struct { typedef struct {
FuriMutex* mutex;
bool ducky_err; bool ducky_err;
bool addr_err; bool addr_err;
bool is_thread_running; bool is_thread_running;

View file

@ -8,10 +8,9 @@
#include "multi_converter_mode_select.h" #include "multi_converter_mode_select.h"
static void multi_converter_render_callback(Canvas* const canvas, void* ctx) { static void multi_converter_render_callback(Canvas* const canvas, void* ctx) {
const MultiConverterState* multi_converter_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(multi_converter_state == NULL) { const MultiConverterState* multi_converter_state = ctx;
return; furi_mutex_acquire(multi_converter_state->mutex, FuriWaitForever);
}
if(multi_converter_state->mode == ModeDisplay) { if(multi_converter_state->mode == ModeDisplay) {
multi_converter_mode_display_draw(canvas, multi_converter_state); multi_converter_mode_display_draw(canvas, multi_converter_state);
@ -19,7 +18,7 @@ static void multi_converter_render_callback(Canvas* const canvas, void* ctx) {
multi_converter_mode_select_draw(canvas, multi_converter_state); multi_converter_mode_select_draw(canvas, multi_converter_state);
} }
release_mutex((ValueMutex*)ctx, multi_converter_state); furi_mutex_release(multi_converter_state->mutex);
} }
static void static void
@ -62,8 +61,8 @@ int32_t multi_converter_app(void* p) {
MultiConverterState* multi_converter_state = malloc(sizeof(MultiConverterState)); MultiConverterState* multi_converter_state = malloc(sizeof(MultiConverterState));
// set mutex for plugin state (different threads can access it) // set mutex for plugin state (different threads can access it)
ValueMutex state_mutex; multi_converter_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, multi_converter_state, sizeof(multi_converter_state))) { if(!multi_converter_state->mutex) {
FURI_LOG_E("MultiConverter", "cannot create mutex\r\n"); FURI_LOG_E("MultiConverter", "cannot create mutex\r\n");
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
free(multi_converter_state); free(multi_converter_state);
@ -72,11 +71,11 @@ int32_t multi_converter_app(void* p) {
// register callbacks for drawing and input processing // register callbacks for drawing and input processing
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, multi_converter_render_callback, &state_mutex); view_port_draw_callback_set(view_port, multi_converter_render_callback, multi_converter_state);
view_port_input_callback_set(view_port, multi_converter_input_callback, event_queue); view_port_input_callback_set(view_port, multi_converter_input_callback, event_queue);
// open GUI and register view_port // open GUI and register view_port
Gui* gui = furi_record_open("gui"); Gui* gui = furi_record_open(RECORD_GUI);
gui_add_view_port(gui, view_port, GuiLayerFullscreen); gui_add_view_port(gui, view_port, GuiLayerFullscreen);
multi_converter_init(multi_converter_state); multi_converter_init(multi_converter_state);
@ -85,8 +84,7 @@ int32_t multi_converter_app(void* p) {
MultiConverterEvent event; MultiConverterEvent event;
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
MultiConverterState* multi_converter_state = furi_mutex_acquire(multi_converter_state->mutex, FuriWaitForever);
(MultiConverterState*)acquire_mutex_block(&state_mutex);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
// press events // press events
@ -148,20 +146,18 @@ int32_t multi_converter_app(void* p) {
} else if(multi_converter_state->keyboard_lock) { } else if(multi_converter_state->keyboard_lock) {
multi_converter_state->keyboard_lock = 0; multi_converter_state->keyboard_lock = 0;
} }
} else {
// event timeout
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, multi_converter_state); furi_mutex_release(multi_converter_state->mutex);
} }
view_port_enabled_set(view_port, false); view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port); gui_remove_view_port(gui, view_port);
furi_record_close("gui"); furi_record_close(RECORD_GUI);
view_port_free(view_port); view_port_free(view_port);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
delete_mutex(&state_mutex); furi_mutex_free(multi_converter_state->mutex);
free(multi_converter_state); free(multi_converter_state);
return 0; return 0;

View file

@ -70,6 +70,7 @@ struct MultiConverterUnit {
}; };
struct MultiConverterState { struct MultiConverterState {
FuriMutex* mutex;
char buffer_orig[MULTI_CONVERTER_NUMBER_DIGITS + 1]; char buffer_orig[MULTI_CONVERTER_NUMBER_DIGITS + 1];
char buffer_dest[MULTI_CONVERTER_NUMBER_DIGITS + 1]; char buffer_dest[MULTI_CONVERTER_NUMBER_DIGITS + 1];
MultiConverterUnitType unit_type_orig; MultiConverterUnitType unit_type_orig;

View file

@ -29,8 +29,7 @@ typedef struct {
} PluginEvent; } PluginEvent;
typedef struct { typedef struct {
int x; FuriMutex* mutex;
int y;
} PluginState; } PluginState;
char rate_text_fmt[] = "Transfer rate: %dMbps"; char rate_text_fmt[] = "Transfer rate: %dMbps";
@ -96,13 +95,13 @@ static void insert_addr(uint8_t* addr, uint8_t addr_size) {
} }
static void render_callback(Canvas* const canvas, void* ctx) { static void render_callback(Canvas* const canvas, void* ctx) {
furi_assert(ctx);
const PluginState* plugin_state = ctx;
furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
uint8_t rate = 2; uint8_t rate = 2;
char sniffing[] = "Yes"; char sniffing[] = "Yes";
const PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25);
if(plugin_state == NULL) {
return;
}
// border around the edge of the screen // border around the edge of the screen
canvas_draw_frame(canvas, 0, 0, 128, 64); canvas_draw_frame(canvas, 0, 0, 128, 64);
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
@ -126,7 +125,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
canvas_draw_str_aligned(canvas, 30, 50, AlignLeft, AlignBottom, addresses_header_text); canvas_draw_str_aligned(canvas, 30, 50, AlignLeft, AlignBottom, addresses_header_text);
canvas_draw_str_aligned(canvas, 30, 60, AlignLeft, AlignBottom, sniffed_address); canvas_draw_str_aligned(canvas, 30, 60, AlignLeft, AlignBottom, sniffed_address);
release_mutex((ValueMutex*)ctx, plugin_state); furi_mutex_release(plugin_state->mutex);
} }
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -320,8 +319,8 @@ int32_t nrfsniff_app(void* p) {
hexlify(address, 5, top_address); hexlify(address, 5, top_address);
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
PluginState* plugin_state = malloc(sizeof(PluginState)); PluginState* plugin_state = malloc(sizeof(PluginState));
ValueMutex state_mutex; plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) { if(!plugin_state->mutex) {
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
FURI_LOG_E(TAG, "cannot create mutex\r\n"); FURI_LOG_E(TAG, "cannot create mutex\r\n");
free(plugin_state); free(plugin_state);
@ -332,7 +331,7 @@ int32_t nrfsniff_app(void* p) {
// Set system callbacks // Set system callbacks
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &state_mutex); view_port_draw_callback_set(view_port, render_callback, plugin_state);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
// Open GUI and register view_port // Open GUI and register view_port
@ -347,7 +346,7 @@ int32_t nrfsniff_app(void* p) {
PluginEvent event; PluginEvent event;
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
PluginState* plugin_state = (PluginState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
// press events // press events
@ -435,7 +434,7 @@ int32_t nrfsniff_app(void* p) {
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, plugin_state); furi_mutex_release(plugin_state->mutex);
} }
clear_cache(); clear_cache();
@ -450,6 +449,7 @@ int32_t nrfsniff_app(void* p) {
furi_record_close(RECORD_STORAGE); furi_record_close(RECORD_STORAGE);
view_port_free(view_port); view_port_free(view_port);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
furi_mutex_free(plugin_state->mutex);
free(plugin_state); free(plugin_state);
return 0; return 0;

View file

@ -7,6 +7,7 @@
typedef struct { typedef struct {
uint8_t status; uint8_t status;
FuriMutex* mutex;
} SentryState; } SentryState;
typedef enum { typedef enum {
@ -22,10 +23,9 @@ typedef struct {
const char* status_texts[3] = {"[Press OK to open safe]", "Sending...", "Done !"}; const char* status_texts[3] = {"[Press OK to open safe]", "Sending...", "Done !"};
static void sentry_safe_render_callback(Canvas* const canvas, void* ctx) { static void sentry_safe_render_callback(Canvas* const canvas, void* ctx) {
const SentryState* sentry_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(sentry_state == NULL) { const SentryState* sentry_state = ctx;
return; furi_mutex_acquire(sentry_state->mutex, FuriWaitForever);
}
// Before the function is called, the state is set with the canvas_reset(canvas) // Before the function is called, the state is set with the canvas_reset(canvas)
@ -41,7 +41,7 @@ static void sentry_safe_render_callback(Canvas* const canvas, void* ctx) {
canvas_draw_str_aligned( canvas_draw_str_aligned(
canvas, 64, 50, AlignCenter, AlignBottom, status_texts[sentry_state->status]); canvas, 64, 50, AlignCenter, AlignBottom, status_texts[sentry_state->status]);
release_mutex((ValueMutex*)ctx, sentry_state); furi_mutex_release(sentry_state->mutex);
} }
static void sentry_safe_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void sentry_safe_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -89,8 +89,8 @@ int32_t sentry_safe_app(void* p) {
sentry_state->status = 0; sentry_state->status = 0;
ValueMutex state_mutex; sentry_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, sentry_state, sizeof(SentryState))) { if(!sentry_state->mutex) {
FURI_LOG_E("SentrySafe", "cannot create mutex\r\n"); FURI_LOG_E("SentrySafe", "cannot create mutex\r\n");
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
free(sentry_state); free(sentry_state);
@ -98,7 +98,7 @@ int32_t sentry_safe_app(void* p) {
} }
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, sentry_safe_render_callback, &state_mutex); view_port_draw_callback_set(view_port, sentry_safe_render_callback, sentry_state);
view_port_input_callback_set(view_port, sentry_safe_input_callback, event_queue); view_port_input_callback_set(view_port, sentry_safe_input_callback, event_queue);
// Open GUI and register view_port // Open GUI and register view_port
@ -109,7 +109,7 @@ int32_t sentry_safe_app(void* p) {
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
SentryState* sentry_state = (SentryState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(sentry_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
// press events // press events
@ -151,7 +151,7 @@ int32_t sentry_safe_app(void* p) {
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, sentry_state); furi_mutex_release(sentry_state->mutex);
} }
// Reset GPIO pins to default state // Reset GPIO pins to default state
@ -162,7 +162,7 @@ int32_t sentry_safe_app(void* p) {
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
view_port_free(view_port); view_port_free(view_port);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
delete_mutex(&state_mutex); furi_mutex_free(sentry_state->mutex);
free(sentry_state); free(sentry_state);
return 0; return 0;

View file

@ -53,4 +53,5 @@ typedef struct {
int8_t selected_card; int8_t selected_card;
CardAnimation animation; CardAnimation animation;
uint8_t* buffer; uint8_t* buffer;
FuriMutex* mutex;
} GameState; } GameState;

View file

@ -155,10 +155,9 @@ static void draw_animation(Canvas* const canvas, const GameState* game_state) {
} }
static void render_callback(Canvas* const canvas, void* ctx) { static void render_callback(Canvas* const canvas, void* ctx) {
const GameState* game_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(game_state == NULL) { const GameState* game_state = ctx;
return; furi_mutex_acquire(game_state->mutex, FuriWaitForever);
}
switch(game_state->state) { switch(game_state->state) {
case GameStateAnimate: case GameStateAnimate:
@ -174,7 +173,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
break; break;
} }
release_mutex((ValueMutex*)ctx, game_state); furi_mutex_release(game_state->mutex);
} }
void remove_drag(GameState* game_state) { void remove_drag(GameState* game_state) {
@ -470,8 +469,8 @@ int32_t solitaire_app(void* p) {
game_state->state = GameStateStart; game_state->state = GameStateStart;
game_state->processing = true; game_state->processing = true;
ValueMutex state_mutex; game_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, game_state, sizeof(GameState))) { if(!game_state->mutex) {
FURI_LOG_E(APP_NAME, "cannot create mutex\r\n"); FURI_LOG_E(APP_NAME, "cannot create mutex\r\n");
return_code = 255; return_code = 255;
goto free_and_exit; goto free_and_exit;
@ -481,13 +480,13 @@ int32_t solitaire_app(void* p) {
notification_message_block(notification, &sequence_display_backlight_enforce_on); notification_message_block(notification, &sequence_display_backlight_enforce_on);
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &state_mutex); view_port_draw_callback_set(view_port, render_callback, game_state);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
FuriTimer* timer = furi_timer_alloc(update_timer_callback, FuriTimerTypePeriodic, event_queue); FuriTimer* timer = furi_timer_alloc(update_timer_callback, FuriTimerTypePeriodic, event_queue);
furi_timer_start(timer, furi_kernel_get_tick_frequency() / 30); furi_timer_start(timer, furi_kernel_get_tick_frequency() / 30);
Gui* gui = furi_record_open("gui"); Gui* gui = furi_record_open(RECORD_GUI);
gui_add_view_port(gui, view_port, GuiLayerFullscreen); gui_add_view_port(gui, view_port, GuiLayerFullscreen);
AppEvent event; AppEvent event;
@ -497,7 +496,7 @@ int32_t solitaire_app(void* p) {
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 150); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 150);
GameState* localstate = (GameState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(game_state->mutex, FuriWaitForever);
bool hadChange = false; bool hadChange = false;
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
if(event.type == EventTypeKey) { if(event.type == EventTypeKey) {
@ -509,7 +508,7 @@ int32_t solitaire_app(void* p) {
case InputKeyRight: case InputKeyRight:
case InputKeyLeft: case InputKeyLeft:
case InputKeyOk: case InputKeyOk:
localstate->input = event.input.key; game_state->input = event.input.key;
break; break;
case InputKeyBack: case InputKeyBack:
processing = false; processing = false;
@ -525,12 +524,12 @@ int32_t solitaire_app(void* p) {
case InputKeyRight: case InputKeyRight:
case InputKeyLeft: case InputKeyLeft:
case InputKeyOk: case InputKeyOk:
if(event.input.key == InputKeyOk && localstate->state == GameStateStart) { if(event.input.key == InputKeyOk && game_state->state == GameStateStart) {
localstate->state = GameStatePlay; game_state->state = GameStatePlay;
init(game_state); init(game_state);
} else { } else {
hadChange = true; hadChange = true;
localstate->input = event.input.key; game_state->input = event.input.key;
} }
break; break;
case InputKeyBack: case InputKeyBack:
@ -543,16 +542,16 @@ int32_t solitaire_app(void* p) {
} }
} }
} else if(event.type == EventTypeTick) { } else if(event.type == EventTypeTick) {
tick(localstate, notification); tick(game_state, notification);
processing = localstate->processing; processing = game_state->processing;
localstate->input = InputKeyMAX; game_state->input = InputKeyMAX;
} }
} else { } else {
//FURI_LOG_W(APP_NAME, "osMessageQueue: event timeout"); //FURI_LOG_W(APP_NAME, "osMessageQueue: event timeout");
// event timeout // event timeout
} }
if(hadChange || game_state->state == GameStateAnimate) view_port_update(view_port); if(hadChange || game_state->state == GameStateAnimate) view_port_update(view_port);
release_mutex(&state_mutex, localstate); furi_mutex_release(game_state->mutex);
} }
notification_message_block(notification, &sequence_display_backlight_enforce_auto); notification_message_block(notification, &sequence_display_backlight_enforce_auto);
@ -562,7 +561,7 @@ int32_t solitaire_app(void* p) {
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
furi_record_close(RECORD_NOTIFICATION); furi_record_close(RECORD_NOTIFICATION);
view_port_free(view_port); view_port_free(view_port);
delete_mutex(&state_mutex); furi_mutex_free(game_state->mutex);
free_and_exit: free_and_exit:
free(game_state->animation.buffer); free(game_state->animation.buffer);

View file

@ -71,6 +71,7 @@ typedef struct {
uint16_t fallSpeed; uint16_t fallSpeed;
GameState gameState; GameState gameState;
FuriTimer* timer; FuriTimer* timer;
FuriMutex* mutex;
} TetrisState; } TetrisState;
typedef enum { typedef enum {
@ -127,11 +128,9 @@ static void tetris_game_draw_playfield(Canvas* const canvas, const TetrisState*
} }
static void tetris_game_render_callback(Canvas* const canvas, void* ctx) { static void tetris_game_render_callback(Canvas* const canvas, void* ctx) {
const TetrisState* tetris_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(tetris_state == NULL) { const TetrisState* tetris_state = ctx;
FURI_LOG_E("TetrisGame", "it null"); furi_mutex_acquire(tetris_state->mutex, FuriWaitForever);
return;
}
tetris_game_draw_border(canvas); tetris_game_draw_border(canvas);
tetris_game_draw_playfield(canvas, tetris_state); tetris_game_draw_playfield(canvas, tetris_state);
@ -159,7 +158,7 @@ static void tetris_game_render_callback(Canvas* const canvas, void* ctx) {
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 32, 73, AlignCenter, AlignBottom, buffer); canvas_draw_str_aligned(canvas, 32, 73, AlignCenter, AlignBottom, buffer);
} }
release_mutex((ValueMutex*)ctx, tetris_state); furi_mutex_release(tetris_state->mutex);
} }
static void tetris_game_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void tetris_game_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -358,8 +357,8 @@ int32_t tetris_game_app() {
TetrisState* tetris_state = malloc(sizeof(TetrisState)); TetrisState* tetris_state = malloc(sizeof(TetrisState));
ValueMutex state_mutex; tetris_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, tetris_state, sizeof(TetrisState))) { if(!tetris_state->mutex) {
FURI_LOG_E("TetrisGame", "cannot create mutex\r\n"); FURI_LOG_E("TetrisGame", "cannot create mutex\r\n");
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
free(tetris_state); free(tetris_state);
@ -376,7 +375,7 @@ int32_t tetris_game_app() {
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_set_orientation(view_port, ViewPortOrientationVertical); view_port_set_orientation(view_port, ViewPortOrientationVertical);
view_port_draw_callback_set(view_port, tetris_game_render_callback, &state_mutex); view_port_draw_callback_set(view_port, tetris_game_render_callback, tetris_state);
view_port_input_callback_set(view_port, tetris_game_input_callback, event_queue); view_port_input_callback_set(view_port, tetris_game_input_callback, event_queue);
// Open GUI and register view_port // Open GUI and register view_port
@ -399,7 +398,7 @@ int32_t tetris_game_app() {
// This 10U implicitly sets the game loop speed. downRepeatCounter relies on this value // This 10U implicitly sets the game loop speed. downRepeatCounter relies on this value
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 10U); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 10U);
TetrisState* tetris_state = (TetrisState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(tetris_state->mutex, FuriWaitForever);
memcpy(newPiece, &tetris_state->currPiece, sizeof(tetris_state->currPiece)); memcpy(newPiece, &tetris_state->currPiece, sizeof(tetris_state->currPiece));
bool wasDownMove = false; bool wasDownMove = false;
@ -466,7 +465,7 @@ int32_t tetris_game_app() {
tetris_game_process_step(tetris_state, newPiece, wasDownMove); tetris_game_process_step(tetris_state, newPiece, wasDownMove);
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, tetris_state); furi_mutex_release(tetris_state->mutex);
} }
furi_timer_free(tetris_state->timer); furi_timer_free(tetris_state->timer);
@ -475,7 +474,7 @@ int32_t tetris_game_app() {
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
view_port_free(view_port); view_port_free(view_port);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
delete_mutex(&state_mutex); furi_mutex_free(tetris_state->mutex);
vTaskPrioritySet(timer_task, origTimerPrio); vTaskPrioritySet(timer_task, origTimerPrio);
free(newPiece); free(newPiece);
free(tetris_state); free(tetris_state);

View file

@ -10,6 +10,7 @@
typedef enum { EventTypeTick, EventTypeKey } EventType; typedef enum { EventTypeTick, EventTypeKey } EventType;
typedef struct { typedef struct {
FuriMutex* mutex;
FuriTimer* timer; FuriTimer* timer;
uint8_t selBoxX; uint8_t selBoxX;
uint8_t selBoxY; uint8_t selBoxY;
@ -173,10 +174,9 @@ static void tictactoe_state_init(TicTacToeState* tictactoe_state) {
} }
static void tictactoe_draw_callback(Canvas* const canvas, void* ctx) { static void tictactoe_draw_callback(Canvas* const canvas, void* ctx) {
TicTacToeState* ticst = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(ticst == NULL) { TicTacToeState* ticst = ctx;
return; furi_mutex_acquire(ticst->mutex, FuriWaitForever);
}
if(ticst->selX > 3) { if(ticst->selX > 3) {
ticst->selX = 3; ticst->selX = 3;
@ -285,7 +285,7 @@ static void tictactoe_draw_callback(Canvas* const canvas, void* ctx) {
tictactoe_draw(canvas, ticst); tictactoe_draw(canvas, ticst);
release_mutex((ValueMutex*)ctx, ticst); furi_mutex_release(ticst->mutex);
} }
static void tictactoe_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void tictactoe_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -308,8 +308,9 @@ int32_t tictactoe_game_app(void* p) {
TicTacToeState* tictactoe_state = malloc(sizeof(TicTacToeState)); TicTacToeState* tictactoe_state = malloc(sizeof(TicTacToeState));
ValueMutex state_mutex; tictactoe_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, tictactoe_state, sizeof(TicTacToeState))) {
if(!tictactoe_state->mutex) {
FURI_LOG_E(TAG, "Cannot create mutex\r\n"); FURI_LOG_E(TAG, "Cannot create mutex\r\n");
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
free(tictactoe_state); free(tictactoe_state);
@ -318,7 +319,7 @@ int32_t tictactoe_game_app(void* p) {
// Set system callbacks // Set system callbacks
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, tictactoe_draw_callback, &state_mutex); view_port_draw_callback_set(view_port, tictactoe_draw_callback, tictactoe_state);
view_port_input_callback_set(view_port, tictactoe_input_callback, event_queue); view_port_input_callback_set(view_port, tictactoe_input_callback, event_queue);
tictactoe_state->timer = tictactoe_state->timer =
@ -337,7 +338,7 @@ int32_t tictactoe_game_app(void* p) {
GameEvent event; GameEvent event;
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
TicTacToeState* tictactoe_state = (TicTacToeState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(tictactoe_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
// Key events // Key events
@ -370,7 +371,7 @@ int32_t tictactoe_game_app(void* p) {
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, tictactoe_state); furi_mutex_release(tictactoe_state->mutex);
} }
furi_timer_free(tictactoe_state->timer); furi_timer_free(tictactoe_state->timer);
@ -379,7 +380,7 @@ int32_t tictactoe_game_app(void* p) {
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
view_port_free(view_port); view_port_free(view_port);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
delete_mutex(&state_mutex); furi_mutex_free(tictactoe_state->mutex);
free(tictactoe_state); free(tictactoe_state);
return 0; return 0;

View file

@ -23,12 +23,14 @@
#define IDLE_TIMEOUT 60000 #define IDLE_TIMEOUT 60000
static void render_callback(Canvas* const canvas, void* ctx) { static void render_callback(Canvas* const canvas, void* ctx) {
PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
PluginState* plugin_state = ctx;
furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
if(plugin_state != NULL) { if(plugin_state != NULL) {
totp_scene_director_render(canvas, plugin_state); totp_scene_director_render(canvas, plugin_state);
} }
release_mutex((ValueMutex*)ctx, plugin_state); furi_mutex_release(plugin_state->mutex);
} }
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -137,8 +139,8 @@ int32_t totp_app() {
return 254; return 254;
} }
ValueMutex state_mutex; plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) { if(!plugin_state->mutex) {
FURI_LOG_E(LOGGING_TAG, "Cannot create mutex\r\n"); FURI_LOG_E(LOGGING_TAG, "Cannot create mutex\r\n");
totp_plugin_state_free(plugin_state); totp_plugin_state_free(plugin_state);
return 255; return 255;
@ -157,7 +159,7 @@ int32_t totp_app() {
// Set system callbacks // Set system callbacks
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &state_mutex); view_port_draw_callback_set(view_port, render_callback, plugin_state);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
// Open GUI and register view_port // Open GUI and register view_port
@ -169,7 +171,7 @@ int32_t totp_app() {
while(processing) { while(processing) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
PluginState* plugin_state_m = acquire_mutex_block(&state_mutex); furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
if(event.type == EventTypeKey) { if(event.type == EventTypeKey) {
@ -179,16 +181,16 @@ int32_t totp_app() {
if(event.type == EventForceCloseApp) { if(event.type == EventForceCloseApp) {
processing = false; processing = false;
} else { } else {
processing = totp_scene_director_handle_event(&event, plugin_state_m); processing = totp_scene_director_handle_event(&event, plugin_state);
} }
} else if( } else if(
plugin_state_m->pin_set && plugin_state_m->current_scene != TotpSceneAuthentication && plugin_state->pin_set && plugin_state->current_scene != TotpSceneAuthentication &&
furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) { furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
totp_scene_director_activate_scene(plugin_state_m, TotpSceneAuthentication, NULL); totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, plugin_state_m); furi_mutex_release(plugin_state->mutex);
} }
totp_cli_unregister_command_handler(cli_context); totp_cli_unregister_command_handler(cli_context);
@ -199,7 +201,7 @@ int32_t totp_app() {
gui_remove_view_port(plugin_state->gui, view_port); gui_remove_view_port(plugin_state->gui, view_port);
view_port_free(view_port); view_port_free(view_port);
furi_message_queue_free(event_queue); furi_message_queue_free(event_queue);
delete_mutex(&state_mutex); furi_mutex_free(plugin_state->mutex);
totp_plugin_state_free(plugin_state); totp_plugin_state_free(plugin_state);
return 0; return 0;
} }

View file

@ -87,4 +87,5 @@ typedef struct {
* @brief Notification method * @brief Notification method
*/ */
NotificationMethod notification_method; NotificationMethod notification_method;
FuriMutex* mutex;
} PluginState; } PluginState;

View file

@ -57,8 +57,10 @@ static void totp_type_code_worker_type_code(TotpTypeCodeWorkerContext* context)
} }
static int32_t totp_type_code_worker_callback(void* context) { static int32_t totp_type_code_worker_callback(void* context) {
ValueMutex context_mutex; furi_assert(context);
if(!init_mutex(&context_mutex, context, sizeof(TotpTypeCodeWorkerContext))) { TotpTypeCodeWorkerContext* ctxx = context;
ctxx->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!ctxx->mutex) {
return 251; return 251;
} }
@ -70,15 +72,16 @@ static int32_t totp_type_code_worker_callback(void* context) {
furi_check((flags & FuriFlagError) == 0); //-V562 furi_check((flags & FuriFlagError) == 0); //-V562
if(flags & TotpTypeCodeWorkerEventStop) break; if(flags & TotpTypeCodeWorkerEventStop) break;
TotpTypeCodeWorkerContext* h_context = acquire_mutex_block(&context_mutex); TotpTypeCodeWorkerContext* h_context = context;
furi_mutex_acquire(ctxx->mutex, FuriWaitForever);
if(flags & TotpTypeCodeWorkerEventType) { if(flags & TotpTypeCodeWorkerEventType) {
totp_type_code_worker_type_code(h_context); totp_type_code_worker_type_code(h_context);
} }
release_mutex(&context_mutex, h_context); furi_mutex_release(ctxx->mutex);
} }
delete_mutex(&context_mutex); furi_mutex_free(ctxx->mutex);
return 0; return 0;
} }

View file

@ -12,6 +12,7 @@ typedef struct {
FuriThread* thread; FuriThread* thread;
FuriMutex* string_sync; FuriMutex* string_sync;
FuriHalUsbInterface* usb_mode_prev; FuriHalUsbInterface* usb_mode_prev;
FuriMutex* mutex;
} TotpTypeCodeWorkerContext; } TotpTypeCodeWorkerContext;
enum TotpTypeCodeWorkerEvents { enum TotpTypeCodeWorkerEvents {

View file

@ -83,6 +83,7 @@ typedef enum EWorkerEventFlags {
} EWorkerEventFlags; } EWorkerEventFlags;
typedef struct SWiFiScannerApp { typedef struct SWiFiScannerApp {
FuriMutex* mutex;
Gui* m_gui; Gui* m_gui;
FuriThread* m_worker_thread; FuriThread* m_worker_thread;
NotificationApp* m_notification; NotificationApp* m_notification;
@ -162,10 +163,9 @@ void DrawSignalStrengthBar(Canvas* canvas, int rssi, int x, int y, int width, in
} }
static void wifi_module_render_callback(Canvas* const canvas, void* ctx) { static void wifi_module_render_callback(Canvas* const canvas, void* ctx) {
SWiFiScannerApp* app = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(app == NULL) { SWiFiScannerApp* app = ctx;
return; furi_mutex_acquire(app->mutex, FuriWaitForever);
}
canvas_clear(canvas); canvas_clear(canvas);
@ -433,7 +433,7 @@ static void wifi_module_render_callback(Canvas* const canvas, void* ctx) {
break; break;
} }
} }
release_mutex((ValueMutex*)ctx, app); furi_mutex_release(app->mutex);
} }
static void wifi_module_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void wifi_module_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -460,14 +460,15 @@ static void uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
static int32_t uart_worker(void* context) { static int32_t uart_worker(void* context) {
furi_assert(context); furi_assert(context);
SWiFiScannerApp* app = acquire_mutex((ValueMutex*)context, 25); SWiFiScannerApp* app = context;
furi_mutex_acquire(app->mutex, FuriWaitForever);
if(app == NULL) { if(app == NULL) {
return 1; return 1;
} }
FuriStreamBuffer* rx_stream = app->m_rx_stream; FuriStreamBuffer* rx_stream = app->m_rx_stream;
release_mutex((ValueMutex*)context, app); furi_mutex_release(app->mutex);
while(true) { while(true) {
uint32_t events = furi_thread_flags_wait( uint32_t events = furi_thread_flags_wait(
@ -527,7 +528,8 @@ static int32_t uart_worker(void* context) {
} while(end < stringSize); } while(end < stringSize);
furi_string_free(chunk); furi_string_free(chunk);
app = acquire_mutex((ValueMutex*)context, 25); app = context;
furi_mutex_acquire(app->mutex, FuriWaitForever);
if(app == NULL) { if(app == NULL) {
return 1; return 1;
} }
@ -584,7 +586,7 @@ static int32_t uart_worker(void* context) {
} }
} }
release_mutex((ValueMutex*)context, app); furi_mutex_release(app->mutex);
// Clear string array // Clear string array
for(index = 0; index < EChunkArrayData_ENUM_MAX; ++index) { for(index = 0; index < EChunkArrayData_ENUM_MAX; ++index) {
@ -665,8 +667,9 @@ int32_t wifi_scanner_app(void* p) {
#endif // ENABLE_MODULE_POWER #endif // ENABLE_MODULE_POWER
#endif // ENABLE_MODULE_DETECTION #endif // ENABLE_MODULE_DETECTION
ValueMutex app_data_mutex; app->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&app_data_mutex, app, sizeof(SWiFiScannerApp))) {
if(!app->mutex) {
WIFI_APP_LOG_E("cannot create mutex\r\n"); WIFI_APP_LOG_E("cannot create mutex\r\n");
free(app); free(app);
return 255; return 255;
@ -674,10 +677,10 @@ int32_t wifi_scanner_app(void* p) {
WIFI_APP_LOG_I("Mutex created"); WIFI_APP_LOG_I("Mutex created");
app->m_notification = furi_record_open("notification"); app->m_notification = furi_record_open(RECORD_NOTIFICATION);
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, wifi_module_render_callback, &app_data_mutex); view_port_draw_callback_set(view_port, wifi_module_render_callback, app);
view_port_input_callback_set(view_port, wifi_module_input_callback, event_queue); view_port_input_callback_set(view_port, wifi_module_input_callback, event_queue);
// Open GUI and register view_port // Open GUI and register view_port
@ -691,7 +694,7 @@ int32_t wifi_scanner_app(void* p) {
app->m_worker_thread = furi_thread_alloc(); app->m_worker_thread = furi_thread_alloc();
furi_thread_set_name(app->m_worker_thread, "WiFiModuleUARTWorker"); furi_thread_set_name(app->m_worker_thread, "WiFiModuleUARTWorker");
furi_thread_set_stack_size(app->m_worker_thread, 1024); furi_thread_set_stack_size(app->m_worker_thread, 1024);
furi_thread_set_context(app->m_worker_thread, &app_data_mutex); furi_thread_set_context(app->m_worker_thread, app);
furi_thread_set_callback(app->m_worker_thread, uart_worker); furi_thread_set_callback(app->m_worker_thread, uart_worker);
furi_thread_start(app->m_worker_thread); furi_thread_start(app->m_worker_thread);
WIFI_APP_LOG_I("UART thread allocated"); WIFI_APP_LOG_I("UART thread allocated");
@ -710,7 +713,7 @@ int32_t wifi_scanner_app(void* p) {
SPluginEvent event; SPluginEvent event;
for(bool processing = true; processing;) { for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
SWiFiScannerApp* app = (SWiFiScannerApp*)acquire_mutex_block(&app_data_mutex); furi_mutex_acquire(app->mutex, FuriWaitForever);
#if ENABLE_MODULE_DETECTION #if ENABLE_MODULE_DETECTION
if(!app->m_wifiModuleAttached) { if(!app->m_wifiModuleAttached) {
@ -807,7 +810,7 @@ int32_t wifi_scanner_app(void* p) {
#endif #endif
view_port_update(view_port); view_port_update(view_port);
release_mutex(&app_data_mutex, app); furi_mutex_release(app->mutex);
} }
WIFI_APP_LOG_I("Start exit app"); WIFI_APP_LOG_I("Start exit app");
@ -831,7 +834,7 @@ int32_t wifi_scanner_app(void* p) {
// Close gui record // Close gui record
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
furi_record_close("notification"); furi_record_close(RECORD_NOTIFICATION);
app->m_gui = NULL; app->m_gui = NULL;
view_port_free(view_port); view_port_free(view_port);
@ -840,7 +843,7 @@ int32_t wifi_scanner_app(void* p) {
furi_stream_buffer_free(app->m_rx_stream); furi_stream_buffer_free(app->m_rx_stream);
delete_mutex(&app_data_mutex); furi_mutex_free(app->mutex);
// Free rest // Free rest
free(app); free(app);

View file

@ -52,6 +52,7 @@ typedef struct {
} Projectile; } Projectile;
typedef struct { typedef struct {
FuriMutex* mutex;
GameState game_state; GameState game_state;
Player player; Player player;
@ -66,10 +67,9 @@ typedef struct {
} PluginState; } PluginState;
static void render_callback(Canvas* const canvas, void* ctx) { static void render_callback(Canvas* const canvas, void* ctx) {
const PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25); furi_assert(ctx);
if(plugin_state == NULL) { const PluginState* plugin_state = ctx;
return; furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
}
canvas_draw_frame(canvas, 0, 0, 128, 64); canvas_draw_frame(canvas, 0, 0, 128, 64);
@ -181,7 +181,7 @@ static void render_callback(Canvas* const canvas, void* ctx) {
//canvas_draw_str_aligned(canvas, 32, 16, AlignLeft, AlignBottom, info); //canvas_draw_str_aligned(canvas, 32, 16, AlignLeft, AlignBottom, info);
//free(info); //free(info);
release_mutex((ValueMutex*)ctx, plugin_state); furi_mutex_release(plugin_state->mutex);
} }
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@ -295,8 +295,8 @@ int32_t zombiez_game_app(void* p) {
PluginState* plugin_state = malloc(sizeof(PluginState)); PluginState* plugin_state = malloc(sizeof(PluginState));
zombiez_state_init(plugin_state); zombiez_state_init(plugin_state);
ValueMutex state_mutex; plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) { if(!plugin_state->mutex) {
FURI_LOG_E("Zombiez", "cannot create mutex\r\n"); FURI_LOG_E("Zombiez", "cannot create mutex\r\n");
return_code = 255; return_code = 255;
goto free_and_exit; goto free_and_exit;
@ -304,7 +304,7 @@ int32_t zombiez_game_app(void* p) {
// Set system callbacks // Set system callbacks
ViewPort* view_port = view_port_alloc(); ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &state_mutex); view_port_draw_callback_set(view_port, render_callback, plugin_state);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
FuriTimer* timer = furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, event_queue); FuriTimer* timer = furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, event_queue);
@ -321,7 +321,7 @@ int32_t zombiez_game_app(void* p) {
bool isRunning = true; bool isRunning = true;
while(isRunning) { while(isRunning) {
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
PluginState* plugin_state = (PluginState*)acquire_mutex_block(&state_mutex); furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
if(event.type == EventTypeKey) { if(event.type == EventTypeKey) {
if(event.input.type == InputTypePress) { if(event.input.type == InputTypePress) {
@ -381,12 +381,10 @@ int32_t zombiez_game_app(void* p) {
} else if(event.type == EventTypeTick) { } else if(event.type == EventTypeTick) {
tick(plugin_state); tick(plugin_state);
} }
} else {
// event timeout
} }
view_port_update(view_port); view_port_update(view_port);
release_mutex(&state_mutex, plugin_state); furi_mutex_release(plugin_state->mutex);
} }
furi_timer_free(timer); furi_timer_free(timer);
@ -394,7 +392,7 @@ int32_t zombiez_game_app(void* p) {
gui_remove_view_port(gui, view_port); gui_remove_view_port(gui, view_port);
furi_record_close(RECORD_GUI); furi_record_close(RECORD_GUI);
view_port_free(view_port); view_port_free(view_port);
delete_mutex(&state_mutex); furi_mutex_free(plugin_state->mutex);
free_and_exit: free_and_exit:
free(plugin_state); free(plugin_state);