Added mutex lock for widget 36/205636/1 accepted/tizen/unified/20190509.041009 submit/tizen/20190508.063421
authorsungrae jo <seongrae.jo@samsung.com>
Wed, 8 May 2019 06:17:59 +0000 (15:17 +0900)
committersungrae jo <seongrae.jo@samsung.com>
Wed, 8 May 2019 06:17:59 +0000 (15:17 +0900)
Change-Id: I5dc841cc223c5ff3c20b7d153316f856bd30bf52
Signed-off-by: sungrae jo <seongrae.jo@samsung.com>
client/vc_widget.c
client/vc_widget_dbus.c

index c3e634c7b6560424d13bb59612270787af9f2f36..fafdda2d2b00cdca5faa956fd5908d26a533224c 100644 (file)
@@ -39,6 +39,8 @@ static Ecore_Timer* g_w_start_timer = NULL;
 static Ecore_Timer* g_w_notify_state_timer = NULL;
 static Ecore_Timer* g_w_notify_result_timer = NULL;
 
+static pthread_mutex_t g_w_init_mutex = PTHREAD_MUTEX_INITIALIZER;
+
 static Ecore_Thread* g_w_prepare_thread = NULL;
 static int g_w_prepare_canceled = 0;
 
@@ -171,8 +173,10 @@ int vc_widget_initialize(vc_h* vc_w)
                }
        }
 
+       pthread_mutex_lock(&g_w_init_mutex);
        if (0 != vc_widget_client_create(vc_w)) {
                SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to create client!!!!!");
+               pthread_mutex_unlock(&g_w_init_mutex);
                return VC_ERROR_OUT_OF_MEMORY;
        }
 
@@ -182,6 +186,7 @@ int vc_widget_initialize(vc_h* vc_w)
                SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to init config manager : %s",
                         __vc_widget_get_error_code(__vc_widget_convert_config_error_code(ret)));
                vc_widget_client_destroy((*vc_w));
+               pthread_mutex_unlock(&g_w_init_mutex);
                return __vc_widget_convert_config_error_code(ret);
        }
 
@@ -190,6 +195,7 @@ int vc_widget_initialize(vc_h* vc_w)
                SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set config changed : %d", ret);
                vc_config_mgr_finalize((*vc_w)->handle);
                vc_widget_client_destroy((*vc_w));
+               pthread_mutex_unlock(&g_w_init_mutex);
                return __vc_widget_convert_config_error_code(ret);
        }
 
@@ -199,6 +205,7 @@ int vc_widget_initialize(vc_h* vc_w)
                        SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize DB : %d", ret);
                        vc_config_mgr_finalize((*vc_w)->handle);
                        vc_widget_client_destroy((*vc_w));
+                       pthread_mutex_unlock(&g_w_init_mutex);
                        return ret;
                }
        }
@@ -207,6 +214,7 @@ int vc_widget_initialize(vc_h* vc_w)
 
        SLOG(LOG_DEBUG, TAG_VCW, "@@@");
 
+       pthread_mutex_unlock(&g_w_init_mutex);
        return VC_ERROR_NONE;
 }
 
@@ -253,9 +261,11 @@ int vc_widget_deinitialize(vc_h vc_w)
                return VC_ERROR_NONE;
        }
 
+       pthread_mutex_lock(&g_w_init_mutex);
        if (false == vc_widget_client_is_valid(vc_w)) {
                SLOG(LOG_ERROR, TAG_VCW, "[ERROR] NOT initialized");
                SLOG(LOG_DEBUG, TAG_VCW, "@@@");
+               pthread_mutex_unlock(&g_w_init_mutex);
                return VC_ERROR_INVALID_STATE;
        }
 
@@ -307,6 +317,7 @@ int vc_widget_deinitialize(vc_h vc_w)
 
        SLOG(LOG_DEBUG, TAG_VCW, "@@@");
 
+       pthread_mutex_unlock(&g_w_init_mutex);
        return VC_ERROR_NONE;
 }
 
