From 683cb03f054706bf18ddf2ef651029f6deaf7e1d Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 30 Nov 2022 13:47:29 +0900 Subject: [PATCH] utils_gthread: Change to use g_cond_wait_until to wait idle - In some cases, signal was sent by idle_callback but there is a problem that this signal is lost and g_cond_wait cannot be awakened. - Above case can cause deadlock problem. - So set 200ms timeout ms with using g_cond_wait_until instead of g_cond_wait. Change-Id: Ib0a549616f74a9fb39e78f7b37b1b8b09e16031d Signed-off-by: Joonbum Ko --- src/tpl_utils_gthread.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/tpl_utils_gthread.c b/src/tpl_utils_gthread.c index 500507f..b3e48ef 100644 --- a/src/tpl_utils_gthread.c +++ b/src/tpl_utils_gthread.c @@ -492,6 +492,8 @@ tpl_gthread_wait_idle(tpl_gthread *gthread) TPL_CHECK_ON_NULL_RETURN(gthread); GSource *idle_source = NULL; + gint64 end_time; + gboolean ret = TRUE; TPL_DEBUG("[WAIT IDLE] BEGIN"); @@ -512,8 +514,18 @@ tpl_gthread_wait_idle(tpl_gthread *gthread) g_source_attach(idle_source, g_main_loop_get_context(gthread->loop)); g_source_unref(idle_source); + /* 200ms timeout */ + end_time = g_get_monotonic_time() + + (200 * G_TIME_SPAN_MILLISECOND); + while (!gthread->is_idle) { - g_cond_wait(>hread->idle_cond, >hread->idle_mutex); + ret = g_cond_wait_until(>hread->idle_cond, + >hread->idle_mutex, + end_time); + if (!ret) { + TPL_ERR("wait_idle timeout!"); + break; + } } g_mutex_unlock(>hread->idle_mutex); -- 2.34.1