Module without data thread does not execute a data socket close 12/210812/8 accepted/tizen/unified/20190730.224236 submit/tizen/20190729.062055
authorYoungHun Kim <yh8004.kim@samsung.com>
Thu, 25 Jul 2019 04:38:34 +0000 (13:38 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Fri, 26 Jul 2019 06:52:31 +0000 (15:52 +0900)
 - update the thread exit

Change-Id: Ieabaab75cf8166d3942694b42147d4259efecef3

server/include/muse_server_private.h
server/src/muse_server_ipc.c
server/src/muse_server_private.c

index 6734f35..5d08f94 100644 (file)
@@ -102,7 +102,6 @@ void ms_new(void);
 void ms_gst_init(char **cmd);
 int ms_run(char **cmd, int notify_fd);
 void ms_cmd_dispatch(muse_module_h m, muse_module_command_e cmd);
-void ms_exit_worker(muse_module_h m);
 void ms_respawn(int signo);
 int ms_get_pid(muse_module_h m);
 void ms_log_process_info(int pid);
index 8dbd528..f70a4e5 100644 (file)
 #define DATA_WORKER_QDATA_MAX_SIZE                     (3840 * 2160 * 4) /* UHD BGRA8888 */
 #define UNLIMITED_INSTANCE                                     -1
 
+static void _ms_ipc_module_data_ch_cleanup(muse_module_h m);
+static void _ms_ipc_module_msg_ch_cleanup(muse_module_h m);
 static void _ms_ipc_module_cleanup(muse_module_h m);
 static gboolean _ms_ipc_module_instance_creation_is_allowed(int module_idx);
 static gpointer _ms_ipc_dispatch_worker(gpointer data);
 static gboolean _ms_ipc_data_processing(int fd, muse_recv_data_head_t *header, muse_channel_info_t *ch);
 static gpointer _ms_ipc_data_worker(gpointer data);
 
-static void _ms_ipc_module_cleanup(muse_module_h m)
+static void _ms_ipc_module_data_ch_cleanup(muse_module_h m)
 {
        muse_return_if_fail(m);
+       muse_return_if_fail(m->ch[MUSE_CHANNEL_DATA].thread);
+
+       g_thread_join(m->ch[MUSE_CHANNEL_DATA].thread);
+       m->ch[MUSE_CHANNEL_DATA].thread = NULL;
 
        g_mutex_lock(&m->ch[MUSE_CHANNEL_DATA].data_mutex);
        g_queue_free(m->ch[MUSE_CHANNEL_DATA].data_queue);
@@ -44,18 +50,42 @@ static void _ms_ipc_module_cleanup(muse_module_h m)
        g_cond_broadcast(&m->ch[MUSE_CHANNEL_DATA].data_cond);
        g_mutex_unlock(&m->ch[MUSE_CHANNEL_DATA].data_mutex);
 
-       if (m->ch[MUSE_CHANNEL_DATA].thread) {
-               g_thread_join(m->ch[MUSE_CHANNEL_DATA].thread);
-               m->ch[MUSE_CHANNEL_DATA].thread = NULL;
-       }
-
        g_mutex_clear(&m->ch[MUSE_CHANNEL_DATA].data_mutex);
        g_cond_clear(&m->ch[MUSE_CHANNEL_DATA].data_cond);
-       LOGD("worker exit");
+
+       LOGD("[close] [%d] MUSE_CHANNEL_DATA", m->ch[MUSE_CHANNEL_DATA].sock_fd);
+       muse_core_connection_close(m->ch[MUSE_CHANNEL_DATA].sock_fd);
+
+}
+
+static void _ms_ipc_module_msg_ch_cleanup(muse_module_h m)
+{
+       muse_return_if_fail(m);
+       muse_return_if_fail(m->ch[MUSE_CHANNEL_MSG].thread);
+
+       SECURE_LOGD("[close] [%d] MUSE_CHANNEL_MSG %p", m->ch[MUSE_CHANNEL_MSG].sock_fd, m);
+       muse_core_connection_close(m->ch[MUSE_CHANNEL_MSG].sock_fd);
+
+       SECURE_LOGD("%p thread exit", m->ch[MUSE_CHANNEL_MSG].thread);
+       g_thread_unref(m->ch[MUSE_CHANNEL_MSG].thread);
+       m->ch[MUSE_CHANNEL_MSG].thread = NULL;
+}
+
+static void _ms_ipc_module_cleanup(muse_module_h m)
+{
+       muse_return_if_fail(m);
+
+       _ms_ipc_module_data_ch_cleanup(m);
 
        ms_connection_unregister(m);
 
-       ms_exit_worker(m);
+       _ms_ipc_module_msg_ch_cleanup(m);
+
+       g_mutex_clear(&m->dispatch_lock);
+
+       memset(m, 0, sizeof(muse_module_t));
+
+       free(m);
 }
 
 static gboolean _ms_ipc_module_instance_creation_is_allowed(int module_idx)
@@ -132,7 +162,8 @@ static gpointer _ms_ipc_dispatch_worker(gpointer data)
                                                if (!_ms_ipc_module_instance_creation_is_allowed(idx)) {
                                                        ms_cmd_dispatch(m, MUSE_MODULE_COMMAND_RESOURCE_NOT_AVAILABLE);
                                                        ms_module_dispatch_unlock(m);
-                                                       ms_exit_worker(m);
+                                                       attempt_to_dispatch = FALSE;
+                                                       break;
                                                }
                                                if (muse_core_msg_object_get_value(MSG_KEY_PID, jobj, MUSE_TYPE_INT, &pid) && m->pid != pid)
                                                        LOGW("connected pid [%d] msg [%d] is different", m->pid, pid);
@@ -177,7 +208,8 @@ static gpointer _ms_ipc_dispatch_worker(gpointer data)
                                                        if (!_ms_ipc_module_instance_creation_is_allowed(idx)) {
                                                                ms_cmd_dispatch(m, MUSE_MODULE_COMMAND_RESOURCE_NOT_AVAILABLE);
                                                                ms_module_dispatch_unlock(m);
-                                                               ms_exit_worker(m);
+                                                               attempt_to_dispatch = FALSE;
+                                                               break;
                                                        }
                                                        ms_connection_register(m);
 
@@ -217,7 +249,9 @@ static gpointer _ms_ipc_dispatch_worker(gpointer data)
 
        _ms_ipc_module_cleanup(m);
 
-       LOGD("Leave");
+       LOGD("worker exit");
+       g_thread_exit(NULL);
+
        return NULL;
 }
 