@@ -591,6 +602,8 @@ int vc_widget_unprepare(vc_h vc_w)
                ecore_thread_cancel(g_w_prepare_thread);
        }
 
+       SLOG(LOG_WARN, TAG_VCW, "[Widget] thread info %d %d %d", curr_thread_count, prev_thread_count - curr_thread_count, !ecore_thread_check(g_w_prepare_thread));
+       SLOG(LOG_WARN, TAG_VCW, "[Widget] thread count %d", count);
        while (0 < curr_thread_count && 1 != prev_thread_count - curr_thread_count && !ecore_thread_check(g_w_prepare_thread)) {
                usleep(50000);
 
index 6660c429248902a3ac277af5595e41b9b744591a..bd25de1c6264849b444b2fa1eb297804fd44f7a0 100644 (file)
@@ -23,6 +23,7 @@
 
 
 static pthread_mutex_t g_w_dbus_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t g_w_init_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static int g_w_waiting_time = 3000;
 static bool g_is_connection_opened = false;
@@ -527,7 +528,9 @@ int vc_widget_dbus_request_hello()
 
 int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_pid)
 {
+       pthread_mutex_lock(&g_w_init_mutex);
        if (0 != __dbus_check()) {
+               pthread_mutex_unlock(&g_w_init_mutex);
                return VC_ERROR_OPERATION_FAILED;
        }
 
@@ -541,6 +544,7 @@ int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_p
 
        if (NULL == msg) {
                SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget initialize : Fail to make message ");
+               pthread_mutex_unlock(&g_w_init_mutex);
                return VC_ERROR_OPERATION_FAILED;
        } else {
                SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget initialize : pid(%d)", pid);
@@ -591,9 +595,11 @@ int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_p
                        if (NULL == g_w_conn_listener) {
                                if (g_is_connection_opened) {
                                        SLOG(LOG_ERROR, TAG_VCW, "[ERROR] g_w_conn_listener is NULL abnormally");
+                                       pthread_mutex_unlock(&g_w_init_mutex);
                                        return VC_ERROR_OPERATION_FAILED;
                                } else {
                                        SLOG(LOG_INFO, TAG_VCW, "[INFO] g_w_conn_listener is NULL and DBUS connection was closed");
+                                       pthread_mutex_unlock(&g_w_init_mutex);
                                        return VC_ERROR_NONE;
                                }
                        }
@@ -602,6 +608,7 @@ int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_p
                        if (dbus_error_is_set(&err)) {
                                SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message);
                                dbus_error_free(&err);
+                               pthread_mutex_unlock(&g_w_init_mutex);
                                return VC_ERROR_OPERATION_FAILED;
                        }
 
@@ -615,12 +622,15 @@ int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_p
                result = VC_ERROR_TIMED_OUT;
        }
 
+       pthread_mutex_unlock(&g_w_init_mutex);
        return result;
 }
 
 int vc_widget_dbus_request_finalize(int pid)
 {
+       pthread_mutex_lock(&g_w_init_mutex);
        if (0 != __dbus_check()) {
+               pthread_mutex_unlock(&g_w_init_mutex);
                return VC_ERROR_OPERATION_FAILED;
        }
 
@@ -636,6 +646,7 @@ int vc_widget_dbus_request_finalize(int pid)
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message);
                dbus_error_free(&err);
+               pthread_mutex_unlock(&g_w_init_mutex);
                return VC_ERROR_OPERATION_FAILED;
        }
 
@@ -649,6 +660,7 @@ int vc_widget_dbus_request_finalize(int pid)
 
        if (NULL == msg) {
                SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget finalize : Fail to make message ");
+               pthread_mutex_unlock(&g_w_init_mutex);
                return VC_ERROR_OPERATION_FAILED;
        } else {
                SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget finalize : pid(%d)", pid);
@@ -691,6 +703,7 @@ int vc_widget_dbus_request_finalize(int pid)
                result = VC_ERROR_TIMED_OUT;
        }
 
+       pthread_mutex_unlock(&g_w_init_mutex);
        return result;
 }