Update the global dispatcher's mutex by module instance 02/167502/3 submit/tizen_4.0/20180119.024422
authorYoungHun Kim <yh8004.kim@samsung.com>
Thu, 18 Jan 2018 04:54:55 +0000 (13:54 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Fri, 19 Jan 2018 02:41:44 +0000 (11:41 +0900)
Change-Id: I817babc236e221930637d6476e9080dc4ce91a18

core/include/muse_core_internal.h
packaging/mused.spec
server/include/muse_server_module.h
server/src/muse_server_ipc.c
server/src/muse_server_module.c
server/src/muse_server_private.c

index b9b06db..872bad0 100644 (file)
@@ -136,6 +136,7 @@ typedef struct muse_module {
        gpointer user_data;
        intptr_t handle;
        gboolean is_create_api_called;
+       GMutex dispatch_lock;
 } muse_module_t;
 
 typedef struct muse_recv_data_head {
index c47c0c9..aba3f77 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mused
 Summary:    A multimedia daemon
-Version:    0.3.27
+Version:    0.3.28
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index db77489..9abbf0b 100644 (file)
@@ -44,6 +44,8 @@ typedef struct ms_module {
 void ms_module_init(ms_module_t *module);
 void ms_module_deinit(ms_module_t *module);
 GModule *ms_module_open(int idx);
+void ms_module_dispatch_lock(muse_module_h m);
+void ms_module_dispatch_unlock(muse_module_h m);
 int ms_module_dispatch(muse_module_h m, int cmd);
 gboolean ms_module_close(muse_module_h m);
 gboolean ms_module_get_loaded_dllsym(int idx);
index 3710303..4d16eaa 100644 (file)
 #define DATA_WORKER_QDATA_MAX_SIZE                     (3840 * 2160 * 4) /* UHD BGRA8888 */
 #define UNLIMITED_INSTANCE                                     -1
 
-static GMutex dispatch_lock;
-
-static gboolean _ms_ipc_receive_message(int fd, char *buf, int msg_len);
-static gboolean _ms_ipc_data_processing(int fd, muse_recv_data_head_t *header, muse_channel_info_t *ch);
 static void _ms_ipc_module_cleanup(muse_module_h m, void *jobj);
+static gboolean _ms_ipc_module_instance_creation_is_allowed(int module_idx);
 static gpointer _ms_ipc_dispatch_worker(gpointer data);
+static gboolean _ms_ipc_receive_message(int fd, char *buf, int msg_len);
+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 gboolean _ms_ipc_module_instance_creation_is_allowed(int module_idx);
 
 static void _ms_ipc_module_cleanup(muse_module_h m, void *jobj)
 {
@@ -125,13 +123,13 @@ static gpointer _ms_ipc_dispatch_worker(gpointer data)
                                        m->disp_api = cmd;
                                        case API_CREATE:
                                                SECURE_LOGI("CREATE %p %d", m, fd);
-                                               g_mutex_lock(&dispatch_lock);
+                                               ms_module_dispatch_lock(m);
                                                if (muse_core_msg_object_get_value(MSG_KEY_MODULE_INDEX, jobj, MUSE_TYPE_INT, &idx)) {
                                                        m->idx = idx;
                                                        m->ch[MUSE_CHANNEL_MSG].dll_handle = ms_module_open(idx);
                                                        if (!_ms_ipc_module_instance_creation_is_allowed(idx) || !m->ch[MUSE_CHANNEL_MSG].data_thread) {
                                                                ms_cmd_dispatch(m, MUSE_MODULE_COMMAND_RESOURCE_NOT_AVAILABLE);
-                                                               g_mutex_unlock(&dispatch_lock);
+                                                               ms_module_dispatch_unlock(m);
                                                                ms_exit_worker(m);
                                                        }
                                                        if (muse_core_msg_object_get_value(MSG_KEY_PID, jobj, MUSE_TYPE_INT, &pid) && m->pid != pid)
@@ -148,7 +146,7 @@ static gpointer _ms_ipc_dispatch_worker(gpointer data)
                                                        LOGD("module fd: %d dll_handle: %p", fd, m->ch[MUSE_CHANNEL_MSG].dll_handle);
                                                        dispatch_ret = ms_module_dispatch(m, cmd);
                                                }
-                                               g_mutex_unlock(&dispatch_lock);
+                                               ms_module_dispatch_unlock(m);
 
                                                if (dispatch_ret != MM_ERROR_NONE) {
                                                        LOGE("create dispatch failed 0x%x, clean up module", dispatch_ret);
@@ -157,9 +155,9 @@ static gpointer _ms_ipc_dispatch_worker(gpointer data)
                                                break;
                                        case API_DESTROY:
                                                SECURE_LOGI("DESTROY %p %d", m, fd);
-                                               g_mutex_lock(&dispatch_lock);
+                                               ms_module_dispatch_lock(m);
                                                dispatch_ret = ms_module_dispatch(m, cmd);
-                                               g_mutex_unlock(&dispatch_lock);
+                                               ms_module_dispatch_unlock(m);
                                                if (dispatch_ret == MM_ERROR_NONE)
                                                        _ms_ipc_module_cleanup(m, jobj);
                                                else
@@ -169,13 +167,13 @@ static gpointer _ms_ipc_dispatch_worker(gpointer data)
                                                m->ch[MUSE_CHANNEL_MSG].tbm_fd = tbm_fd[0];
 
                                                if (!m->is_create_api_called) {
-                                                       g_mutex_lock(&dispatch_lock);
+                                                       ms_module_dispatch_lock(m);
                                                        if (muse_core_msg_object_get_value(MSG_KEY_MODULE_INDEX, jobj, MUSE_TYPE_INT, &idx)) {
                                                                m->idx = idx;
                                                                m->ch[MUSE_CHANNEL_MSG].dll_handle = ms_module_open(idx);
                                                                if (!_ms_ipc_module_instance_creation_is_allowed(idx)) {
                                                                        ms_cmd_dispatch(m, MUSE_MODULE_COMMAND_RESOURCE_NOT_AVAILABLE);
-                                                                       g_mutex_unlock(&dispatch_lock);
+                                                                       ms_module_dispatch_unlock(m);
                                                                        ms_exit_worker(m);
                                                                }
                                                                ms_connection_register(m);
@@ -195,7 +193,7 @@ static gpointer _ms_ipc_dispatch_worker(gpointer data)
                                                                if (!ms_module_close(m))
                                                                        SECURE_LOGE("module %p close fail", m);
                                                        }
-                                                       g_mutex_unlock(&dispatch_lock);
+                                                       ms_module_dispatch_unlock(m);
                                                        _ms_ipc_module_cleanup(m, jobj);
                                                }
                                                break;
index 8c53b22..a749be3 100644 (file)
@@ -108,6 +108,18 @@ GModule *ms_module_open(int idx)
        return dllsym;
 }
 
+void ms_module_dispatch_lock(muse_module_h m)
+{
+       g_return_if_fail(m);
+       g_mutex_lock(&m->dispatch_lock);
+}
+
+void ms_module_dispatch_unlock(muse_module_h m)
+{
+       g_return_if_fail(m);
+       g_mutex_unlock(&m->dispatch_lock);
+}
+
 int ms_module_dispatch(muse_module_h m, int cmd)
 {
        int ret = MUSE_ERR;
index 20af98c..30b5d54 100644 (file)
@@ -297,6 +297,7 @@ static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition conditio
                }
                m->ch[MUSE_CHANNEL_MSG].sock_fd = client_sockfd;
                m->pid = pid;
+               g_mutex_init(&m->dispatch_lock);
        } else {
                _ms_get_module_addr(client_sockfd, &module_addr);
 
@@ -690,6 +691,8 @@ void ms_exit_worker(muse_module_h m)
        if (m->ch[MUSE_CHANNEL_MSG].data_thread)
                g_thread_unref(m->ch[MUSE_CHANNEL_MSG].data_thread);
 
+       g_mutex_clear(&m->dispatch_lock);
+
        memset(m, 0, sizeof(muse_module_t));
 
        free(m);