From 3668cd228d422e640766ba2208e791ee601cbe2b Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Mon, 24 Oct 2016 18:13:11 +0900 Subject: Add mutex lock for module open/close and set_value function [Version] 0.1.23 [Profile] Common [Issue Type] Update [Dependency module] N/A [Dependency commit] N/A [Test] [M(T) - Boot=(OK), sdb=(OK), Home=(OK), Touch=(OK), Version=tizen-mobile_20161019.4] Change-Id: I2acb6516c7106d533a8e41f610404b5dfabcc485 Signed-off-by: Jeongmo Yang --- include/muse_core_module.h | 1 + packaging/mused.spec | 2 +- src/muse_core_ipc.c | 5 +++++ src/muse_core_module.c | 7 +++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/muse_core_module.h b/include/muse_core_module.h index d8c9639..affc790 100644 --- a/include/muse_core_module.h +++ b/include/muse_core_module.h @@ -50,6 +50,7 @@ typedef struct muse_core_module { void (*set_value) (int, const char *, gpointer); int (*get_value) (int, const char *, gpointer *); void (*free) (void); + GMutex module_lock[MUSE_MODULE_MAX]; gboolean module_loaded[MUSE_MODULE_MAX]; GModule *module[MUSE_MODULE_MAX]; GHashTable *table[MUSE_MODULE_MAX]; diff --git a/packaging/mused.spec b/packaging/mused.spec index 84014f5..55b678a 100644 --- a/packaging/mused.spec +++ b/packaging/mused.spec @@ -1,6 +1,6 @@ Name: mused Summary: A Multimedia Daemon in Tizen Native API -Version: 0.1.22 +Version: 0.1.23 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/src/muse_core_ipc.c b/src/muse_core_ipc.c index 3f2e381..dffaabc 100644 --- a/src/muse_core_ipc.c +++ b/src/muse_core_ipc.c @@ -141,6 +141,9 @@ static gpointer _muse_core_ipc_dispatch_worker(gpointer data) module->ch[MUSE_CHANNEL_MSG].tbm_fd = tbm_fd; if (module->is_create_api_called == false) { + + pthread_mutex_lock(&muse_core_workqueue_get_instance()->jobs_mutex); + if (muse_core_msg_json_deserialize(MUSE_MODULE, module->recvMsg + module->msg_offset, &parse_len, &api_module, &err, MUSE_TYPE_INT)) { module->api_module = api_module; module->ch[MUSE_CHANNEL_DATA].queue = g_queue_new(); @@ -162,6 +165,8 @@ static gpointer _muse_core_ipc_dispatch_worker(gpointer data) muse_core_module_get_instance()->close(module); } + pthread_mutex_unlock(&muse_core_workqueue_get_instance()->jobs_mutex); + _muse_core_ipc_client_cleanup(module); } break; diff --git a/src/muse_core_module.c b/src/muse_core_module.c index 7094998..15ad787 100644 --- a/src/muse_core_module.c +++ b/src/muse_core_module.c @@ -120,6 +120,9 @@ static void _muse_core_module_set_dllsymbol_value(int api_module, const char *ke g_return_if_fail(keyname != NULL); gpointer orig_key; + + g_mutex_lock(&g_muse_core_module->module_lock[api_module]); + /* Try looking up this key. */ if (g_hash_table_lookup_extended(g_muse_core_module->table[api_module], keyname, &orig_key, NULL)) { g_hash_table_remove(g_muse_core_module->table[api_module], keyname); @@ -129,6 +132,8 @@ static void _muse_core_module_set_dllsymbol_value(int api_module, const char *ke /* Insert into our hash table it is not a duplicate. */ g_hash_table_insert(g_muse_core_module->table[api_module], g_strdup(keyname), value); } + + g_mutex_unlock(&g_muse_core_module->module_lock[api_module]); } static int _muse_core_module_get_dllsymbol_value(int api_module, const char *keyname, gpointer *value) @@ -157,6 +162,7 @@ static void _muse_core_module_free(void) g_return_if_fail(g_muse_core_module != NULL); for (idx = 0; idx < MUSE_MODULE_MAX; idx++) { + g_mutex_clear(&g_muse_core_module->module_lock[idx]); g_module_close(g_muse_core_module->module[idx]); g_hash_table_foreach_remove(g_muse_core_module->table[idx], _muse_core_module_free_key, NULL); g_hash_table_destroy(g_muse_core_module->table[idx]); @@ -186,6 +192,7 @@ static void _muse_core_module_init_instance(GModule* (*load) (int), void (*dispa g_muse_core_module->get_value = get_value; for (idx = 0; idx < MUSE_MODULE_MAX; idx++) { + g_mutex_init(&g_muse_core_module->module_lock[idx]); g_muse_core_module->module_loaded[idx] = false; g_muse_core_module->table[idx] = g_hash_table_new(g_str_hash, g_str_equal); g_return_if_fail(g_muse_core_module->table[idx] != NULL); -- cgit v1.2.3