Skip to content

Commit 581376a

Browse files
committed
modules: lvgl: Fix thread deletion in OSAL
Do not delete the thread from within the thread callback function, secure thread_delete against trying to delete a terminated thread. Signed-off-by: Fabian Blatz <[email protected]>
1 parent ccd4d46 commit 581376a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

modules/lvgl/lvgl_zephyr_osal.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,20 @@ lv_result_t lv_thread_delete(lv_thread_t *thread)
4242
{
4343
int ret;
4444

45-
k_thread_abort(thread->tid);
45+
if (thread == NULL || thread->tid == NULL) {
46+
LOG_ERR("Invalid thread pointer");
47+
return LV_RESULT_INVALID;
48+
}
49+
50+
ret = k_thread_join(&thread->thread, K_MSEC(100));
51+
if (ret != 0) {
52+
LOG_WRN("Thread join failed or timed out: %d, aborting thread", ret);
53+
k_thread_abort(thread->tid);
54+
}
55+
4656
ret = k_thread_stack_free(thread->stack);
4757
if (ret < 0) {
48-
LOG_ERR("Failled to delete thread: %d", ret);
58+
LOG_ERR("Failed to delete thread: %d", ret);
4959
return LV_RESULT_INVALID;
5060
}
5161

@@ -153,7 +163,6 @@ void thread_entry(void *thread, void *cb, void *user_data)
153163
lv_thread_entry entry_cb = (lv_thread_entry)cb;
154164

155165
entry_cb(user_data);
156-
lv_thread_delete((lv_thread_t *)thread);
157166
}
158167

159168
void lv_sleep_ms(uint32_t ms)

0 commit comments

Comments
 (0)