Furi Thread: don't use thread pointer after FuriThreadStateStopped callback (#1799)

* Furi Thread: correct furi_thread_join, do not use thread pointer after FuriThreadStateStopped callback
* Furi: a little bit easier way to do harakiri
* Furi: crash on thread self join attempt

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Sergey Gavrilov 2022-09-29 03:37:07 +10:00 committed by GitHub
parent f8b532f063
commit 5883e134d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -85,7 +85,6 @@ static void furi_thread_body(void* context) {
}
furi_assert(thread->state == FuriThreadStateRunning);
furi_thread_set_state(thread, FuriThreadStateStopped);
if(thread->is_service) {
FURI_LOG_E(
@ -99,7 +98,10 @@ static void furi_thread_body(void* context) {
furi_assert(pvTaskGetThreadLocalStoragePointer(NULL, 0) != NULL);
vTaskSetThreadLocalStoragePointer(NULL, 0, NULL);
vTaskDelete(thread->task_handle);
// from here we can't use thread pointer
furi_thread_set_state(thread, FuriThreadStateStopped);
vTaskDelete(NULL);
furi_thread_catch();
}
@ -205,7 +207,9 @@ void furi_thread_start(FuriThread* thread) {
bool furi_thread_join(FuriThread* thread) {
furi_assert(thread);
while(thread->state != FuriThreadStateStopped) {
furi_check(furi_thread_get_current() != thread);
while(eTaskGetState(thread->task_handle) != eDeleted) {
furi_delay_ms(10);
}