Add new enum type tpl_gsource_type_t. 68/254768/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Mon, 28 Dec 2020 07:00:26 +0000 (16:00 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Tue, 9 Mar 2021 08:44:42 +0000 (17:44 +0900)
 - tpl_gsource_type_t can be classified into 4 enums below

  SOURCE_TYPE_UNKNOWN : not specified. it will be classified to NORMAL
  SOURCE_TYPE_NORMAL : normal source
  SOURCE_TYPE_DISPOSABLE : disposable source
  SOURCE_TYPE_FINALIZER : disposable source to finalize normal source.

Change-Id: I8a570929642e98ea89d20f6c63f21f7d96574c27
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl_utils_gthread.c
src/tpl_utils_gthread.h
src/tpl_wl_egl.c

index 66e7b23..6d84137 100644 (file)
@@ -24,7 +24,7 @@ struct _tpl_gsource {
        tpl_bool_t             is_eventfd;
        tpl_gsource_functions *gsource_funcs;
 
-       tpl_bool_t             is_disposable;
+       tpl_gsource_type_t     type;
 
        void                  *data;
 };
@@ -187,7 +187,7 @@ _thread_source_dispatch(GSource *source, GSourceFunc cb, gpointer data)
                                 gsource, gsource->fd, cond);
        }
 
-       if (gsource->is_disposable)
+       if (gsource->type == SOURCE_TYPE_DISPOSABLE)
                ret = TPL_GSOURCE_REMOVE;
 
        return ret;
@@ -219,7 +219,7 @@ static GSourceFuncs _thread_source_funcs = {
 
 tpl_gsource *
 tpl_gsource_create(tpl_gthread *thread, void *data, int fd,
-                                  tpl_gsource_functions *funcs, tpl_bool_t is_disposable)
+                                  tpl_gsource_functions *funcs, tpl_gsource_type_t type)
 {
        tpl_gsource *new_gsource = NULL;
 
@@ -241,12 +241,13 @@ tpl_gsource_create(tpl_gthread *thread, void *data, int fd,
                new_gsource->is_eventfd = TPL_TRUE;
        } else {
                new_gsource->fd = fd;
+               new_gsource->is_eventfd = TPL_FALSE;
        }
 
        new_gsource->thread        = thread;
        new_gsource->gsource_funcs = funcs;
        new_gsource->data          = data;
-       new_gsource->is_disposable = is_disposable;
+       new_gsource->type          = type;
 
        new_gsource->tag = g_source_add_unix_fd(&new_gsource->gsource,
                                                                                        new_gsource->fd,
index 084754c..4da3828 100644 (file)
@@ -19,6 +19,14 @@ typedef void (*tpl_gthread_func) (void *user_data);
 typedef GMutex tpl_gmutex;
 typedef GCond tpl_gcond;
 
+typedef enum {
+       SOURCE_TYPE_UNKNOWN = -1, /* not specified. it will be classified to NORMAL */
+       SOURCE_TYPE_NORMAL, /* normal source */
+       SOURCE_TYPE_DISPOSABLE, /* disposable source */
+       SOURCE_TYPE_FINALIZER, /* disposable source to finalize normal source. */
+       SOURCE_TYPE_MAX
+} tpl_gsource_type_t;
+
 struct _tpl_gsource_functions {
        tpl_bool_t (*prepare)  (tpl_gsource *source);
        tpl_bool_t (*check)    (tpl_gsource *source);
@@ -67,9 +75,7 @@ tpl_gthread_destroy(tpl_gthread *thread, tpl_gthread_func deinit_func);
  *  If it is -1, eventfd is created in this function.
  * @param funcs Pointer to tpl_gsource_functions.
  *  This structure corresponds to GSourceFuncs, and dispatch and finalize are required.
- * @param is_disposable If it is intended to be used for single use, TRUE should be passed,
- *  and FALSE should be passed to keep it.
- *  In the case of disposable, it is not necessary to call tpl_gsource_destroy.
+ * @param type Type of source to be created. @see tpl_gsource_type_t
  * @return Pointer to newly created tpl_gsource.
  *
  * All created tpl_gsource resources will be freed in the thread.
@@ -77,7 +83,7 @@ tpl_gthread_destroy(tpl_gthread *thread, tpl_gthread_func deinit_func);
  */
 tpl_gsource *
 tpl_gsource_create(tpl_gthread *thread, void *data, int fd,
-                                  tpl_gsource_functions *funcs, tpl_bool_t is_disposable);
+                                  tpl_gsource_functions *funcs, tpl_gsource_type_t type);
 
 /**
  * Detach the passed tpl_gsource from thread and destroy it.
index 99285b8..4cfb306 100644 (file)
@@ -291,7 +291,7 @@ _thread_tdm_init(tpl_wl_egl_display_t *wl_egl_display)
 
        tdm_source = tpl_gsource_create(wl_egl_display->thread,
                                                                        (void *)wl_egl_display, tdm_display_fd,
-                                                                       &tdm_funcs, TPL_FALSE);
+                                                                       &tdm_funcs, SOURCE_TYPE_NORMAL);
        if (!tdm_source) {
                TPL_ERR("Failed to create tdm_gsource\n");
                tdm_client_destroy(tdm_client);
@@ -593,7 +593,7 @@ __tpl_wl_egl_display_init(tpl_display_t *display)
        wl_egl_display->disp_source = tpl_gsource_create(wl_egl_display->thread,
                                                                                                         (void *)wl_egl_display,
                                                                                                         wl_display_get_fd(wl_egl_display->wl_display),
-                                                                                                        &disp_funcs, TPL_FALSE);
+                                                                                                        &disp_funcs, SOURCE_TYPE_NORMAL);
        if (!wl_egl_display->disp_source) {
                TPL_ERR("Failed to add native_display(%p) to thread(%p)",
                                display->native_handle,