Remove unused mutex vc_config_mgr_mutex 06/286206/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 7 Dec 2022 04:38:48 +0000 (13:38 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Fri, 30 Dec 2022 04:38:03 +0000 (13:38 +0900)
- Requirement:
vc_config_mgr_mutex is not valuable to assure thread safety.

- Content:
Through previous patches, all important global variable has their own
mutex for thread safety. Thus, vc_config_mgr_mutex is not needed
anymore. Therefore, this patch removes vc_config_mgr_mutex from the
module.

Change-Id: Icaac3b07f5f8a378f4c5f236746fe31d5be27175
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
common/vc_config_mgr.cpp

index 0544548..ba2bb00 100644 (file)
@@ -74,8 +74,6 @@ static int g_wd_lang = -1;
 static GList* g_ino_list = nullptr;
 static mutex g_ino_list_mutex;
 
-static pthread_mutex_t vc_config_mgr_mutex = PTHREAD_MUTEX_INITIALIZER;
-
 static int __vc_config_mgr_register_engine_config_updated_event(const char* path);
 static int __vc_config_mgr_unregister_engine_config_updated_event();
 static int __vc_config_mgr_set_default_language(const char* language);
@@ -360,7 +358,6 @@ static Eina_Bool __vc_config_mgr_engine_config_inotify_event_callback(void* data
 {
        SLOG(LOG_DEBUG, vc_config_tag(), "@@@ Engine config updated callback event");
        ecore_thread_main_loop_begin();
-       pthread_mutex_lock(&vc_config_mgr_mutex);
 
        vc_engine_inotify_s *ino = (vc_engine_inotify_s *)data;
        int dir_fd = ino->dir_fd;
@@ -373,7 +370,6 @@ static Eina_Bool __vc_config_mgr_engine_config_inotify_event_callback(void* data
        if (0 > length) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Empty Inotify event");
                SLOG(LOG_DEBUG, vc_config_tag(), "@@@");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                ecore_thread_main_loop_end();
                return ECORE_CALLBACK_DONE;
        }
@@ -414,7 +410,6 @@ static Eina_Bool __vc_config_mgr_engine_config_inotify_event_callback(void* data
 
        SLOG(LOG_DEBUG, vc_config_tag(), "@@@");
 
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        ecore_thread_main_loop_end();
        return ECORE_CALLBACK_PASS_ON;
 }
@@ -645,14 +640,10 @@ int __vc_config_set_auto_language()
 
 void __vc_config_language_changed_cb(keynode_t *key, void *data)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
        if (g_VoiceControlConfig->isAutoLanguageEnabled()) {
                /* Get voice input vconf key */
                __vc_config_set_auto_language();
        }
-
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
-       return;
 }
 
 static int __initialize_vc_config_mgr()
@@ -767,12 +758,10 @@ int vc_config_mgr_initialize(unsigned int uid)
 {
        SLOG(LOG_INFO, vc_config_tag(), "[WARNING] Enter critical section");
        ecore_thread_main_loop_begin();
-       pthread_mutex_lock(&vc_config_mgr_mutex);
 
        int ret = __initialize_vc_config_mgr();
        if (VC_CONFIG_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to initialize vc_config_mgr");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                ecore_thread_main_loop_end();
                SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
                return ret;
@@ -785,7 +774,6 @@ int vc_config_mgr_initialize(unsigned int uid)
        /* Check uid */
        if (g_VoiceControlClients->isUidValid(uid)) {
                SLOG(LOG_WARN, vc_config_tag(), "[CONFIG] uid(%u) has already registered", uid);
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                ecore_thread_main_loop_end();
                SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
                return VC_CONFIG_ERROR_NONE;
@@ -798,7 +786,6 @@ int vc_config_mgr_initialize(unsigned int uid)
 
        g_VoiceControlClients->printOutClients();
 
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        ecore_thread_main_loop_end();
        SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
        return VC_ERROR_NONE;
@@ -808,12 +795,8 @@ int vc_config_mgr_finalize(unsigned int uid)
 {
        SLOG(LOG_INFO, vc_config_tag(), "[WARNING] Enter critical section");
 
-       pthread_mutex_lock(&vc_config_mgr_mutex);
-
        if (0 < g_VoiceControlClients->removeClient(uid)) {
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
-
                return VC_ERROR_NONE;
        }
 
@@ -827,7 +810,6 @@ int vc_config_mgr_finalize(unsigned int uid)
        vconf_ignore_key_changed(VCONFKEY_LANGSET, __vc_config_language_changed_cb);
        __finalize_config_info();
 
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
 
        g_config_mgr_initialized = false;
@@ -1000,32 +982,23 @@ int vc_config_mgr_unset_enabled_cb(unsigned int uid)
 
 int vc_config_mgr_get_auto_language(bool* value)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
-
        if (g_config_mgr_initialized.load() == false) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
        if (NULL == value) {
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
        *value = g_VoiceControlConfig->isAutoLanguageEnabled();
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
-
        return VC_ERROR_NONE;
 }
 
 int vc_config_mgr_set_auto_language(bool value)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
-
        if (g_config_mgr_initialized.load() == false) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
@@ -1033,7 +1006,6 @@ int vc_config_mgr_set_auto_language(bool value)
                /* Check language is valid */
                if (0 != vc_parser_set_auto_lang(value)) {
                        SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save engine id");
-                       pthread_mutex_unlock(&vc_config_mgr_mutex);
                        return -1;
                }
                g_VoiceControlConfig->setAutoLanguageEnabled(value);
@@ -1043,29 +1015,23 @@ int vc_config_mgr_set_auto_language(bool value)
                }
        }
 
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        return VC_ERROR_NONE;
 }
 
 int vc_config_mgr_get_engine_list(vc_config_supported_engine_cb callback, void* user_data)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
-
        if (g_config_mgr_initialized.load() == false) {
                SLOG(LOG_ERROR, vc_config_tag(), "Not initialized");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_INVALID_STATE;
        }
 
        if (NULL == callback) {
                SLOG(LOG_ERROR, vc_config_tag(), " callback is NULL");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_INVALID_PARAMETER;
        }
 
        if (g_VoiceControlEngines->isEngineEmpty()) {
                SLOG(LOG_WARN, vc_config_tag(), "[ERROR] Engine list is NULL");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_ENGINE_NOT_FOUND;
        }
 
@@ -1083,35 +1049,29 @@ int vc_config_mgr_get_engine_list(vc_config_supported_engine_cb callback, void*
                }
        }
 
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        return VC_CONFIG_ERROR_NONE;
 }
 
 
 int vc_config_mgr_get_engine(char** engine)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
        if (g_config_mgr_initialized.load() == false) {
                SLOG(LOG_ERROR, vc_config_tag(), "Not initialized"); //LCOV_EXCL_LINE
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_INVALID_STATE;
        }
 
        if (NULL == engine) {
                SLOG(LOG_ERROR, vc_config_tag(), "Parameter is NULL");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_INVALID_PARAMETER;
        }
 
        string default_engine_id = g_VoiceControlConfig->getEngineId();
        if (default_engine_id.empty()) {
                SLOG(LOG_ERROR, vc_config_tag(), " Engine id is NULL"); //LCOV_EXCL_LINE
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_ENGINE_NOT_FOUND;
        }
        *engine = strdup(default_engine_id.c_str());
 
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        return VC_CONFIG_ERROR_NONE;
 }
 
