#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);
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;
}
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;
}
} 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)
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)) {
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)
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);