mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-23 13:21:44 +03:00
FuriTimer: Use an event instead of a volatile bool to wait for deletion (#3887)
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
543f6058e5
commit
70d8951fb7
@ -3,6 +3,7 @@
|
||||
#include "kernel.h"
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <event_groups.h>
|
||||
#include <timers.h>
|
||||
|
||||
struct FuriTimer {
|
||||
@ -14,6 +15,8 @@ struct FuriTimer {
|
||||
// IMPORTANT: container MUST be the FIRST struct member
|
||||
static_assert(offsetof(FuriTimer, container) == 0);
|
||||
|
||||
#define TIMER_DELETED_EVENT (1U << 0)
|
||||
|
||||
static void TimerCallback(TimerHandle_t hTimer) {
|
||||
FuriTimer* instance = pvTimerGetTimerID(hTimer);
|
||||
furi_check(instance);
|
||||
@ -41,8 +44,8 @@ static void furi_timer_epilogue(void* context, uint32_t arg) {
|
||||
furi_assert(context);
|
||||
UNUSED(arg);
|
||||
|
||||
volatile bool* can_be_removed = context;
|
||||
*can_be_removed = true;
|
||||
EventGroupHandle_t hEvent = context;
|
||||
xEventGroupSetBits(hEvent, TIMER_DELETED_EVENT);
|
||||
}
|
||||
|
||||
void furi_timer_free(FuriTimer* instance) {
|
||||
@ -52,14 +55,12 @@ void furi_timer_free(FuriTimer* instance) {
|
||||
TimerHandle_t hTimer = (TimerHandle_t)instance;
|
||||
furi_check(xTimerDelete(hTimer, portMAX_DELAY) == pdPASS);
|
||||
|
||||
volatile bool can_be_removed = false;
|
||||
furi_check(
|
||||
xTimerPendFunctionCall(furi_timer_epilogue, (void*)&can_be_removed, 0, portMAX_DELAY) ==
|
||||
pdPASS);
|
||||
StaticEventGroup_t event_container;
|
||||
EventGroupHandle_t hEvent = xEventGroupCreateStatic(&event_container);
|
||||
furi_check(xTimerPendFunctionCall(furi_timer_epilogue, hEvent, 0, portMAX_DELAY) == pdPASS);
|
||||
|
||||
while(!can_be_removed) {
|
||||
furi_delay_tick(2);
|
||||
}
|
||||
xEventGroupWaitBits(hEvent, TIMER_DELETED_EVENT, 0, pdTRUE, portMAX_DELAY);
|
||||
vEventGroupDelete(hEvent);
|
||||
|
||||
free(instance);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user