@@ -1173,22 +1133,18 @@ int __vc_config_set_buxtonkey(const char* engine)
 
 int vc_config_mgr_set_engine(const char* engine)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
        if (g_config_mgr_initialized.load() == false) {
                SLOG(LOG_ERROR, vc_config_tag(), "Not initialized");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_INVALID_STATE;
        }
 
        if (NULL == engine) {
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_INVALID_PARAMETER;
        }
 
        /* Check current engine id with new engine id */
        string default_engine_id = g_VoiceControlConfig->getEngineId();
        if (0 == default_engine_id.compare(engine)) {
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_NONE;
        }
 
@@ -1197,20 +1153,17 @@ int vc_config_mgr_set_engine(const char* engine)
        int ret = __vc_config_set_buxtonkey(engine);
        if (0 != ret) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] set buxtonkey Failed!!!");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return ret;
        }
 
        shared_ptr<VoiceControlEngineInfo> engineInfo = g_VoiceControlEngines->getEngineInfo(engine);
        if (nullptr == engineInfo) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] There is no engine with id (%s)!!", engine);
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_INVALID_PARAMETER;
        }
 
        if (0 != vc_parser_set_engine(engine)) {
                SLOG(LOG_ERROR, vc_config_tag(), " Fail to save config");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_OPERATION_FAILED;
        }
        g_VoiceControlConfig->setEngineId(engine);
