Remove client data dependency from reprepare thread 28/253628/4
authorSuyeon Hwang <stom.hwang@samsung.com>
Tue, 16 Feb 2021 04:56:54 +0000 (13:56 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 18 Feb 2021 02:13:55 +0000 (11:13 +0900)
Change-Id: I5f65fd56ef3ec89b6f7343b681a0e7dbc08d8150
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts.c
client/tts_client.c
client/tts_client.h
client/tts_core.c
client/tts_core.h
client/tts_dbus.c

index f556cec7589bde7cceea6246011d66275d6e63d8..d9bd7fcb12aceea7d96bf80e4b857119f44263fe 100644 (file)
@@ -408,12 +408,6 @@ int tts_destroy(tts_h tts)
                /* Unset registered callbacks */
                __tts_unset_all_callbacks(tts);
 
-               /* Cancel and Check threads */
-               if (NULL != client->thread && false == ecore_thread_check(client->thread)) {
-                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Cancel client thread");
-                       ecore_thread_cancel(client->thread);
-               }
-
                int thread_count = ecore_thread_active_get();
                SLOG(LOG_INFO, TAG_TTSC, "[INFO] Active thread count: %d", thread_count);
                int cnt = 0;
index 4e76b7c2db5ebff19bbc50d2929d974915664f54..050d6ed0ee86a7a6418552fb142d9c6744c6dcaa 100644 (file)
@@ -99,8 +99,6 @@ int tts_client_new(tts_h* tts)
 
        client->text_repeat = NULL;
 
-       client->thread = NULL;
-
        client->notify_error_timer = NULL;
        client->notify_state_timer = NULL;
 
index 1a6822a56a934e6a697ec8d0a5496faea079debb..5e2fd5ea4e0f0e44f86c51c5e2fe181a22790a9a 100644 (file)
@@ -73,9 +73,6 @@ typedef struct {
        /* repetition */
        char*           text_repeat;
 
-       /* thread */
-       Ecore_Thread* thread;
-
        /* timer */
        Ecore_Timer* notify_error_timer;
        Ecore_Timer* notify_state_timer;
index 2de6ca85104f0a8e6b404ddd8fe10274295e3655..575e4b7fb7bfa3d520e4229e0ecb8b0ba3bbbc2f 100644 (file)
@@ -28,6 +28,8 @@ static volatile bool g_is_thread_canceled = false;
 static char* g_engine_name = NULL;
 static int g_engine_update_status = 0;
 
+static Ecore_Thread* g_reprepare_thread = NULL;
+
 static char* g_pkgmgr_status = NULL;
 static pkgmgr_client* g_pkgmgr = NULL;
 static Ecore_Thread* g_pkgmgr_thread = NULL;
@@ -325,27 +327,15 @@ static void __start_reprepare_thread(void* data, Ecore_Thread* thread)
 {
        SLOG(LOG_INFO, TAG_TTSC, "[DEBUG] start reprepare thread. engine update status(%d)", g_engine_update_status);
 
-       tts_client_s* client = (tts_client_s*)data;
-       /* check handle */
-       if (NULL == client || false == tts_client_is_valid(client->tts)) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
-               return;
-       }
-
        int cnt = 0;
        while (!g_engine_update_status && cnt < 20) {
                SLOG(LOG_WARN, TAG_TTSC, "[WARNING] wait for starting update");
-               /* Checking handle which can be destroyed on other thread */
-               if (false == tts_client_is_valid(client->tts)) {
-                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] client is already destroyed");
-                       return;
-               }
 
                usleep(50000);
                cnt++;
 
                /* Checking thread is canceled or not */
-               if (ecore_thread_check(client->thread)) {
+               if (ecore_thread_check(thread)) {
                        SLOG(LOG_WARN, TAG_TTSC, "[WARNING] client thread is canceled. Exit");
                        return;
                }
@@ -354,16 +344,10 @@ static void __start_reprepare_thread(void* data, Ecore_Thread* thread)
        SLOG(LOG_INFO, TAG_TTSC, "[DEBUG] update status(%d)", g_engine_update_status);
 
        while (g_engine_update_status && (NULL != g_pkgmgr)) {
-               /* Checking handle which can be destroyed on other thread */
-               if (false == tts_client_is_valid(client->tts)) {
-                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] client is already destroyed");
-                       return;
-               }
-
                usleep(200000);
 
                /* Checking thread is canceled or not */
-               if (ecore_thread_check(client->thread)) {
+               if (ecore_thread_check(thread)) {
                        SLOG(LOG_WARN, TAG_TTSC, "[WARNING] client thread is canceled. Exit");
                        return;
                }
@@ -371,10 +355,6 @@ static void __start_reprepare_thread(void* data, Ecore_Thread* thread)
 
        SLOG(LOG_INFO, TAG_TTSC, "[INFO] finish updating. request to prepare");
 
-       if (0 != tts_core_prepare(client)) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
-       }
-
        return;
 }
 
@@ -382,35 +362,41 @@ static void __end_reprepare_thread(void* data, Ecore_Thread* thread)
 {
        SLOG(LOG_INFO, TAG_TTSC, "[INFO] end reprepare thread");
 
-       tts_client_s* client = (tts_client_s*)data;
-       /* check handle */
-       if (NULL == client || false == tts_client_is_valid(client->tts)) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
+       GList* clients = tts_client_get_client_list();
+       if (NULL == clients) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client list");
                return;
        }
 
-       client->thread = NULL;
+       GList *iter = NULL;
+       if (g_list_length(clients) > 0) {
+               iter = g_list_first(clients);
+
+               while (NULL != iter) {
+                       tts_client_s* client = iter->data;
+                       if (NULL != client && tts_client_is_valid(client->tts)) {
+                               tts_core_prepare(client);
+                       }
+
+                       iter = g_list_next(iter);
+               }
+       }
+
+       g_list_free(clients);
+       g_reprepare_thread = NULL;
 }
 
 static void __cancel_reprepare_thread(void* data, Ecore_Thread* thread)
 {
        SLOG(LOG_INFO, TAG_TTSC, "[INFO] cancel reprepare thread");
-
-       tts_client_s* client = (tts_client_s*)data;
-       /* check handle */
-       if (NULL == client || false == tts_client_is_valid(client->tts)) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
-               return;
-       }
-
-       client->thread = NULL;
+       g_reprepare_thread = NULL;
 }
 
