Modify to use the dlsym saved at muse server with mutex lock 48/160248/5 submit/tizen_4.0/20171115.074600
authorYoungHun Kim <yh8004.kim@samsung.com>
Wed, 15 Nov 2017 05:39:29 +0000 (14:39 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Wed, 15 Nov 2017 07:40:32 +0000 (16:40 +0900)
Change-Id: I16067f4bae2a639c98d9ae990fb8b9a0a814a109

packaging/mused.spec
server/src/muse_server_module.c

index f477530..a6488e8 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mused
 Summary:    A multimedia daemon
-Version:    0.3.15
+Version:    0.3.16
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index a5bcb84..6a2fa3c 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "muse_server_private.h"
 
+static GMutex dllsym_table_lock;
+
 static gboolean _ms_module_dispatch_timeout_callback(gpointer data);
 static gboolean _ms_module_enable_dispatch_timeout_callback(int cmd, muse_module_h m);
 static gboolean _ms_module_free_key(gpointer key, gpointer value, gpointer user_data);
@@ -75,24 +77,35 @@ static void _ms_module_set_loaded_dllsym(int idx, GModule *dllsym, gboolean valu
        SECURE_LOGD("dll_handle: %p", module->dllsym);
 }
 
+static gboolean _ms_module_free_key(gpointer key, gpointer value, gpointer user_data)
+{
+       MUSE_G_FREE(key);
+       return TRUE;
+}
+
 GModule *ms_module_open(int idx)
 {
        GModule *dllsym = NULL;
+       ms_module_t *module = ms_get_module_instance(idx);
+
+       g_return_val_if_fail(module, NULL);
+
+       g_mutex_lock(&module->lock);
 
        if (ms_module_get_loaded_dllsym(idx) == false) {
                dllsym = g_module_open(ms_config_get_path(idx), G_MODULE_BIND_LAZY);
 
-               if (!dllsym) {
+               if (!dllsym)
                        LOGE("%s", g_module_error());
-                       return NULL;
-               } else {
+               else
                        _ms_module_set_loaded_dllsym(idx, dllsym, true);
-               }
-       } else if (ms_module_get_loaded_dllsym(idx) == true) {
+       } else {
                dllsym = ms_module_get_dllsym(idx);
                SECURE_LOGW("already module is opened: %p", dllsym);
        }
 
+       g_mutex_unlock(&module->lock);
+
        return dllsym;
 }
 
@@ -110,8 +123,10 @@ int ms_module_dispatch(muse_module_h m, int cmd)
        module = ms_get_module_instance(m->idx);
        g_return_val_if_fail(module, MUSE_ERR);
 
-       if (m->ch[MUSE_CHANNEL_MSG].dll_handle) {
-               g_module_symbol(m->ch[MUSE_CHANNEL_MSG].dll_handle, DISPATCHER, (gpointer *)&dispatcher);
+       g_mutex_lock(&module->lock);
+
+       if (module->dllsym) {
+               g_module_symbol(module->dllsym, DISPATCHER, (gpointer *)&dispatcher);
 
                m->last_cmd = cmd;
 
@@ -135,25 +150,37 @@ int ms_module_dispatch(muse_module_h m, int cmd)
                        }
                } else {
                        LOGE("[%s] [%d] error - dispatcher", ms_get_instance()->conf->host[m->idx], cmd);
-                       return MUSE_ERR;
+                       ret = MUSE_ERR;
                }
        }
 
+       g_mutex_unlock(&module->lock);
+
        return ret;
 }
 
 gboolean ms_module_close(muse_module_h m)
 {
+       ms_module_t *module = NULL;
+
        g_return_val_if_fail(m, FALSE);
 
+       module = ms_get_module_instance(m->idx);
+       g_return_val_if_fail(module, FALSE);
+
+       g_mutex_lock(&module->lock);
+
        LOGD("Closing module %s", g_module_name(m->ch[MUSE_CHANNEL_MSG].dll_handle));
        if (!g_module_close(m->ch[MUSE_CHANNEL_MSG].dll_handle)) {
                LOGE("Couldn't close dll_handle %s: %s", g_module_name(m->ch[MUSE_CHANNEL_MSG].dll_handle), g_module_error());
+               g_mutex_unlock(&module->lock);
                return FALSE;
        }
 
        _ms_module_set_loaded_dllsym(m->idx, NULL, false);
 
+       g_mutex_unlock(&module->lock);
+
        return TRUE;
 }
 GModule *ms_module_get_dllsym(int idx)
@@ -180,7 +207,7 @@ void ms_module_set_dllsym_value(int idx, const char *name, gpointer value)
        g_return_if_fail(module);
        g_return_if_fail(name);
 
-       g_mutex_lock(&module->lock);
+       g_mutex_lock(&dllsym_table_lock);
 
        /* Try looking up this key. */
        if (g_hash_table_lookup_extended(module->dllsym_table, name, &orig_key, NULL)) {
@@ -192,7 +219,7 @@ void ms_module_set_dllsym_value(int idx, const char *name, gpointer value)
                g_hash_table_insert(module->dllsym_table, g_strdup(name), value);
        }
 
-       g_mutex_unlock(&module->lock);
+       g_mutex_unlock(&dllsym_table_lock);
 }
 
 int ms_module_get_dllsym_value(int idx, const char *name, gpointer *value)
@@ -232,12 +259,6 @@ int ms_module_get_timeout(int idx, int disp_api)
        return module->disp_timeout[disp_api];
 }
 
-static gboolean _ms_module_free_key(gpointer key, gpointer value, gpointer user_data)
-{
-       MUSE_G_FREE(key);
-       return TRUE;
-}
-
 void ms_module_deinit(ms_module_t *module)
 {
        g_return_if_fail(module);