@@ -1224,7 +1177,6 @@ int vc_config_mgr_set_engine(const char* engine)
                auto languages = engineInfo->getSupportedLanguages();
                if (languages.empty()) {
                        SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to get default language. Engine id(%s) is not valid", engine);
-                       pthread_mutex_unlock(&vc_config_mgr_mutex);
                        return VC_CONFIG_ERROR_OPERATION_FAILED;
                }
 
@@ -1233,29 +1185,23 @@ int vc_config_mgr_set_engine(const char* engine)
 
        SLOG(LOG_DEBUG, vc_config_tag(), "[Config] Engine changed");
        g_VoiceControlConfig->printOutConfig();
-
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        return VC_CONFIG_ERROR_NONE;
 }
 
 int vc_config_mgr_get_language_list(vc_supported_language_cb callback, void* user_data)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
        if (g_config_mgr_initialized.load() == false) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
        if (nullptr == callback) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Callback is null");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_INVALID_PARAMETER;
        }
 
        if (g_VoiceControlEngines->isEngineEmpty()) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] There is no engine");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
@@ -1263,7 +1209,6 @@ int vc_config_mgr_get_language_list(vc_supported_language_cb callback, void* use
        shared_ptr<VoiceControlEngineInfo> engineInfo = g_VoiceControlEngines->getEngineInfo(default_engine_id);
        if (nullptr == engineInfo) {
                SLOG(LOG_ERROR, vc_config_tag(), "Fail to find engine information : %s", default_engine_id.c_str());
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_NONE;
        }
 
@@ -1282,33 +1227,27 @@ int vc_config_mgr_get_language_list(vc_supported_language_cb callback, void* use
                }
        }
 
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        return VC_ERROR_NONE;
 }
 
 int vc_config_mgr_get_default_language(char** language)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
        if (g_config_mgr_initialized.load() == false) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
        if (NULL == language) {
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
        string default_language = g_VoiceControlConfig->getCurrentLanguage();
        if (default_language.empty()) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] language is NULL");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
        *language = strdup(default_language.c_str());
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        return VC_ERROR_NONE;
 }
 
@@ -1341,66 +1280,51 @@ static int __vc_config_mgr_set_default_language(const char* language)
 
 int vc_config_mgr_set_default_language(const char* language)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
        int ret = __vc_config_mgr_set_default_language(language);
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
-
        return ret;
 }
 
 int vc_config_mgr_get_enabled(bool* value)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
        if (g_config_mgr_initialized.load() == false) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
        if (NULL == value) {
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
        *value = g_VoiceControlConfig->isEnabled();
-
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        return VC_ERROR_NONE;
 }
 
 int vc_config_mgr_set_enabled(bool value)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
        if (g_config_mgr_initialized.load() == false) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
        if (0 != vc_parser_set_enabled(value)) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to set enabled");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
        g_VoiceControlConfig->setEnabled(value);
 
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        return VC_ERROR_NONE;
 }
 
 int vc_config_mgr_get_nonfixed_support(bool* value)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
        if (g_config_mgr_initialized.load() == false) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
        if (NULL == value) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Input parameter is NULL");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
@@ -1408,32 +1332,25 @@ int vc_config_mgr_get_nonfixed_support(bool* value)
        shared_ptr<VoiceControlEngineInfo> engineInfo = g_VoiceControlEngines->getEngineInfo(default_engine_id);
        if (nullptr == engineInfo) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] There is no engine with id (%s)!!", default_engine_id.c_str());
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return VC_CONFIG_ERROR_ENGINE_NOT_FOUND;
        };
 
        *value = engineInfo->isNonFixedSupported();
-
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        return VC_ERROR_NONE;
 }
 
 bool vc_config_check_default_engine_is_valid(const char* engine)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
        if (g_config_mgr_initialized.load() == false) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
        if (NULL == engine) {
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return false;
        }
 
        bool is_valid = g_VoiceControlEngines->isEngineIdValid(engine);
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        return is_valid;
 }
 
@@ -1463,26 +1380,20 @@ bool vc_config_check_default_language_is_valid(const char* language)
 
 int vc_config_mgr_set_foreground(int pid, bool value)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
        if (g_config_mgr_initialized.load() == false) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        return vc_parser_set_foreground(pid, value);
 }
 
 int vc_config_mgr_get_foreground(int* pid)
 {
-       pthread_mutex_lock(&vc_config_mgr_mutex);
        if (g_config_mgr_initialized.load() == false) {
                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
-               pthread_mutex_unlock(&vc_config_mgr_mutex);
                return -1;
        }
 
-       pthread_mutex_unlock(&vc_config_mgr_mutex);
        return vc_parser_get_foreground(pid);
 }