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 "kernel.h"
|
||||||
|
|
||||||
#include <FreeRTOS.h>
|
#include <FreeRTOS.h>
|
||||||
|
#include <event_groups.h>
|
||||||
#include <timers.h>
|
#include <timers.h>
|
||||||
|
|
||||||
struct FuriTimer {
|
struct FuriTimer {
|
||||||
@ -14,6 +15,8 @@ struct FuriTimer {
|
|||||||
// IMPORTANT: container MUST be the FIRST struct member
|
// IMPORTANT: container MUST be the FIRST struct member
|
||||||
static_assert(offsetof(FuriTimer, container) == 0);
|
static_assert(offsetof(FuriTimer, container) == 0);
|
||||||
|
|
||||||
|
#define TIMER_DELETED_EVENT (1U << 0)
|
||||||
|
|
||||||
static void TimerCallback(TimerHandle_t hTimer) {
|
static void TimerCallback(TimerHandle_t hTimer) {
|
||||||
FuriTimer* instance = pvTimerGetTimerID(hTimer);
|
FuriTimer* instance = pvTimerGetTimerID(hTimer);
|
||||||
furi_check(instance);
|
furi_check(instance);
|
||||||
@ -41,8 +44,8 @@ static void furi_timer_epilogue(void* context, uint32_t arg) {
|
|||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
UNUSED(arg);
|
UNUSED(arg);
|
||||||
|
|
||||||
volatile bool* can_be_removed = context;
|
EventGroupHandle_t hEvent = context;
|
||||||
*can_be_removed = true;
|
xEventGroupSetBits(hEvent, TIMER_DELETED_EVENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void furi_timer_free(FuriTimer* instance) {
|
void furi_timer_free(FuriTimer* instance) {
|
||||||
@ -52,14 +55,12 @@ void furi_timer_free(FuriTimer* instance) {
|
|||||||
TimerHandle_t hTimer = (TimerHandle_t)instance;
|
TimerHandle_t hTimer = (TimerHandle_t)instance;
|
||||||
furi_check(xTimerDelete(hTimer, portMAX_DELAY) == pdPASS);
|
furi_check(xTimerDelete(hTimer, portMAX_DELAY) == pdPASS);
|
||||||
|
|
||||||
volatile bool can_be_removed = false;
|
StaticEventGroup_t event_container;
|
||||||
furi_check(
|
EventGroupHandle_t hEvent = xEventGroupCreateStatic(&event_container);
|
||||||
xTimerPendFunctionCall(furi_timer_epilogue, (void*)&can_be_removed, 0, portMAX_DELAY) ==
|
furi_check(xTimerPendFunctionCall(furi_timer_epilogue, hEvent, 0, portMAX_DELAY) == pdPASS);
|
||||||
pdPASS);
|
|
||||||
|
|
||||||
while(!can_be_removed) {
|
xEventGroupWaitBits(hEvent, TIMER_DELETED_EVENT, 0, pdTRUE, portMAX_DELAY);
|
||||||
furi_delay_tick(2);
|
vEventGroupDelete(hEvent);
|
||||||
}
|
|
||||||
|
|
||||||
free(instance);
|
free(instance);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user