From 2edce67e411ade5a708e0c03712f2f0f6d3f3ac0 Mon Sep 17 00:00:00 2001 From: YoungHun Kim Date: Thu, 18 Jan 2018 13:54:55 +0900 Subject: [PATCH] Update the global dispatcher's mutex by module instance Change-Id: I817babc236e221930637d6476e9080dc4ce91a18 --- core/include/muse_core_internal.h | 1 + packaging/mused.spec | 2 +- server/include/muse_server_module.h | 2 ++ server/src/muse_server_ipc.c | 24 +++++++++++------------- server/src/muse_server_module.c | 12 ++++++++++++ server/src/muse_server_private.c | 3 +++ 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/core/include/muse_core_internal.h b/core/include/muse_core_internal.h index b9b06db..872bad0 100644 --- a/core/include/muse_core_internal.h +++ b/core/include/muse_core_internal.h @@ -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 { diff --git a/packaging/mused.spec b/packaging/mused.spec index c47c0c9..aba3f77 100644 --- a/packaging/mused.spec +++ b/packaging/mused.spec @@ -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 diff --git a/server/include/muse_server_module.h b/server/include/muse_server_module.h index db77489..9abbf0b 100644 --- a/server/include/muse_server_module.h +++ b/server/include/muse_server_module.h @@ -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); diff --git a/server/src/muse_server_ipc.c b/server/src/muse_server_ipc.c index 3710303..4d16eaa 100644 --- a/server/src/muse_server_ipc.c +++ b/server/src/muse_server_ipc.c @@ -27,14 +27,12 @@ #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; diff --git a/server/src/muse_server_module.c b/server/src/muse_server_module.c index 8c53b22..a749be3 100644 --- a/server/src/muse_server_module.c +++ b/server/src/muse_server_module.c @@ -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; diff --git a/server/src/muse_server_private.c b/server/src/muse_server_private.c index 20af98c..30b5d54 100644 --- a/server/src/muse_server_private.c +++ b/server/src/muse_server_private.c @@ -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); -- 2.7.4