Add null checking before calling tpl_gsource_destroy. 14/282514/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Wed, 5 Oct 2022 01:57:23 +0000 (10:57 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Wed, 5 Oct 2022 01:57:23 +0000 (10:57 +0900)
Change-Id: I431f21b80215abeafc5ab6daa45778f617cc661a
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl_wl_egl_thread.c

index 487cf63..fb9286f 100755 (executable)
@@ -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);