Add a checker whether pkgmgr_thread is done or not 23/246823/1
authorsooyeon.kim <sooyeon.kim@samsung.com>
Wed, 4 Nov 2020 08:40:26 +0000 (17:40 +0900)
committersooyeon.kim <sooyeon.kim@samsung.com>
Wed, 4 Nov 2020 08:40:26 +0000 (17:40 +0900)
Change-Id: I78b3c3cbcf6af9b50e2514a1b62837695376bc17
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
client/tts.c

index 0828368251092dac4b840647427eb3008f1517ec..3f6a1be29fac8d2c6224509cb0f734d26a548450 100644 (file)
@@ -59,6 +59,7 @@ static char g_engine_appid[256];
 static int g_engine_update_status = 0;
 static pthread_mutex_t g_pkgmgr_mutex = PTHREAD_MUTEX_INITIALIZER;
 static Ecore_Thread* g_pkgmgr_thread = NULL;
+static volatile bool g_is_finished_pkgmgr_thread = false;
 static bool __is_engine_launched(const char* appid);
 
 /* Function definition */
@@ -319,11 +320,14 @@ static void __create_pkgmgr_thread(void* data, Ecore_Thread* thread)
 {
        SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] create pkgmgr thread");
 
+       g_is_finished_pkgmgr_thread = false;
+
        tts_h tts = (tts_h)data;
        tts_client_s* client = tts_client_get(tts);
        /* check handle */
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] client is null");
+               g_is_finished_pkgmgr_thread = true;
                return ;
        }
 
@@ -369,6 +373,9 @@ static void __create_pkgmgr_thread(void* data, Ecore_Thread* thread)
        }
 
        pthread_mutex_unlock(&g_pkgmgr_mutex);
+       g_is_finished_pkgmgr_thread = true;
+       SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Finish pkgmgr_thread. func_end will be invoked in main thread.");
+
        return ;
 }
 
@@ -631,8 +638,8 @@ int tts_destroy(tts_h tts)
                __tts_unset_all_callbacks(tts);
 
                /* Cancel and Check threads */
-               if (NULL != g_pkgmgr_thread && false == ecore_thread_check(g_pkgmgr_thread)) {
-                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Cancel pkgmgr thread");
+               if (NULL != g_pkgmgr_thread && false == ecore_thread_check(g_pkgmgr_thread) && false == g_is_finished_pkgmgr_thread) {
+                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] pkgmgr thread is not finished. Cancel pkgmgr thread");
                        ecore_thread_cancel(g_pkgmgr_thread);
                }
                if (NULL != client->thread && false == ecore_thread_check(client->thread)) {