-static inline void __run_client_reprepare_thread(tts_client_s* client)
+static inline void __run_client_reprepare_thread()
 {
-       if (NULL == client->thread) {
+       if (NULL == g_reprepare_thread) {
                SLOG(LOG_INFO, TAG_TTSC, "[INFO] ecore thread run: start_reprepare_thread");
-               client->thread = ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, __cancel_reprepare_thread, client);
+               g_reprepare_thread = ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, __cancel_reprepare_thread, NULL);
        } else {
                SLOG(LOG_INFO, TAG_TTSC, "[INFO] Reprepare thread is already running");
        }
@@ -439,7 +425,7 @@ static int __send_hello_msg(tts_client_s* client)
                if (g_engine_update_status) {
                        /* suyeon wait engine update */
                        SLOG(LOG_INFO, TAG_TTSC, "[INFO] cannot prepare due to engine update");
-                       __run_client_reprepare_thread(client);
+                       __run_client_reprepare_thread();
                        return TTS_ERROR_INVALID_STATE;
                }
        }
@@ -529,7 +515,7 @@ static Eina_Bool __prepare_sync_cb(tts_client_s* client)
                /* check whether engine is updating or not */
                if (g_engine_update_status) {
                        SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] cannot prepare due to engine update");
-                       __run_client_reprepare_thread(client);
+                       __run_client_reprepare_thread();
                        return EINA_FALSE;
                }
        }
