Change the order of creation of tdm_source. 79/254779/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Wed, 3 Feb 2021 01:27:03 +0000 (10:27 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Tue, 9 Mar 2021 08:51:07 +0000 (17:51 +0900)
Change-Id: I3bdfa3db71ed6a0dbacda4cf5a56d2ea81840d9e
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl_utils_gthread.c
src/tpl_wl_egl.c

index b1480c1cf003a3fd173ff22b5a269850999bb479..23e28d5d5f2a195a8b3bf7a33906874fd8d672a1 100644 (file)
@@ -109,17 +109,19 @@ tpl_gthread_create(const char *thread_name,
 
 
        g_mutex_lock(&new_thread->thread_mutex);
-       new_thread->destroy_sig_source =
-               tpl_gsource_create(new_thread, new_thread, -1,
-                                                  &thread_destroy_funcs, SOURCE_TYPE_FINALIZER);
 
        new_thread->loop      = loop;
+       TPL_DEBUG("loop(%p)", loop);
        new_thread->init_func = init_func;
        new_thread->func_data = func_data;
        new_thread->thread    = g_thread_new(thread_name,
                                                                             _tpl_gthread_init, new_thread);
        g_cond_wait(&new_thread->thread_cond,
                                &new_thread->thread_mutex);
+
+       new_thread->destroy_sig_source =
+       tpl_gsource_create(new_thread, new_thread, -1,
+                                          &thread_destroy_funcs, SOURCE_TYPE_FINALIZER);
        g_mutex_unlock(&new_thread->thread_mutex);
 
        return new_thread;
@@ -207,16 +209,17 @@ _thread_source_dispatch(GSource *source, GSourceFunc cb, gpointer data)
                        ret = gsource->gsource_funcs->dispatch(gsource, message);
 
                if (gsource->type == SOURCE_TYPE_FINALIZER) {
-                       tpl_gsource *del_source = (tpl_gsource *)data;
+                       tpl_gsource *del_source = (tpl_gsource *)gsource->data;
                        if (!g_source_is_destroyed(&del_source->gsource)) {
-                               g_mutex_lock(&del_source->thread->thread_mutex);
+                               tpl_gthread *thread = del_source->thread;
+                               g_mutex_lock(&thread->thread_mutex);
 
                                g_source_remove_unix_fd(&del_source->gsource, del_source->tag);
                                g_source_destroy(&del_source->gsource);
                                g_source_unref(&del_source->gsource);
 
-                               g_cond_signal(&del_source->thread->thread_cond);
-                               g_mutex_unlock(&del_source->thread->thread_mutex);
+                               g_cond_signal(&thread->thread_cond);
+                               g_mutex_unlock(&thread->thread_mutex);
                        }
                }
        } else {
@@ -307,6 +310,9 @@ tpl_gsource_create(tpl_gthread *thread, void *data, int fd,
        g_source_attach(&new_gsource->gsource,
                                        g_main_loop_get_context(thread->loop));
 
+       TPL_DEBUG("[GSOURCE_CREATE] tpl_gsource(%p) thread(%p) data(%p) fd(%d) type(%d)",
+                         new_gsource, thread, data, new_gsource->fd, type);
+
        return new_gsource;
 }
 
@@ -319,14 +325,18 @@ tpl_gsource_destroy(tpl_gsource *source, tpl_bool_t destroy_in_thread)
                return;
        }
 
+       TPL_DEBUG("[GSOURCE_DESTROY] tpl_gsource(%p) type(%d)",
+                         source, source->type);
+
        if (destroy_in_thread) {
+               tpl_gthread *thread = source->thread;
                if (source->type == SOURCE_TYPE_NORMAL) {
-                       g_mutex_lock(&source->thread->thread_mutex);
+                       g_mutex_lock(&thread->thread_mutex);
 
                        tpl_gsource_send_message(source->finalizer, 1);
 
-                       g_cond_wait(&source->thread->thread_cond, &source->thread->thread_mutex);
-                       g_mutex_unlock(&source->thread->thread_mutex);
+                       g_cond_wait(&thread->thread_cond, &thread->thread_mutex);
+                       g_mutex_unlock(&thread->thread_mutex);
                }
        } else {
                if (source->type == SOURCE_TYPE_NORMAL &&
index 320827d90adc4e37d0eda27289feb292638c648e..ba7cd6bc528b0f9bf0b8e9e6caff6b597a3bff6f 100644 (file)
@@ -53,6 +53,7 @@ struct _tpl_wl_egl_display {
 
        tdm_client                   *tdm_client;
        tpl_gsource                  *tdm_source;
+       int                           tdm_display_fd;
 
        tpl_bool_t                    use_wait_vblank;
        tpl_bool_t                    use_explicit_sync;
@@ -284,6 +285,7 @@ __thread_func_tdm_finalize(tpl_gsource *gsource)
        if (wl_egl_display->tdm_client) {
                tdm_client_destroy(wl_egl_display->tdm_client);
                wl_egl_display->tdm_client = NULL;
+               wl_egl_display->tdm_display_fd = -1;
        }
 
        wl_egl_display->tdm_initialized = TPL_FALSE;
@@ -299,16 +301,10 @@ static tpl_gsource_functions tdm_funcs = {
 tpl_result_t
 _thread_tdm_init(tpl_wl_egl_display_t *wl_egl_display)
 {
-       tpl_gsource      *tdm_source = NULL;
        tdm_client       *tdm_client = NULL;
        int               tdm_display_fd = -1;
        tdm_error         tdm_err = TDM_ERROR_NONE;
 
-       if (!wl_egl_display->thread) {
-               TPL_ERR("thread should be created before init tdm_client.");
-               return TPL_ERROR_INVALID_OPERATION;
-       }
-
        tdm_client = tdm_client_create(&tdm_err);
        if (!tdm_client || tdm_err != TDM_ERROR_NONE) {
                TPL_ERR("TDM_ERROR:%d Failed to create tdm_client\n", tdm_err);
@@ -322,23 +318,14 @@ _thread_tdm_init(tpl_wl_egl_display_t *wl_egl_display)
                return TPL_ERROR_INVALID_OPERATION;
        }
 
-       tdm_source = tpl_gsource_create(wl_egl_display->thread,
-                                                                       (void *)wl_egl_display, tdm_display_fd,
-                                                                       &tdm_funcs, SOURCE_TYPE_NORMAL);
-       if (!tdm_source) {
-               TPL_ERR("Failed to create tdm_gsource\n");
-               tdm_client_destroy(tdm_client);
-               return TPL_ERROR_INVALID_OPERATION;
-       }
-
-       wl_egl_display->tdm_client = tdm_client;
-       wl_egl_display->tdm_source = tdm_source;
-
+       wl_egl_display->tdm_display_fd  = tdm_display_fd;
+       wl_egl_display->tdm_client      = tdm_client;
+       wl_egl_display->tdm_source      = NULL;
        wl_egl_display->tdm_initialized = TPL_TRUE;
 
-       TPL_LOG_T("WL_EGL", "TPL_WAIT_VBLANK:DEFAULT_ENABLED");
-       TPL_LOG_T("WL_EGL", "wl_egl_display(%p) tdm_source(%p) tdm_client(%p)",
-                         wl_egl_display, tdm_source, tdm_client);
+       TPL_INFO("[TDM_CLIENT_INIT]",
+                        "wl_egl_display(%p) tdm_client(%p) tdm_display_fd(%d)",
+                        wl_egl_display, tdm_client, tdm_display_fd);
 
        return TPL_ERROR_NONE;
 }
@@ -498,6 +485,14 @@ _thread_wl_display_init(tpl_wl_egl_display_t *wl_egl_display)
 
        wl_egl_display->wl_initialized = TPL_TRUE;
 
+       TPL_INFO("[WAYLAND_INIT]",
+                        "wl_egl_display(%p) wl_display(%p) event_queue(%p)",
+                        wl_egl_display, wl_egl_display->wl_display, wl_egl_display->ev_queue);
+       TPL_INFO("[WAYLAND_INIT]",
+                        "tizen_surface_shm(%p) wp_presentation(%p) explicit_sync(%p)",
+                        wl_egl_display->tss, wl_egl_display->presentation,
+                        wl_egl_display->explicit_sync);
+
 fini:
        if (display_wrapper)
                wl_proxy_wrapper_destroy(display_wrapper);
@@ -768,6 +763,15 @@ __tpl_wl_egl_display_init(tpl_display_t *display)
                goto free_display;
        }
 
+       wl_egl_display->tdm_source = tpl_gsource_create(wl_egl_display->thread,
+                                                                                                       (void *)wl_egl_display,
+                                                                                                       wl_egl_display->tdm_display_fd,
+                                                                                                       &tdm_funcs, SOURCE_TYPE_NORMAL);
+       if (!wl_egl_display->tdm_source) {
+               TPL_ERR("Failed to create tdm_gsource\n");
+               goto free_display;
+       }
+
        TPL_LOG_T("WL_EGL",
                          "[INIT DISPLAY] wl_egl_display(%p) tpl_gthread(%p) wl_display(%p)",
                          wl_egl_display,
@@ -784,7 +788,11 @@ __tpl_wl_egl_display_init(tpl_display_t *display)
 
 free_display:
        if (wl_egl_display->thread) {
-               tpl_gsource_destroy(wl_egl_display->tdm_source, TPL_TRUE);
+               if (wl_egl_display->tdm_source)
+                       tpl_gsource_destroy(wl_egl_display->tdm_source, TPL_TRUE);
+               if (wl_egl_display->disp_source)
+                       tpl_gsource_destroy(wl_egl_display->disp_source, TPL_TRUE);
+
                tpl_gthread_destroy(wl_egl_display->thread, _thread_fini);
        }
 
@@ -810,16 +818,16 @@ __tpl_wl_egl_display_fini(tpl_display_t *display)
                                  wl_egl_display->thread,
                                  wl_egl_display->wl_display);
 
-               if (wl_egl_display->disp_source) {
-                       tpl_gsource_destroy(wl_egl_display->disp_source, TPL_TRUE);
-                       wl_egl_display->disp_source = NULL;
-               }
-
                if (wl_egl_display->tdm_source && wl_egl_display->tdm_initialized) {
                        tpl_gsource_destroy(wl_egl_display->tdm_source, TPL_TRUE);
                        wl_egl_display->tdm_source = NULL;
                }
 
+               if (wl_egl_display->disp_source) {
+                       tpl_gsource_destroy(wl_egl_display->disp_source, TPL_TRUE);
+                       wl_egl_display->disp_source = NULL;
+               }
+
                if (wl_egl_display->thread) {
                        tpl_gthread_destroy(wl_egl_display->thread, NULL);
                        wl_egl_display->thread = NULL;