From: joonbum.ko Date: Thu, 21 Sep 2017 03:15:54 +0000 (+0900) Subject: tpl_wayland_egl_thread: modified the tdm_source to be destroyed in the thread. X-Git-Tag: accepted/tizen/4.0/unified/20170925.150846~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0224a1f5c4f59a7db474006da5afddf8bccd4a54;p=platform%2Fcore%2Fuifw%2Flibtpl-egl.git tpl_wayland_egl_thread: modified the tdm_source to be destroyed in the thread. - The tdm_source is created in the thread. - The tdm_del_source is created in the main thread after the tdm_source is created. - When twe_thread_destroy() is called, the tdm_source is destroyed in the thread by triggering an event on tdm_del_source. Change-Id: Icc88a9b92e446071d3776191fc120153a4c62502 Signed-off-by: joonbum.ko --- diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 2e1294d..4102e23 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -49,6 +49,7 @@ struct _twe_tdm_source { gpointer tag; tdm_client *tdm_client; int tdm_fd; + twe_del_source *tdm_del_source; }; struct _twe_wl_disp_source { @@ -116,6 +117,12 @@ struct _twe_wl_buffer_info { static twe_thread_context *_twe_ctx; static twe_tdm_source * _twe_thread_tdm_source_create(void); +static void +_twe_thread_tdm_source_destroy(void *source); +twe_del_source * +_twe_del_source_init(twe_thread_context *ctx, void *target_source); +void +_twe_del_source_fini(twe_del_source *source); static gpointer _twe_thread_loop(gpointer data) @@ -303,6 +310,8 @@ _twe_thread_tdm_source_finalize(GSource *source) TPL_LOG_T("WL_EGL", "tdm_destroy| tdm_source(%p) tdm_client(%p)", tdm_source, tdm_source->tdm_client); + g_source_remove_unix_fd(source, tdm_source->tag); + if (tdm_source->tdm_client) { tdm_client_destroy(tdm_source->tdm_client); tdm_source->tdm_client = NULL; @@ -361,15 +370,22 @@ _twe_thread_tdm_source_create(void) } static void -_twe_thread_tdm_source_destroy(twe_tdm_source *tdm_source) +_twe_thread_tdm_source_destroy(void *source) { + twe_tdm_source *tdm_source = (twe_tdm_source *)source; + if (!tdm_source || g_source_is_destroyed(&tdm_source->gsource)) { TPL_ERR("TDM source(%p) already destroyed.", tdm_source); return; } + g_mutex_lock(&_twe_ctx->thread_mutex); + g_source_destroy(&tdm_source->gsource); g_source_unref(&tdm_source->gsource); + + g_cond_signal(&_twe_ctx->thread_cond); + g_mutex_unlock(&_twe_ctx->thread_mutex); } twe_thread* @@ -406,6 +422,16 @@ twe_thread_create(void) _twe_ctx); g_cond_wait(&_twe_ctx->thread_cond, &_twe_ctx->thread_mutex); + + if (_twe_ctx->tdm_source) { + twe_tdm_source *tdm_source = _twe_ctx->tdm_source; + + tdm_source->tdm_del_source = _twe_del_source_init(_twe_ctx, tdm_source); + if (tdm_source->tdm_del_source) + tdm_source->tdm_del_source->destroy_target_source_func + = _twe_thread_tdm_source_destroy; + } + g_mutex_unlock(&_twe_ctx->thread_mutex); _twe_ctx->ref_cnt = 0; @@ -425,8 +451,19 @@ twe_thread_destroy(twe_thread* thread) if (thread->ctx->ref_cnt == 0) { if (_twe_ctx->tdm_source) { - _twe_thread_tdm_source_destroy(_twe_ctx->tdm_source); + twe_del_source *tdm_del_source = _twe_ctx->tdm_source->tdm_del_source; + _twe_ctx->tdm_source->tdm_del_source = NULL; + + g_mutex_lock(&_twe_ctx->thread_mutex); + + _twe_thread_del_source_trigger(tdm_del_source); + g_cond_wait(&_twe_ctx->thread_cond, &_twe_ctx->thread_mutex); + + g_mutex_unlock(&_twe_ctx->thread_mutex); + _twe_ctx->tdm_source = NULL; + + _twe_del_source_fini(tdm_del_source); } g_main_loop_quit(thread->ctx->twe_loop);