@@ -606,6 +592,11 @@ int tts_core_initialize()
 
 int tts_core_deinitialize()
 {
+       if (NULL != g_reprepare_thread && EINA_FALSE == ecore_thread_check(g_reprepare_thread)) {
+               SLOG(LOG_INFO, TAG_TTSC, "[INFO] Cancel reprepare thread");
+               ecore_thread_cancel(g_reprepare_thread);
+       }
+
        if (NULL != g_pkgmgr_thread) {
                SLOG(LOG_INFO, TAG_TTSC, "[INFO] Cancel pkgmgr thread");
                g_is_thread_canceled = true;
@@ -988,17 +979,32 @@ int tts_core_unprepare(tts_client_s* client, bool is_screen_reader_on)
        return TTS_ERROR_NONE;
 }
 
-int tts_core_reprepare(tts_client_s* client)
+int tts_core_reprepare()
 {
        /* check handle */
-       if (NULL == client || false == tts_client_is_valid(client->tts)) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
-               return TTS_ERROR_INVALID_PARAMETER;
+       GList* clients = tts_client_get_client_list();
+       if (NULL == clients) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client list");
+               return TTS_ERROR_OPERATION_FAILED;
        }
 
-       client->current_state = TTS_STATE_CREATED;
-       client->reason = 0;
-       __run_client_reprepare_thread(client);
+       GList *iter = NULL;
+       if (g_list_length(clients) > 0) {
+               iter = g_list_first(clients);
+
+               while (NULL != iter) {
+                       tts_client_s* client = iter->data;
+                       if (NULL != client && tts_client_is_valid(client->tts)) {
+                               client->current_state = TTS_STATE_CREATED;
+                               client->reason = TTS_ERROR_NONE;
+                       }
+
+                       iter = g_list_next(iter);
+               }
+       }
+
+       g_list_free(clients);
+       __run_client_reprepare_thread();
 
        return TTS_ERROR_NONE;
 }
index e3f75f71eef8f7ff4be7ad4d3ca685d260d54de8..5bbdf3085f4af2882a0e4e3ade9e55634419ee4b 100644 (file)
@@ -40,7 +40,7 @@ const char* tts_core_get_engine_name();
 int tts_core_prepare(tts_client_s* client);
 int tts_core_prepare_sync(tts_client_s* client);
 int tts_core_unprepare(tts_client_s* client, bool is_screen_reader_on);
-int tts_core_reprepare(tts_client_s* client);
+int tts_core_reprepare();
 
 // called by tts_dbus.c
 int tts_core_receive_hello(int uid, int ret, int credential_needed);
index f068c9d390550d1145db52f0e473a41b966cb631..2c89c860643d4919192ba6a305609428bf539c56 100644 (file)
@@ -64,24 +64,19 @@ static int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg
                                /* call callback function */
                                tts_core_notify_error_async(data, utt_id, reason);
 
-                               if (TTS_ERROR_SERVICE_RESET == reason) {
-                                       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
-
-                                       tts_client_s* client = tts_client_get(data->tts);
-                                       if (NULL == client) {
-                                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
-                                               return TTS_ERROR_INVALID_PARAMETER;
-                                       }
-
-                                       tts_core_reprepare(data);
-                               }
-
                                /* Next item */
                                iter = g_list_next(iter);
                        }
                }
 
                g_list_free(client_list);
+
+               if (TTS_ERROR_SERVICE_RESET == reason) {
+                       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
+
+                       tts_core_reprepare();
+               }
+
        } else {
                tts_client_s* client = tts_client_get_by_uid(uid);
 
@@ -98,12 +93,6 @@ static int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg
                        client->err_msg = strdup(err_msg);
 
                tts_core_notify_error_async(client, utt_id, reason);
-
-               if (TTS_ERROR_SERVICE_RESET == reason) {
-                       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
-
-                       tts_core_reprepare(client);
-               }
        }
 
        return 0;