1
mirror of https://github.com/flipperdevices/flipperzero-firmware.git synced 2025-12-12 04:41:26 +04:00

Furi: Fix EventLoop state persisting on same thread after free (#3711)

* Furi: Fix EventLoop state persisting on same thread after free
* Furi: clear event loop notification state and value on allocation, report unprocessed events on free
* UnitTests: add multiple event loop runs in one thread test

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
WillyJL
2024-06-14 15:00:34 +01:00
committed by GitHub
parent ca8517a1b0
commit 12c1d10246
3 changed files with 70 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
#include "event_loop_i.h"
#include "message_queue_i.h"
#include "log.h"
#include "check.h"
#include "thread.h"
@@ -10,6 +11,8 @@
#include <FreeRTOS.h>
#include <task.h>
#define TAG "FuriEventLoop"
struct FuriEventLoopItem {
// Source
FuriEventLoop* owner;
@@ -99,9 +102,15 @@ FuriEventLoop* furi_event_loop_alloc(void) {
FuriEventLoop* instance = malloc(sizeof(FuriEventLoop));
instance->thread_id = furi_thread_get_current_id();
FuriEventLoopTree_init(instance->tree);
WaitingList_init(instance->waiting_list);
// Clear notification state and value
xTaskNotifyStateClearIndexed(instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX);
ulTaskNotifyValueClearIndexed(
instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, 0xFFFFFFFF);
return instance;
}
@@ -110,6 +119,14 @@ void furi_event_loop_free(FuriEventLoop* instance) {
furi_check(instance->thread_id == furi_thread_get_current_id());
FuriEventLoopTree_clear(instance->tree);
uint32_t flags = 0;
BaseType_t ret = xTaskNotifyWaitIndexed(
FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, 0, FuriEventLoopFlagAll, &flags, 0);
if(ret == pdTRUE) {
FURI_LOG_D(TAG, "Some events was not processed: 0x%lx", flags);
}
free(instance);
}