index 64f0574..95edcec 100644 (file)
@@ -614,6 +614,8 @@ int ms_deinit(void)
        muse_return_val_if_fail(muse_server->watchdog, retval);
        muse_return_val_if_fail(muse_server->workqueue, retval);
 
+       ms_recursive_rmdir(MUSE_DATA_ROOT_PATH);
+
        ms_set_state(MUSE_SERVER_STATE_IDLE);
 
 #ifdef MUSE_USE_WATCHDOG
@@ -826,37 +828,6 @@ void ms_cmd_dispatch(muse_module_h m, muse_module_command_e cmd)
        }
 }
 
-void ms_exit_worker(muse_module_h m)
-{
-       LOGD("Enter");
-
-       muse_return_if_fail(m);
-
-       SECURE_LOGD("[close] [%d] MUSE_CHANNEL_MSG %p", m->ch[MUSE_CHANNEL_MSG].sock_fd, m);
-       muse_core_connection_close(m->ch[MUSE_CHANNEL_MSG].sock_fd);
-
-       LOGD("[close] [%d] MUSE_CHANNEL_DATA", m->ch[MUSE_CHANNEL_DATA].sock_fd);
-       muse_core_connection_close(m->ch[MUSE_CHANNEL_DATA].sock_fd);
-
-       SECURE_LOGD("%p thread exit", m->ch[MUSE_CHANNEL_MSG].thread);
-       if (m->ch[MUSE_CHANNEL_MSG].thread) {
-               g_thread_unref(m->ch[MUSE_CHANNEL_MSG].thread);
-               m->ch[MUSE_CHANNEL_MSG].thread = NULL;
-       }
-
-       g_mutex_clear(&m->dispatch_lock);
-
-       memset(m, 0, sizeof(muse_module_t));
-
-       free(m);
-
-       ms_recursive_rmdir(MUSE_DATA_ROOT_PATH);
-
-       LOGD("Leave");
-
-       g_thread_exit(NULL);
-}
-
 void ms_respawn(int signo)
 {
        pid_t pid = getpid();