tpl_wayland_egl_thread: protected the process of twe_display_del with mutex. 94/151894/4
authorjoonbum.ko <joonbum.ko@samsung.com>
Fri, 22 Sep 2017 06:54:30 +0000 (15:54 +0900)
committerjoonbum.ko <joonbum.ko@samsung.com>
Mon, 25 Sep 2017 02:47:55 +0000 (11:47 +0900)
 - The function twe_display_del is called by the main thread,
  but the actual destroy process is handled by the thread through twe_del_source.
   Therefore, while the del_source is being processed by the thread,
  the main thread must wait in cond_wait.

Change-Id: I7cffdc1d6fd477213d8258cf87871aa3de0c75f2
Signed-off-by: joonbum.ko <joonbum.ko@samsung.com>
src/tpl_wayland_egl_thread.c

index 5f2d3a1..2e1294d 100644 (file)
@@ -699,6 +699,7 @@ _twe_thread_wl_disp_source_destroy(void *source)
                return;
        }
 
+       g_mutex_lock(&_twe_ctx->thread_mutex);
        TPL_OBJECT_LOCK(&disp_source->obj);
 
        /* If disp_source is in prepared state, cancel it */
@@ -715,11 +716,15 @@ _twe_thread_wl_disp_source_destroy(void *source)
        wl_event_queue_destroy(disp_source->ev_queue);
        TPL_OBJECT_UNLOCK(&disp_source->obj);
 
+       TPL_LOG_T("WL_EGL", "[DEL] twe_display(%p) wl_display(%p)",
+                         disp_source, disp_source->disp);
+
        g_source_remove_poll(&disp_source->gsource, &disp_source->gfd);
        g_source_destroy(&disp_source->gsource);
+       g_source_unref(&disp_source->gsource);
 
-       TPL_LOG_T("WL_EGL", "[DEL] twe_display(%p) wl_display(%p)",
-                         disp_source, disp_source->disp);
+       g_cond_signal(&_twe_ctx->thread_cond);
+       g_mutex_unlock(&_twe_ctx->thread_mutex);
 }
 
 twe_display_h
@@ -790,13 +795,11 @@ twe_display_del(twe_display_h twe_display)
        _twe_display_fini_wl_tbm_client(source->wl_tbm_client);
        source->wl_tbm_client = NULL;
 
-       _twe_thread_del_source_trigger(disp_del_source);
-
-       while (!g_source_is_destroyed(&source->gsource)) {
-               /* Waiting for destroying disp_source */
-       }
+       g_mutex_lock(&_twe_ctx->thread_mutex);
 
-       g_source_unref(&source->gsource);
+       _twe_thread_del_source_trigger(disp_del_source);
+       g_cond_wait(&_twe_ctx->thread_cond, &_twe_ctx->thread_mutex);
+       g_mutex_unlock(&_twe_ctx->thread_mutex);
 
        _twe_del_source_fini(disp_del_source);