Fixed thread unsafe bug when deinitialize as soon as initialize 35/179735/1 accepted/tizen/unified/20180522.052833 submit/tizen/20180521.130752
authorsungrae jo <seongrae.jo@samsung.com>
Mon, 21 May 2018 12:48:18 +0000 (21:48 +0900)
committersungrae jo <seongrae.jo@samsung.com>
Mon, 21 May 2018 12:48:18 +0000 (21:48 +0900)
Change-Id: Ia8a615696212f69472e915c4489dd8a86331db70
Signed-off-by: sungrae jo <seongrae.jo@samsung.com>
client/vc_widget.c

index 6e5ea939ac5905e99361b31117e48778f40be5da..ea0d2cf2fd69043893401eef693ede8e27fbb4fa 100644 (file)
@@ -262,6 +262,21 @@ int vc_widget_deinitialize(vc_h vc_w)
                return VC_ERROR_INVALID_STATE;
        }
 
+
+       int thread_count = ecore_thread_active_get();
+       int count = 0;
+       while (0 < thread_count) {
+               usleep(50000);
+               count++;
+               if (100 == count) {
+                       SLOG(LOG_WARN, TAG_VCW, "[WARNING!!] Thread is blocked, cnt(%d), thread count(%d)", count, thread_count);
+                       break;
+               } else if (0 == count % 5) {
+                       SLOG(LOG_WARN, TAG_VCW, "[WARNING!!] Thread is alive, cnt(%d), thread count(%d)", count, thread_count);
+               }
+               thread_count = ecore_thread_active_get();
+       }
+
        vc_state_e state;
        vc_widget_client_get_state(vc_w, &state);
        vc_widget_s* widget = widget_get(vc_w);
@@ -338,7 +353,7 @@ static Eina_Bool __focus_changed_cb(void *data, int type, void *event)
        return ECORE_CALLBACK_RENEW;
 }
 
-static Eina_Bool __vc_widget_connect_daemon(void *data)
+static void __vc_widget_connect_daemon(void *data)
 {
        vc_h vc_w = (vc_h)data;
 
@@ -359,7 +374,7 @@ static Eina_Bool __vc_widget_connect_daemon(void *data)
                ecore_main_loop_thread_safe_call_async(__vc_widget_notify_error, vc_w);
 
                SLOG(LOG_DEBUG, TAG_VCW, "@@@");
-               return EINA_FALSE;
+               return;
 
        } else if (VC_ERROR_INVALID_PARAMETER == ret) {
                SLOG(LOG_WARN, TAG_VCW, "[WARNING] Invalid Parameter");
@@ -370,19 +385,17 @@ static Eina_Bool __vc_widget_connect_daemon(void *data)
                ecore_main_loop_thread_safe_call_async(__vc_widget_notify_error, vc_w);
 
                SLOG(LOG_DEBUG, TAG_VCW, "@@@");
-               return EINA_TRUE;
+               return;
        }
 
        vc_widget_client_set_service_state(vc_w, (vc_service_state_e)service_state);
 
        SLOG(LOG_INFO, TAG_VCW, "@@@ [Widget] Connect daemon");
 
-       ecore_thread_main_loop_begin();
        if (NULL == g_focus_in_handler)
                g_focus_in_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, __focus_changed_cb, NULL);
        if (NULL == g_focus_out_handler)
                g_focus_out_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, __focus_changed_cb, NULL);
-       ecore_thread_main_loop_end();
 
        char appid[1024] = {'\0',};
        aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
@@ -419,7 +432,7 @@ static Eina_Bool __vc_widget_connect_daemon(void *data)
 
        SLOG(LOG_DEBUG, TAG_VCW, "@@@");
 
-       return EINA_FALSE;
+       return;
 }
 
 static void __start_prepare_thread(void *data, Ecore_Thread *thread)
@@ -444,6 +457,7 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread)
                }
        }
 
+#if 0
        ret = -1;
        retry_count = 0;
        while (0 != ret) {
@@ -457,6 +471,9 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread)
                else
                        retry_count++;
        }
+#endif
+
+       ecore_main_loop_thread_safe_call_async(__vc_widget_connect_daemon, vc_w);
 
        return;
 }