From bf1660b1af2f01ba1f4c7b86e1cf09033ae6c506 Mon Sep 17 00:00:00 2001 From: TaeHyeon Jeong Date: Thu, 10 Oct 2024 17:52:29 +0900 Subject: [PATCH] tpl: Add check id after tpl_gthread_add_idle() Change-Id: Ib0376bfdae54df2e309365ca8e487d89053ca170 --- src/tpl_utils_gthread.c | 33 ++++++++++++++------------ src/tpl_wl_egl_thread.c | 51 +++++++++++++++++++++++++---------------- 2 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/tpl_utils_gthread.c b/src/tpl_utils_gthread.c index a5c77bd..a0b1fb7 100644 --- a/src/tpl_utils_gthread.c +++ b/src/tpl_utils_gthread.c @@ -538,21 +538,24 @@ tpl_gthread_wait_idle(tpl_gthread *gthread) g_mutex_lock(>hread->idle_mutex); id = tpl_gthread_add_idle(gthread, (tpl_gsource_func)_thread_idle_cb, gthread); - - /* 500ms timeout */ - end_time = g_get_monotonic_time() + - (WAIT_IDLE_TIMEOUT * G_TIME_SPAN_MILLISECOND); - do { - ret = g_cond_wait_until(>hread->idle_cond, - >hread->idle_mutex, - end_time); - if (!ret) { - tpl_gsource_remove(gthread, id); - TPL_ERR("wait_idle timeout!"); - res = TPL_ERROR_TIME_OUT; - break; - } - } while (!gthread->is_idle); + if (!id) { + TPL_WARN("Failed to attach idle gsource."); + } else { + /* 500ms timeout */ + end_time = g_get_monotonic_time() + + (WAIT_IDLE_TIMEOUT * G_TIME_SPAN_MILLISECOND); + do { + ret = g_cond_wait_until(>hread->idle_cond, + >hread->idle_mutex, + end_time); + if (!ret) { + tpl_gsource_remove(gthread, id); + TPL_ERR("wait_idle timeout!"); + res = TPL_ERROR_TIME_OUT; + break; + } + } while (!gthread->is_idle); + } gthread->is_idle = TPL_FALSE; diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index 76e602f..893fe78 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -2471,19 +2471,24 @@ __tpl_wl_egl_surface_fini(tpl_surface_t *surface) wl_egl_surface->buffers_finalize_done = TPL_FALSE; id = tpl_gthread_add_idle(wl_egl_display->thread, __idle_cb_buffers_finalize, wl_egl_surface); - tpl_gcond_timed_wait(&wl_egl_surface->surf_cond, - &wl_egl_surface->surf_mutex, - BUFFER_CLEAR_WAITING_TIMEOUT_MS) - { - if (wl_egl_surface->buffers_finalize_done) - break; - } else { - tpl_gsource_remove(wl_egl_display->thread, id); - TPL_WARN("buffer clear timeout. wl_egl_surface(%p)", wl_egl_surface); - - wl_egl_surface->buffers_finalize_done = TPL_TRUE; + if (!id) { + TPL_WARN("Failed to attach idle gsource. wl_egl_surface(%p)", + wl_egl_surface); wl_egl_surface->need_force_release = TPL_TRUE; + } else { + tpl_gcond_timed_wait(&wl_egl_surface->surf_cond, + &wl_egl_surface->surf_mutex, + BUFFER_CLEAR_WAITING_TIMEOUT_MS) + { + if (wl_egl_surface->buffers_finalize_done) + break; + } else { + tpl_gsource_remove(wl_egl_display->thread, id); + TPL_WARN("buffer clear timeout. wl_egl_surface(%p)", wl_egl_surface); + wl_egl_surface->need_force_release = TPL_TRUE; + } } + wl_egl_surface->buffers_finalize_done = TPL_TRUE; if (wl_egl_surface->surf_source) { // Send destroy mesage to thread @@ -2869,16 +2874,22 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, wl_egl_surface->buffers_commit_done = TPL_FALSE; id = tpl_gthread_add_idle(wl_egl_display->thread, __idle_cb_check_buffers_commit, wl_egl_surface); - tpl_gcond_timed_wait(&wl_egl_surface->surf_cond, - &wl_egl_surface->surf_mutex, - CHECK_COMMIT_TIMEOUT_MS) - { - if (wl_egl_surface->buffers_commit_done) - break; + if (!id) { + TPL_WARN("Failed to attach idle gsource. wl_egl_surface(%p)", + wl_egl_surface); } else { - tpl_gsource_remove(wl_egl_display->thread, id); - TPL_WARN("wl_egl_surface(%p) timeout error occured", wl_egl_surface); - _print_buffer_lists(wl_egl_surface); + tpl_gcond_timed_wait(&wl_egl_surface->surf_cond, + &wl_egl_surface->surf_mutex, + CHECK_COMMIT_TIMEOUT_MS) + { + if (wl_egl_surface->buffers_commit_done) + break; + } else { + tpl_gsource_remove(wl_egl_display->thread, id); + TPL_WARN("wl_egl_surface(%p) timeout error occured", + wl_egl_surface); + _print_buffer_lists(wl_egl_surface); + } } wl_egl_surface->buffers_commit_done = TPL_TRUE; -- 2.34.1