utils_gthread: add enum type to distinguish the fd type 93/295593/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Mon, 10 Jul 2023 11:06:47 +0000 (20:06 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Tue, 11 Jul 2023 06:47:33 +0000 (15:47 +0900)
Change-Id: Idca314bb4cb28cae973c56b9bc99a32195924e47
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl_utils_gthread.c
src/tpl_utils_gthread.h
src/tpl_wl_egl_thread.c
src/tpl_wl_vk_thread.c

index 4b17598..8406753 100644 (file)
@@ -24,7 +24,7 @@ struct _tpl_gsource {
        tpl_gthread           *thread;
 
        int                    fd;
-       tpl_bool_t             is_eventfd;
+       fd_type_t              fd_type;
        tpl_gsource_functions *gsource_funcs;
 
        tpl_gsource_type_t     type;
@@ -187,7 +187,7 @@ _thread_source_dispatch(GSource *source, GSourceFunc cb, gpointer data)
                ssize_t s;
                uint64_t message = 0;
 
-               if (gsource->is_eventfd) {
+               if (gsource->fd_type == FD_TYPE_EVENT) {
                        s = read(gsource->fd, &message, sizeof(uint64_t));
                        if (s != sizeof(uint64_t)) {
                                TPL_ERR("Failed to read from event_fd(%d)",
@@ -245,7 +245,7 @@ _thread_source_finalize(GSource *source)
        if (gsource->gsource_funcs && gsource->gsource_funcs->finalize)
                gsource->gsource_funcs->finalize(gsource);
 
-       if (gsource->is_eventfd)
+       if (gsource->fd_type == FD_TYPE_EVENT)
                close(gsource->fd);
 
        gsource->fd = -1;
@@ -263,7 +263,7 @@ static GSourceFuncs _thread_source_funcs = {
 };
 
 tpl_gsource *
-tpl_gsource_create(tpl_gthread *thread, void *data, int fd,
+tpl_gsource_create(tpl_gthread *thread, void *data, int fd, fd_type_t fd_type,
                                   tpl_gsource_functions *funcs, tpl_gsource_type_t type)
 {
        tpl_gsource *new_gsource = NULL;
@@ -283,10 +283,10 @@ tpl_gsource_create(tpl_gthread *thread, void *data, int fd,
                        return NULL;
                }
 
-               new_gsource->is_eventfd = TPL_TRUE;
+               new_gsource->fd_type = FD_TYPE_EVENT;
        } else {
                new_gsource->fd = fd;
-               new_gsource->is_eventfd = TPL_FALSE;
+               new_gsource->fd_type = fd_type;
        }
 
        new_gsource->thread        = thread;
@@ -296,7 +296,7 @@ tpl_gsource_create(tpl_gthread *thread, void *data, int fd,
        new_gsource->intended_destroy = TPL_FALSE;
 
        if (new_gsource->type == SOURCE_TYPE_NORMAL) {
-               tpl_gsource *finalizer = tpl_gsource_create(thread, new_gsource, -1,
+               tpl_gsource *finalizer = tpl_gsource_create(thread, new_gsource, -1, FD_TYPE_NONE,
                                                                                                        NULL, SOURCE_TYPE_FINALIZER);
                new_gsource->finalizer = finalizer;
        } else
@@ -365,7 +365,7 @@ tpl_gsource_send_message(tpl_gsource *source, uint64_t message)
        uint64_t value = message;
        int ret;
 
-       if (!source->is_eventfd) {
+       if (source->fd_type != FD_TYPE_EVENT) {
                TPL_ERR("source is not using eventfd. source(%p) fd(%d)",
                                source, source->fd);
                return;
index c6ae5a4..b5f0eb5 100644 (file)
@@ -17,6 +17,14 @@ typedef GMutex tpl_gmutex;
 typedef GCond tpl_gcond;
 
 typedef enum {
+       FD_TYPE_NONE = -1, /* not specified */
+       FD_TYPE_EVENT, /* event fd. should close it when finalize */
+       FD_TYPE_FENCE, /* fence fd. should close after waiting until it signaled */
+       FD_TYPE_SOCKET, /* socket fd. cannot close this passed fd */
+       FD_TYPE_MAX
+} fd_type_t;
+
+typedef enum {
        SOURCE_TYPE_UNKNOWN = -1, /* not specified. it will be classified to NORMAL */
        SOURCE_TYPE_NORMAL, /* normal source */
        SOURCE_TYPE_DISPOSABLE, /* disposable source */
@@ -83,7 +91,7 @@ tpl_gthread_destroy(tpl_gthread *thread);
  * @see tpl_gsource_destroy
  */
 tpl_gsource *
-tpl_gsource_create(tpl_gthread *thread, void *data, int fd,
+tpl_gsource_create(tpl_gthread *thread, void *data, int fd, fd_type_t fd_type,
                                   tpl_gsource_functions *funcs, tpl_gsource_type_t type);
 
 /**
index 84e8d08..6debf26 100755 (executable)
@@ -931,6 +931,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),
+                                                                                                        FD_TYPE_SOCKET,
                                                                                                         &disp_funcs, SOURCE_TYPE_NORMAL);
        if (!wl_egl_display->disp_source) {
                TPL_ERR("Failed to add native_display(%p) to thread(%p)",
@@ -946,6 +947,7 @@ __tpl_wl_egl_display_init(tpl_display_t *display)
                wl_egl_display->tdm.tdm_source = tpl_gsource_create(wl_egl_display->thread,
                                                                                                                (void *)wl_egl_display,
                                                                                                                wl_egl_display->tdm.tdm_display_fd,
+                                                                                                               FD_TYPE_SOCKET,
                                                                                                                &tdm_funcs, SOURCE_TYPE_NORMAL);
                wl_egl_display->tdm.gsource_finalized = TPL_FALSE;
                if (!wl_egl_display->tdm.tdm_source) {
@@ -1771,7 +1773,7 @@ __tpl_wl_egl_surface_init(tpl_surface_t *surface)
        }
 
        surf_source = tpl_gsource_create(wl_egl_display->thread, (void *)wl_egl_surface,
-                                                                        -1, &surf_funcs, SOURCE_TYPE_NORMAL);
+                                                                        -1, FD_TYPE_NONE, &surf_funcs, SOURCE_TYPE_NORMAL);
        if (!surf_source) {
                TPL_ERR("Failed to create surf_source with wl_egl_surface(%p)",
                                wl_egl_surface);
@@ -3008,7 +3010,8 @@ _thread_surface_queue_acquire(tpl_wl_egl_surface_t *wl_egl_surface)
 
                                wl_egl_buffer->waiting_source =
                                        tpl_gsource_create(wl_egl_display->thread, wl_egl_buffer,
-                                                                          wl_egl_buffer->acquire_fence_fd, &buffer_funcs,
+                                                                          wl_egl_buffer->acquire_fence_fd,
+                                                                          FD_TYPE_FENCE, &buffer_funcs,
                                                                           SOURCE_TYPE_DISPOSABLE);
                                wl_egl_buffer->status = WAITING_SIGNALED;
 
index 0592063..a40b4f0 100644 (file)
@@ -789,6 +789,7 @@ __tpl_wl_vk_display_init(tpl_display_t *display)
 
        wl_vk_display->disp_source = tpl_gsource_create(wl_vk_display->thread,
                                                                                                        (void *)wl_vk_display,
+                                                                                                       FD_TYPE_SOCKET,
                                                                                                        wl_display_get_fd(wl_vk_display->wl_display),
                                                                                                        &disp_funcs, SOURCE_TYPE_NORMAL);
        if (!wl_vk_display->disp_source) {
@@ -804,6 +805,7 @@ __tpl_wl_vk_display_init(tpl_display_t *display)
        wl_vk_display->tdm.tdm_source = tpl_gsource_create(wl_vk_display->thread,
                                                                                                   (void *)wl_vk_display,
                                                                                                   wl_vk_display->tdm.tdm_display_fd,
+                                                                                                  FD_TYPE_SOCKET,
                                                                                                   &tdm_funcs, SOURCE_TYPE_NORMAL);
        if (!wl_vk_display->tdm.tdm_source) {
                TPL_ERR("Failed to create tdm_gsource\n");
@@ -1308,7 +1310,7 @@ __tpl_wl_vk_surface_init(tpl_surface_t *surface)
        }
 
        surf_source = tpl_gsource_create(wl_vk_display->thread, (void *)wl_vk_surface,
-                                                                        -1, &surf_funcs, SOURCE_TYPE_NORMAL);
+                                                                        -1, FD_TYPE_NONE, &surf_funcs, SOURCE_TYPE_NORMAL);
        if (!surf_source) {
                TPL_ERR("Failed to create surf_source with wl_vk_surface(%p)",
                                wl_vk_surface);