static int g_fd_lang;
static int g_wd_lang;
+static pthread_mutex_t vc_config_mgr_mutex = PTHREAD_MUTEX_INITIALIZER;
int __vc_config_mgr_print_engine_info();
int* get_uid;
vc_config_client_s* temp_client = NULL;
+ if (0 != pthread_mutex_init(&vc_config_mgr_mutex, NULL)) {
+ SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to initialize vc_config_mgr_mutex.");
+ }
+
+ SLOG(LOG_INFO, vc_config_tag(), "[WARNING] Enter critical section");
+ pthread_mutex_lock(&vc_config_mgr_mutex);
+
if (0 < g_slist_length(g_config_client_list)) {
/* Check uid */
iter = g_slist_nth(g_config_client_list, 0);
if (uid == *get_uid) {
SLOG(LOG_WARN, vc_config_tag(), "[CONFIG] uid(%d) has already registered", uid);
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
+ SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
return 0;
}
temp_client = (vc_config_client_s*)calloc(1, sizeof(vc_config_client_s));
if (NULL == temp_client) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to allocate memory");
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_ERROR_OUT_OF_MEMORY;
}
SLOG(LOG_WARN, vc_config_tag(), "[CONFIG] Add uid(%d) but config has already initialized", uid);
__vc_config_mgr_print_client_info();
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
+ SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
return 0;
}
if (0 != access(VC_CONFIG_BASE, F_OK)) {
if (0 != mkdir(VC_CONFIG_BASE, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to make directory : %s", VC_CONFIG_BASE);
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
} else {
SLOG(LOG_DEBUG, vc_config_tag(), "Success to make directory : %s", VC_CONFIG_BASE);
if (0 != access(VC_RUNTIME_INFO_ROOT, F_OK)) {
if (0 != mkdir(VC_RUNTIME_INFO_ROOT, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to make directory : %s", VC_RUNTIME_INFO_ROOT);
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
} else {
SLOG(LOG_DEBUG, vc_config_tag(), "Success to make directory : %s", VC_RUNTIME_INFO_ROOT);
if (0 != vc_parser_load_config(&g_config_info)) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to parse configure information");
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
if (0 != __vc_config_mgr_check_engine_is_valid(g_config_info->engine_id)) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to get default engine");
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_ENGINE_NOT_FOUND;
}
char* tmp_language;
if (0 != __vc_config_mgr_select_lang(g_config_info->engine_id, &tmp_language)) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to select language");
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
if (0 != vc_parser_set_language(tmp_language)) {
free(tmp_language);
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save config");
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
temp_client = (vc_config_client_s*)calloc(1, sizeof(vc_config_client_s));
if (NULL == temp_client) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to allocate memory");
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_ERROR_OUT_OF_MEMORY;
}
__vc_config_mgr_print_client_info();
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
+ SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
return 0;
}
GSList *iter = NULL;
vc_config_client_s* temp_client = NULL;
+ SLOG(LOG_INFO, vc_config_tag(), "[WARNING] Enter critical section");
+ pthread_mutex_lock(&vc_config_mgr_mutex);
+
if (0 < g_slist_length(g_config_client_list)) {
/* Check uid */
iter = g_slist_nth(g_config_client_list, 0);
if (0 < g_slist_length(g_config_client_list)) {
SLOG(LOG_DEBUG, vc_config_tag(), "Client count (%d)", g_slist_length(g_config_client_list));
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
+
+ if (0 != pthread_mutex_destroy(&vc_config_mgr_mutex)) {
+ SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to destroy vc_config_mgr_mutex.");
+ }
+
return 0;
}
vc_parser_unload_config(g_config_info);
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
+ SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
+
+ if (0 != pthread_mutex_destroy(&vc_config_mgr_mutex)) {
+ SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to destroy vc_config_mgr_mutex.");
+ }
+
SLOG(LOG_DEBUG, vc_config_tag(), "[Success] Finalize config");
return 0;
/*Get handle data from list*/
lang = iter_lang->data;
- SLOG(LOG_DEBUG, vc_config_tag(), " %s", lang);
+ SLOG(LOG_INFO, vc_config_tag(), "lang(%s)", lang);
if (NULL != lang) {
if (false == callback(lang, user_data))
break;