Update the diagnostic thread structure 11/235211/8
authorYoungHun Kim <yh8004.kim@samsung.com>
Wed, 3 Jun 2020 00:00:09 +0000 (09:00 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Wed, 3 Jun 2020 05:15:24 +0000 (14:15 +0900)
Change-Id: I223d6e2840d84aa88899045aa7e2d5507a5afbad

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

index aa53b40..62a426e 100644 (file)
@@ -40,7 +40,6 @@ typedef enum {
 typedef struct ms_connection {
        int instance_count[MUSE_MODULE_MAX];
        GQueue *instance_q;
-       GAsyncQueue *msg_aq;
        GMutex lock;
 } ms_connection_t;
 
index 481f076..296cc6c 100644 (file)
@@ -68,6 +68,12 @@ typedef struct connection_msg {
        int cmd;
 } ms_diag_msg_t;
 
+typedef struct ms_diag {
+       GThread *idle_state_thread;
+       GThread *conn_event_thread;
+       GAsyncQueue *msg_aq;
+} ms_diag_t;
+
 typedef struct _muse_server {
        int msg_fd;
        int data_fd;
@@ -78,8 +84,7 @@ typedef struct _muse_server {
        int cpu_threshold;
        tbm_bufmgr bufmgr;
        GMainLoop *main_loop;
-       GThread *diag_idle_state_thread;
-       GThread *diag_connection_event_thread;
+       ms_diag_t diag;
        ms_config_t *conf;
        ms_connection_t *connection;
        ms_module_t *module[MUSE_MODULE_MAX];
@@ -112,7 +117,6 @@ ms_module_t *ms_get_module_instance(int idx);
 int ms_deinit(void);
 void ms_check_cpu_memory(void);
 void ms_new(void);
-int ms_open_lockfile(void);
 void ms_run(void);
 void ms_cmd_dispatch(muse_module_h m, muse_module_command_e cmd);
 void ms_respawn(int signo);
@@ -126,8 +130,6 @@ void ms_deinit_bufmgr(void);
 void ms_cmd_dispatch_foreach_func(gpointer data, gpointer user_data);
 void ms_set_state(ms_state_e state);
 gboolean ms_is_server_ready(void);
-void ms_diag_thread_create(void);
-void ms_diag_thread_destroy(void);
 gboolean ms_create_ready_file(void);
 void ms_remove_ready_file(void);
 const char *ms_get_command_string(int cmd);
index f66ca96..2ffab95 100644 (file)
 
 #define EPOLL_ERR -1
 
-static void _ms_connection_destroy_async_queue(gpointer data);
 static void _ms_connection_module_instance_info(muse_module_h m, ms_connection_t *connection, GQueue *queue, int cmd);
 
-static void _ms_connection_destroy_async_queue(gpointer data)
-{
-       ms_diag_msg_t *dm = (ms_diag_msg_t *)data;
-
-       LOGI("diag msg (%p) free", dm);
-       g_free(dm);
-}
-
 static void _ms_connection_module_instance_info(muse_module_h m, ms_connection_t *connection, GQueue *queue, int cmd)
 {
        muse_module_h connecting_m;
@@ -41,11 +32,14 @@ static void _ms_connection_module_instance_info(muse_module_h m, ms_connection_t
        char pid[MUSE_PARAM_MAX] = {'\0',};
        int idx, len;
        ms_diag_msg_t *dm;
+       muse_server_h ms;
 
        muse_return_if_fail(m);
        muse_return_if_fail(connection);
        muse_return_if_fail(queue);
-       muse_return_if_fail(ms_get_instance());
+
+       ms = ms_get_instance();
+       muse_return_if_fail(ms);
 
        len = g_queue_get_length(queue);
 
@@ -60,16 +54,14 @@ static void _ms_connection_module_instance_info(muse_module_h m, ms_connection_t
                strncat(pids, pid, MUSE_MSG_LEN_MAX - strlen(pids) - 1);
        }
 
-       strncpy(ms_get_instance()->instance_pid_info, pids, MUSE_MSG_LEN_MAX);
+       strncpy(ms->instance_pid_info, pids, MUSE_MSG_LEN_MAX);
 
        dm = g_new0(ms_diag_msg_t, 1);
-
        dm->cmd = cmd;
-
-       g_async_queue_push(connection->msg_aq, (gpointer)dm);
+       g_async_queue_push(ms->diag.msg_aq, (gpointer)dm);
 
        LOGW("total number of modules = %d ( %s) - %s %p from pid %d %s client (count %d)",
-               len, ms_get_instance()->instance_pid_info, ms_get_command_string(cmd), m, m->pid,
+               len, ms->instance_pid_info, ms_get_command_string(cmd), m, m->pid,
                ms_config_get_host_name(m->idx), connection->instance_count[m->idx]);
 }
 
@@ -169,9 +161,6 @@ void ms_connection_deinit(ms_connection_t *connection)
        g_queue_free(connection->instance_q);
        connection->instance_q = NULL;
 
-       g_async_queue_unref(connection->msg_aq);
-       connection->msg_aq = NULL;
-
        g_mutex_clear(&connection->lock);
 
        g_free(connection);
@@ -184,9 +173,6 @@ void ms_connection_init(ms_connection_t *connection)
        connection->instance_q = g_queue_new();
        muse_return_if_fail(connection->instance_q);
 
-       connection->msg_aq = g_async_queue_new_full(_ms_connection_destroy_async_queue);
-       muse_return_if_fail(connection->msg_aq);
-
        g_mutex_init(&connection->lock);
 }
 
index 6119022..da93f64 100644 (file)
@@ -72,7 +72,10 @@ static void _ms_unlock_state(void);
 static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition condition, gpointer data);
 #ifdef MUSE_USE_LWIPC
 static void _ms_wait_event(void);
+static void _ms_diag_init(void);
+static void _ms_diag_deinit(void);
 static gboolean _ms_idle_cb(gpointer user_data);
+static int _ms_open_lockfile(void);
 
 static void _ms_wait_event(void)
 {
@@ -459,11 +462,14 @@ static gpointer _ms_diag_check_idle_state_thread(gpointer data)
 
 static gpointer _ms_diag_check_connection_event_thread(gpointer data)
 {
+       ms_diag_t *d;
        ms_diag_msg_t *dm = NULL;
        muse_return_val_if_fail(muse_server, NULL);
 
+       d = &muse_server->diag;
+
        while (ms_is_server_ready()) {
-               dm = (ms_diag_msg_t *)g_async_queue_pop(ms_get_instance()->connection->msg_aq);
+               dm = (ms_diag_msg_t *)g_async_queue_pop(d->msg_aq);
                if (!dm)
                        continue;
 
@@ -498,12 +504,75 @@ static void _ms_unlock_state(void)
        g_mutex_unlock(&muse_server->state_lock);
 }
 
+static void _ms_diag_init(void)
+{
+       ms_diag_t *d;
+       char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
+       GError *error = NULL;
+
+       muse_return_if_fail(muse_server);
+
+       d = &muse_server->diag;
+
+       d->idle_state_thread = g_thread_try_new("diag_idle_state",
+               _ms_diag_check_idle_state_thread, muse_server->main_loop, &error);
+       if (!d->idle_state_thread) {
+               snprintf(err_msg, sizeof(err_msg), "diag_idle_state_thread creation failed : %s", error->message);
+               LOGE("%s", err_msg);
+               g_error_free(error);
+               ms_log_process_info(muse_server->pid);
+       }
+
+       d->msg_aq = g_async_queue_new_full(g_free);
+       muse_return_if_fail(d->msg_aq);
+
+       d->conn_event_thread = g_thread_try_new("diag_connection_event",
+               _ms_diag_check_connection_event_thread, muse_server->main_loop, &error);
+       if (!d->conn_event_thread) {
+               snprintf(err_msg, sizeof(err_msg), "diag_connection_event_thread creation failed : %s", error->message);
+               LOGE("%s", err_msg);
+               g_error_free(error);
+               ms_log_process_info(muse_server->pid);
+       }
+}
+
+static void _ms_diag_deinit(void)
+{
+       ms_diag_t *d;
+       ms_diag_msg_t *dm;
+
+       LOGD("Enter");
+
+       muse_return_if_fail(muse_server);
+
+       d = &muse_server->diag;
+
+       dm = g_new0(ms_diag_msg_t, 1);
+
+       dm->thread_stop = TRUE;
+       LOGI("[%p] g_async_queue_push", dm);
+       g_async_queue_push_front(d->msg_aq, (gpointer)dm);
+
+       if (d->idle_state_thread) {
+               g_thread_join(d->idle_state_thread);
+               d->idle_state_thread = NULL;
+       }
+
+       if (d->conn_event_thread) {
+               g_thread_join(d->conn_event_thread);
+               d->conn_event_thread = NULL;
+       }
+
+       g_async_queue_unref(d->msg_aq);
+       d->msg_aq = NULL;
+}
+
 static gboolean _ms_idle_cb(gpointer user_data)
 {
        if (!ms_create_ready_file())
                LOGE("%s file creation is failed", MUSE_SERVER_READY);
 
-       ms_diag_thread_create();
+       _ms_diag_init();
 
        return G_SOURCE_REMOVE;
 }
@@ -555,7 +624,7 @@ static void _ms_init(void)
        LOGD("Leave");
 }
 
-int ms_open_lockfile(void)
+static int _ms_open_lockfile(void)
 {
        int fd, already_running;
        char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
@@ -600,59 +669,6 @@ int ms_open_lockfile(void)
        return MM_ERROR_NONE;
 }
 
-void ms_diag_thread_create(void)
-{
-       char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
-       GError *error = NULL;
-
-       muse_return_if_fail(muse_server);
-
-       muse_server->diag_idle_state_thread = g_thread_try_new("diag_idle_state",
-               _ms_diag_check_idle_state_thread, muse_server->main_loop, &error);
-       if (!muse_server->diag_idle_state_thread && error) {
-               snprintf(err_msg, sizeof(err_msg), "diag_idle_state_thread creation failed : %s", error->message);
-               LOGE("%s", err_msg);
-               g_error_free(error);
-               ms_log_process_info(muse_server->pid);
-       }
-
-       muse_server->diag_connection_event_thread = g_thread_try_new("diag_connection_event",
-               _ms_diag_check_connection_event_thread, muse_server->main_loop, &error);
-       if (!muse_server->diag_connection_event_thread && error) {
-               snprintf(err_msg, sizeof(err_msg), "diag_connection_event_thread creation failed : %s", error->message);
-               LOGE("%s", err_msg);
-               g_error_free(error);
-               ms_log_process_info(muse_server->pid);
-       }
-}
-
-void ms_diag_thread_destroy(void)
-{
-       ms_diag_msg_t *dm;
-
-       muse_return_if_fail(muse_server);
-
-       LOGD("Enter");
-
-       dm = g_new0(ms_diag_msg_t, 1);
-
-       dm->thread_stop = TRUE;
-       LOGI("[%p] g_async_queue_push", dm);
-       g_async_queue_push_front(muse_server->connection->msg_aq, (gpointer)dm);
-
-       if (muse_server->diag_idle_state_thread) {
-               g_thread_join(muse_server->diag_idle_state_thread);
-               muse_server->diag_idle_state_thread = NULL;
-       }
-
-       if (muse_server->diag_connection_event_thread) {
-               g_thread_join(muse_server->diag_connection_event_thread);
-               muse_server->diag_connection_event_thread = NULL;
-       }
-
-       LOGD("Leave");
-}
-
 void ms_setup_syslog(void)
 {
        int flags = LOG_CONS|LOG_NDELAY|LOG_PID;
@@ -913,9 +929,7 @@ void ms_init(char **argv)
 
        _ms_init();
 
-       muse_return_if_fail(ms_get_instance());
-
-       muse_return_if_fail(ms_open_lockfile() == MM_ERROR_NONE);
+       muse_return_if_fail(_ms_open_lockfile() == MM_ERROR_NONE);
 
        ms_new();
 
@@ -925,10 +939,10 @@ void ms_init(char **argv)
        trace_end();
 #endif
 
-       ms_system_subscribe_external_event(ms_get_instance()->system);
+       ms_system_subscribe_external_event(muse_server->system);
 
 #ifdef MUSE_USE_WATCHDOG
-       if (!ms_watchdog_attach(ms_get_instance()->watchdog)) {
+       if (!ms_watchdog_attach(muse_server->watchdog)) {
                LOGE("watchdog thread failed");
                ms_log_process_info(muse_server->pid);
                return;
@@ -1003,14 +1017,12 @@ int ms_deinit(void)
        muse_return_val_if_fail(muse_server->log, retval);
        muse_return_val_if_fail(muse_server->security, retval);
        muse_return_val_if_fail(muse_server->watchdog, retval);
-       muse_return_val_if_fail(muse_server->diag_idle_state_thread, retval);
-       muse_return_val_if_fail(muse_server->diag_connection_event_thread, retval);
 
        ms_recursive_rmdir(MUSE_DATA_ROOT_PATH);
 
        ms_set_state(MUSE_SERVER_STATE_IDLE);
 
-       ms_diag_thread_destroy();
+       _ms_diag_deinit();
 
 #ifdef MUSE_USE_WATCHDOG
        ms_watchdog_detach(muse_server->watchdog);