Skip to content

Commit

Permalink
FuriTimer: Use a local variable to wait for deletion
Browse files Browse the repository at this point in the history
This combines the current synchronous behaviour
(as we could have deferred the free call too) with
a smaller FuriTimer - it's safe to pass a pointer to
a local variable to this pending timer call, because we
know it'll be finished before the caller returns
  • Loading branch information
CookiePLMonster committed Sep 7, 2024
1 parent 8672a1d commit 7005648
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions furi/core/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ struct FuriTimer {
StaticTimer_t container;
FuriTimerCallback cb_func;
void* cb_context;
volatile bool can_be_removed;
};

// IMPORTANT: container MUST be the FIRST struct member
Expand Down Expand Up @@ -42,9 +41,8 @@ static void furi_timer_epilogue(void* context, uint32_t arg) {
furi_assert(context);
UNUSED(arg);

FuriTimer* instance = context;

instance->can_be_removed = true;
volatile bool* can_be_removed = context;
*can_be_removed = true;
}

void furi_timer_free(FuriTimer* instance) {
Expand All @@ -53,9 +51,13 @@ void furi_timer_free(FuriTimer* instance) {

TimerHandle_t hTimer = (TimerHandle_t)instance;
furi_check(xTimerDelete(hTimer, portMAX_DELAY) == pdPASS);
furi_check(xTimerPendFunctionCall(furi_timer_epilogue, instance, 0, portMAX_DELAY) == pdPASS);

while(!instance->can_be_removed) {
volatile bool can_be_removed = false;
furi_check(
xTimerPendFunctionCall(furi_timer_epilogue, (void*)&can_be_removed, 0, portMAX_DELAY) ==
pdPASS);

while(!can_be_removed) {
furi_delay_tick(2);
}

Expand Down

0 comments on commit 7005648

Please sign in to comment.