From 50c990169dcffad91255612a7c2929df3735be97 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 5 Oct 2022 10:57:23 +0900 Subject: [PATCH] Add null checking before calling tpl_gsource_destroy. Change-Id: I431f21b80215abeafc5ab6daa45778f617cc661a Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 52 ++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index 487cf63..fb9286f 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -1035,19 +1035,21 @@ __tpl_wl_egl_display_fini(tpl_display_t *display) tpl_gmutex_unlock(&wl_egl_display->tdm.tdm_mutex); } - /* This is a protection to prevent problems that arise in unexpected situations - * that g_cond_wait cannot work normally. - * When calling tpl_gsource_destroy() with destroy_in_thread is TPL_TRUE, - * caller should use tpl_gcond_wait() in the loop with checking finalized flag - * */ - tpl_gmutex_lock(&wl_egl_display->disp_mutex); - // Send destroy mesage to thread - tpl_gsource_destroy(wl_egl_display->disp_source, TPL_TRUE); - while (wl_egl_display->disp_source && !wl_egl_display->gsource_finalized) { - tpl_gcond_wait(&wl_egl_display->disp_cond, &wl_egl_display->disp_mutex); + if (wl_egl_display->disp_source) { + tpl_gmutex_lock(&wl_egl_display->disp_mutex); + // Send destroy mesage to thread + tpl_gsource_destroy(wl_egl_display->disp_source, TPL_TRUE); + /* This is a protection to prevent problems that arise in unexpected situations + * that g_cond_wait cannot work normally. + * When calling tpl_gsource_destroy() with destroy_in_thread is TPL_TRUE, + * caller should use tpl_gcond_wait() in the loop with checking finalized flag + * */ + while (!wl_egl_display->gsource_finalized) { + tpl_gcond_wait(&wl_egl_display->disp_cond, &wl_egl_display->disp_mutex); + } + wl_egl_display->disp_source = NULL; + tpl_gmutex_unlock(&wl_egl_display->disp_mutex); } - wl_egl_display->disp_source = NULL; - tpl_gmutex_unlock(&wl_egl_display->disp_mutex); if (wl_egl_display->thread) { tpl_gthread_destroy(wl_egl_display->thread); @@ -2198,19 +2200,21 @@ __tpl_wl_egl_surface_fini(tpl_surface_t *surface) _tpl_wl_egl_surface_buffer_clear(wl_egl_surface); - /* This is a protection to prevent problems that arise in unexpected situations - * that g_cond_wait cannot work normally. - * When calling tpl_gsource_destroy() with destroy_in_thread is TPL_TRUE, - * caller should use tpl_gcond_wait() in the loop with checking finalized flag - * */ - tpl_gmutex_lock(&wl_egl_surface->surf_mutex); - // Send destroy mesage to thread - tpl_gsource_destroy(wl_egl_surface->surf_source, TPL_TRUE); - while (wl_egl_surface->surf_source && !wl_egl_surface->gsource_finalized) { - tpl_gcond_wait(&wl_egl_surface->surf_cond, &wl_egl_surface->surf_mutex); + if (wl_egl_surface->surf_source) { + tpl_gmutex_lock(&wl_egl_surface->surf_mutex); + // Send destroy mesage to thread + tpl_gsource_destroy(wl_egl_surface->surf_source, TPL_TRUE); + /* This is a protection to prevent problems that arise in unexpected situations + * that g_cond_wait cannot work normally. + * When calling tpl_gsource_destroy() with destroy_in_thread is TPL_TRUE, + * caller should use tpl_gcond_wait() in the loop with checking finalized flag + * */ + while (!wl_egl_surface->gsource_finalized) { + tpl_gcond_wait(&wl_egl_surface->surf_cond, &wl_egl_surface->surf_mutex); + } + wl_egl_surface->surf_source = NULL; + tpl_gmutex_unlock(&wl_egl_surface->surf_mutex); } - wl_egl_surface->surf_source = NULL; - tpl_gmutex_unlock(&wl_egl_surface->surf_mutex); _print_buffer_lists(wl_egl_surface); -- 2.34.1