Skip to content

Commit

Permalink
Furi: properly handle thread free if thread was not started
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Jun 12, 2024
1 parent f0b9ff8 commit 016be3f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions furi/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct FuriThread {
// this ensures that the size of this structure is minimal
bool is_service;
bool heap_trace_enabled;
volatile bool ready_to_die;
volatile bool is_active;
};

// IMPORTANT: container MUST be the FIRST struct member
Expand Down Expand Up @@ -196,7 +196,7 @@ void furi_thread_free(FuriThread* thread) {
furi_check(thread->is_service == false);
// Cannot free a non-joined thread
furi_check(thread->state == FuriThreadStateStopped);
furi_check(thread->ready_to_die);
furi_check(!thread->is_active);

furi_thread_set_name(thread, NULL);
furi_thread_set_appid(thread, NULL);
Expand Down Expand Up @@ -312,7 +312,7 @@ void furi_thread_start(FuriThread* thread) {
uint32_t stack_depth = thread->stack_size / sizeof(StackType_t);
UBaseType_t priority = thread->priority ? thread->priority : FuriThreadPriorityNormal;

thread->ready_to_die = false;
thread->is_active = true;

furi_check(
xTaskCreateStatic(
Expand All @@ -331,7 +331,7 @@ void furi_thread_cleanup_tcb_event(TaskHandle_t task) {
// clear thread local storage
vTaskSetThreadLocalStoragePointer(task, 0, NULL);
furi_check(thread == (FuriThread*)task);
thread->ready_to_die = true;
thread->is_active = false;
}
}

Expand All @@ -346,7 +346,7 @@ bool furi_thread_join(FuriThread* thread) {
//
// If your thread exited, but your app stuck here: some other thread uses
// all cpu time, which delays kernel from releasing task handle
while(!thread->ready_to_die) {
while(thread->is_active) {
furi_delay_ms(10);
}

Expand Down

0 comments on commit 016be3f

Please sign in to comment.