added eventfd for io_thread exit 08/117608/1
authorJongkyu Koo <jk.koo@samsung.com>
Mon, 6 Mar 2017 11:55:05 +0000 (20:55 +0900)
committerJongkyu Koo <jk.koo@samsung.com>
Tue, 7 Mar 2017 00:55:05 +0000 (16:55 -0800)
Change-Id: Iedfbdec4943f9e8ff58f071625ac58516e9f701e
Signed-off-by: Jongkyu Koo <jk.koo@samsung.com>
src/pims-ipc.c

index 05bb611..805f05c 100644 (file)
@@ -89,6 +89,7 @@ typedef struct {
        GList *data_queue;
 
        pthread_mutex_t call_mutex; /* not to be interrupted while sending and receiving */
+       int eventfd;
 } pims_ipc_s;
 
 static unsigned int ref_cnt;
@@ -119,6 +120,8 @@ static void __pims_ipc_free_handle(pims_ipc_s *handle)
        pthread_mutex_lock(&__gmutex);
 
        handle->epoll_stop_thread = TRUE;
+       if (handle->eventfd != -1)
+               eventfd_write(handle->eventfd, 1);
 
        if (handle->fd != -1)
                close(handle->fd);
@@ -193,7 +196,7 @@ static int __pims_ipc_receive_for_subscribe(pims_ipc_s *handle)
 
                cb_data = (pims_ipc_cb_s*)g_hash_table_lookup(handle->subscribe_cb_table, data->call_id);
                if (cb_data == NULL)
-                       VERBOSE("unable to find %s", call_id);
+                       VERBOSE("unable to find %s", data->call_id);
                else
                        cb_data->callback((pims_ipc_h)handle, data->handle, cb_data->user_data);
 
@@ -573,9 +576,14 @@ static void* __io_thread(void *data)
 
        pthread_mutex_lock(&__gmutex);
 
+       handle->eventfd = eventfd(0, EFD_NONBLOCK);
+       ev.data.fd = handle->eventfd;
+       ev.events = EPOLLIN;
+       ret = epoll_ctl(epfd, EPOLL_CTL_ADD, handle->eventfd, &ev);
+       WARN_IF(ret != 0, "listen error :%d", ret);
+
        ev.events = EPOLLIN | EPOLLHUP;
        ev.data.fd = handle->fd;
-
        ret = epoll_ctl(epfd, EPOLL_CTL_ADD, handle->fd, &ev);
        WARN_IF(ret != 0, "listen error :%d", ret);
        pthread_mutex_unlock(&__gmutex);
@@ -597,6 +605,7 @@ static void* __io_thread(void *data)
                pthread_mutex_lock(&__gmutex);
 
                if (handle->epoll_stop_thread) {
+                       DBG("__io_thread epoll_stop_thread");
                        pthread_mutex_unlock(&__gmutex);
                        break;
                }
@@ -630,6 +639,7 @@ static void* __io_thread(void *data)
        }
 
        close(epfd);
+       close(handle->eventfd);
 
        pthread_exit(NULL);
 }
@@ -676,6 +686,7 @@ static pims_ipc_h __pims_ipc_create(char *service, pims_ipc_mode_e mode)
 
                handle->subscribe_fd = -1;
                handle->io_thread = 0;
+               handle->eventfd = -1;
                handle->service = g_strdup(service);
                handle->id = g_strdup_printf("%x:%x", getpid(), __get_global_sequence_no());
                handle->fd = socket(PF_UNIX, SOCK_STREAM, 0);