tpl_wayland_egl_thread: Modified naming and usage of twe_del_source. 92/151892/3
authorjoonbum.ko <joonbum.ko@samsung.com>
Wed, 20 Sep 2017 04:25:25 +0000 (13:25 +0900)
committerjoonbum.ko <joonbum.ko@samsung.com>
Mon, 25 Sep 2017 02:31:05 +0000 (11:31 +0900)
- To extend the usability of the 'twe_wl_disp_del_source'
 that was created to delete the disp_source, I changed naming
 to 'twe_del_source' and changed the associated functions to be common.

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

index 8823d8c..29f2a5a 100644 (file)
@@ -25,7 +25,7 @@ typedef struct _twe_wl_disp_source            twe_wl_disp_source;
 typedef struct _twe_wl_surf_source             twe_wl_surf_source;
 typedef struct _twe_wl_buffer_info             twe_wl_buffer_info;
 typedef struct _twe_tdm_source                 twe_tdm_source;
-typedef struct _twe_wl_disp_del_source twe_wl_disp_del_source;
+typedef struct _twe_del_source                 twe_del_source;
 
 struct _twe_thread_context {
        int ref_cnt;
@@ -56,17 +56,18 @@ struct _twe_wl_disp_source {
        struct wayland_tbm_client *wl_tbm_client;
        struct tizen_surface_shm *tss; /* used for surface buffer_flush */
        tpl_bool_t prepared;
-       twe_wl_disp_del_source *disp_del_source;
+       twe_del_source *disp_del_source;
        twe_thread *thread;
        tpl_object_t obj;
        /* TODO : surface list */
 };
 
-struct _twe_wl_disp_del_source {
+struct _twe_del_source {
        GSource gsource;
        gpointer tag;
        int event_fd;
-       twe_wl_disp_source* disp_source;
+       void* target_source;
+       void (*destroy_target_source_func)(void *);
 };
 
 struct _twe_wl_surf_source {
@@ -550,8 +551,9 @@ _twe_display_shm_fini(twe_wl_disp_source *disp_source)
 }
 
 static void
-_twe_thread_wl_disp_del(twe_wl_disp_source *disp_source)
+_twe_thread_wl_disp_source_destroy(void *source)
 {
+       twe_wl_disp_source *disp_source = (twe_wl_disp_source *)source;
        if (g_source_is_destroyed(&disp_source->gsource)) {
                TPL_ERR("disp_source(%p) already destroyed.", disp_source);
                return;
@@ -581,88 +583,95 @@ _twe_thread_wl_disp_del(twe_wl_disp_source *disp_source)
 }
 
 static gboolean
-_twe_thread_wl_disp_del_dispatch(GSource *source, GSourceFunc cb, gpointer data)
+_twe_thread_del_source_dispatch(GSource *source, GSourceFunc cb, gpointer data)
 {
-       twe_wl_disp_del_source *disp_del_source = (twe_wl_disp_del_source *)source;
+       twe_del_source *del_source = (twe_del_source *)source;
        GIOCondition cond;
 
        if (g_source_is_destroyed(source)) {
-               TPL_ERR("disp_del source(%p) already destroyed.", source);
+               TPL_ERR("del_source(%p) already destroyed.", source);
                return G_SOURCE_REMOVE;
        }
 
-       cond = g_source_query_unix_fd(source, disp_del_source->tag);
+       cond = g_source_query_unix_fd(source, del_source->tag);
 
        if (cond & G_IO_IN) {
                ssize_t s;
                uint64_t u;
 
-               s = read(disp_del_source->event_fd, &u, sizeof(uint64_t));
+               s = read(del_source->event_fd, &u, sizeof(uint64_t));
                if (s != sizeof(uint64_t))
                        TPL_ERR("Failed to read from event_fd(%d)",
-                                       disp_del_source->event_fd);
+                                       del_source->event_fd);
 
-               _twe_thread_wl_disp_del(disp_del_source->disp_source);
+               if (del_source->destroy_target_source_func)
+                       del_source->destroy_target_source_func(del_source->target_source);
        }
 
        return G_SOURCE_CONTINUE;
 }
 
 static void
-_twe_thread_wl_disp_del_finalize(GSource *source)
+_twe_thread_del_source_finalize(GSource *source)
 {
-       twe_wl_disp_del_source *disp_del_source =
-               (twe_wl_disp_del_source *)source;
+       twe_del_source *del_source = (twe_del_source *)source;
 
        TPL_LOG_T("WL_EGL", "gsource(%p) event_fd(%d)",
-                         source, disp_del_source->event_fd);
+                         source, del_source->event_fd);
 
-       g_source_remove_unix_fd(source, disp_del_source->tag);
+       g_source_remove_unix_fd(source, del_source->tag);
 
-       close(disp_del_source->event_fd);
+       close(del_source->event_fd);
 
-       disp_del_source->tag = NULL;
-       disp_del_source->event_fd = -1;
+       del_source->tag = NULL;
+       del_source->event_fd = -1;
 
        return;
 }
 
-static GSourceFuncs _twe_wl_disp_del_funcs = {
+static GSourceFuncs _twe_del_source_funcs = {
        .prepare = NULL,
        .check = NULL,
-       .dispatch = _twe_thread_wl_disp_del_dispatch,
-       .finalize = _twe_thread_wl_disp_del_finalize,
+       .dispatch = _twe_thread_del_source_dispatch,
+       .finalize = _twe_thread_del_source_finalize,
 };
 
 static void
-_twe_thread_wl_disp_del_trigger(twe_wl_disp_source *disp_source)
+_twe_thread_del_source_trigger(twe_del_source *del_source)
 {
-       twe_wl_disp_del_source *disp_del_source = disp_source->disp_del_source;
        uint64_t value = 1;
        int ret;
 
-       ret = write(disp_del_source->event_fd, &value, sizeof(uint64_t));
+       if (!del_source || g_source_is_destroyed(&del_source->gsource)) {
+               TPL_ERR("del_source(%p) is already destroyed.", del_source);
+               return;
+       }
+
+       ret = write(del_source->event_fd, &value, sizeof(uint64_t));
        if (ret == -1) {
-               TPL_ERR("failed to send acquirable event. twe_wl_disp_del_source(%p)",
-                               disp_del_source);
+               TPL_ERR("failed to send acquirable event. twe_del_source(%p)",
+                               del_source);
                return;
        }
 }
 
-twe_wl_disp_del_source *
-_twe_display_del_source_init(twe_thread *thread,
-                                                        twe_wl_disp_source *disp_source)
+twe_del_source *
+_twe_del_source_init(twe_thread_context *ctx, void *target_source)
 {
-       twe_thread_context *ctx = thread->ctx;
-       twe_wl_disp_del_source *source = NULL;
+       twe_del_source *source = NULL;
+
+       if (!ctx) {
+               TPL_ERR("Invalid parameter. twe_thread_context is NULL");
+               return NULL;
+       }
 
-       if (!disp_source) {
-               TPL_ERR("Invalid parameter. disp_source is NULL");
+       if (!target_source) {
+               TPL_ERR("Invalid parameter. target_source is NULL");
                return NULL;
        }
 
-       source = (twe_wl_disp_del_source *)g_source_new(&_twe_wl_disp_del_funcs,
-                                                                                               sizeof(twe_wl_disp_del_source));
+       source = (twe_del_source *)g_source_new(&_twe_del_source_funcs,
+                                                                                       sizeof(twe_del_source));
        if (!source) {
                TPL_ERR("[THREAD] Failed to create GSource");
                return NULL;
@@ -678,7 +687,7 @@ _twe_display_del_source_init(twe_thread *thread,
        source->tag = g_source_add_unix_fd(&source->gsource,
                                                                           source->event_fd,
                                                                           G_IO_IN);
-       source->disp_source = disp_source;
+       source->target_source = target_source;
 
        g_source_attach(&source->gsource, g_main_loop_get_context(ctx->twe_loop));
 
@@ -686,7 +695,7 @@ _twe_display_del_source_init(twe_thread *thread,
 }
 
 void
-_twe_display_del_source_fini(twe_wl_disp_del_source *source)
+_twe_del_source_fini(twe_del_source *source)
 {
        g_source_destroy(&source->gsource);
        g_source_unref(&source->gsource);
@@ -726,7 +735,9 @@ twe_display_add(twe_thread* thread, struct wl_display *display)
 
        _twe_display_shm_init(source);
 
-       source->disp_del_source = _twe_display_del_source_init(thread, source);
+       source->disp_del_source = _twe_del_source_init(ctx, source);
+       source->disp_del_source->destroy_target_source_func
+               = _twe_thread_wl_disp_source_destroy;
 
        g_source_set_callback(&source->gsource, NULL, display, NULL);
        g_source_add_poll(&source->gsource, &source->gfd);
@@ -743,7 +754,7 @@ twe_display_del(twe_display_h twe_display)
 {
        gboolean is_destroyed = FALSE;
        twe_wl_disp_source *source = (twe_wl_disp_source *)twe_display;
-       twe_wl_disp_del_source *disp_del_source = NULL;
+       twe_del_source *disp_del_source = NULL;
 
        if (!source ||
                        (is_destroyed = g_source_is_destroyed(&source->gsource))) {
@@ -758,7 +769,7 @@ 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_wl_disp_del_trigger(source);
+       _twe_thread_del_source_trigger(disp_del_source);
 
        while (!g_source_is_destroyed(&source->gsource)) {
                /* Waiting for destroying disp_source */
@@ -766,7 +777,7 @@ twe_display_del(twe_display_h twe_display)
 
        g_source_unref(&source->gsource);
 
-       _twe_display_del_source_fini(disp_del_source);
+       _twe_del_source_fini(disp_del_source);
 
        return TPL_ERROR_NONE;
 }