From: Suyeon Hwang Date: Tue, 16 Feb 2021 04:56:54 +0000 (+0900) Subject: Remove client data dependency from reprepare thread X-Git-Tag: submit/tizen/20210223.104651~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cf28e854300d2ca98cc01bf55f89a60c1e81aabc;p=platform%2Fcore%2Fuifw%2Ftts.git Remove client data dependency from reprepare thread Change-Id: I5f65fd56ef3ec89b6f7343b681a0e7dbc08d8150 Signed-off-by: Suyeon Hwang --- diff --git a/client/tts.c b/client/tts.c index f556cec7..d9bd7fcb 100644 --- a/client/tts.c +++ b/client/tts.c @@ -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; diff --git a/client/tts_client.c b/client/tts_client.c index 4e76b7c2..050d6ed0 100644 --- a/client/tts_client.c +++ b/client/tts_client.c @@ -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; diff --git a/client/tts_client.h b/client/tts_client.h index 1a6822a5..5e2fd5ea 100644 --- a/client/tts_client.h +++ b/client/tts_client.h @@ -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; diff --git a/client/tts_core.c b/client/tts_core.c index 2de6ca85..575e4b7f 100644 --- a/client/tts_core.c +++ b/client/tts_core.c @@ -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; } diff --git a/client/tts_core.h b/client/tts_core.h index e3f75f71..5bbdf308 100644 --- a/client/tts_core.h +++ b/client/tts_core.h @@ -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); diff --git a/client/tts_dbus.c b/client/tts_dbus.c index f068c9d3..2c89c860 100644 --- a/client/tts_dbus.c +++ b/client/tts_dbus.c @@ -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;