From 0bd67440c985b2f7fc47d221060aeea646e98ef1 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Fri, 24 Jul 2020 18:42:39 +0900 Subject: [PATCH] Add ecore_thread_cancel to avoid crash Change-Id: I635c27473b4ce8225b9a51f7f2f2fa472497f069 Signed-off-by: sooyeon.kim --- client/tts.c | 42 ++++++++++++++++++++++++++++++++++++------ server/ttsd_dbus_server.c | 4 ++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/client/tts.c b/client/tts.c index 7228ee0..46bca01 100644 --- a/client/tts.c +++ b/client/tts.c @@ -66,6 +66,7 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg); int __tts_recheck_screen_reader(); static void __start_reprepare_thread(void* data, Ecore_Thread* thread); static void __end_reprepare_thread(void* data, Ecore_Thread* thread); +static void __cancel_reprepare_thread(void* data, Ecore_Thread* thread); static const char* tts_tag() { @@ -358,6 +359,12 @@ static void __finish_pkgmgr_thread(void* data, Ecore_Thread* thread) g_pkgmgr_thread = NULL; } +static void __cancel_pkgmgr_thread(void* data, Ecore_Thread* thread) +{ + SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] Cancel pkgmgr thread"); + g_pkgmgr_thread = NULL; +} + static void __pkgmgr_thread(void* data) { SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] call pkgmgr_thread"); @@ -370,7 +377,7 @@ static void __pkgmgr_thread(void* data) if (NULL == g_pkgmgr_thread) { SLOG(LOG_INFO, TAG_TTSC, "[INFO] ecore thread run: create_pkgmgr_thread"); - g_pkgmgr_thread = ecore_thread_run(__create_pkgmgr_thread, __finish_pkgmgr_thread, NULL, tts); + g_pkgmgr_thread = ecore_thread_run(__create_pkgmgr_thread, __finish_pkgmgr_thread, __cancel_pkgmgr_thread, tts); } return ; } @@ -604,7 +611,16 @@ int tts_destroy(tts_h tts) /* Unset registered callbacks */ __tts_unset_all_callbacks(tts); - /* Check threads */ + /* 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"); + ecore_thread_cancel(g_pkgmgr_thread); + } + 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; @@ -917,7 +933,7 @@ static Eina_Bool __tts_connect_daemon(void *data) SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] cannot prepare due to engine update"); if (NULL == client->thread) { SLOG(LOG_INFO, TAG_TTSC, "[INFO] ecore thread run: start_reprepare_thread"); - client->thread = ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, NULL, tts); + client->thread = ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, __cancel_reprepare_thread, tts); } return EINA_FALSE; } @@ -1129,7 +1145,7 @@ static Eina_Bool __send_hello(void *data) SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] cannot prepare due to engine update"); if (NULL == client->thread) { SLOG(LOG_INFO, TAG_TTSC, "[INFO] ecore thread run: start_reprepare_thread"); - client->thread = ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, NULL, tts); + client->thread = ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, __cancel_reprepare_thread, tts); } client->hello_timer = NULL; return EINA_FALSE; @@ -2608,6 +2624,20 @@ static void __end_reprepare_thread(void* data, Ecore_Thread* thread) client->thread = NULL; } +static void __cancel_reprepare_thread(void* data, Ecore_Thread* thread) +{ + SLOG(LOG_INFO, TAG_TTSC, "[INFO] cancel reprepare thread"); + + 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"); + return; + } + client->thread = NULL; +} + int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg) { if (-1 == uid) { @@ -2659,7 +2689,7 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg) tts_dbus_remove_match(client->mode); if (NULL == data->thread) { SLOG(LOG_INFO, TAG_TTSC, "[INFO] ecore thread run: start_reprepare_thread"); - data->thread = ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, NULL, data->tts); + data->thread = ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, __cancel_reprepare_thread, data->tts); } } @@ -2701,7 +2731,7 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg) tts_dbus_remove_match(client->mode); if (NULL == client->thread) { SLOG(LOG_INFO, TAG_TTSC, "[INFO] ecore thread run: start_reprepare_thread"); - client->thread = ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, NULL, client->tts); + client->thread = ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, __cancel_reprepare_thread, client->tts); } } } diff --git a/server/ttsd_dbus_server.c b/server/ttsd_dbus_server.c index 0280ad9..f980c93 100644 --- a/server/ttsd_dbus_server.c +++ b/server/ttsd_dbus_server.c @@ -52,8 +52,8 @@ int ttsd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg) ret = TTS_ERROR_ALREADY_INITIALIZED; credential_needed = TTS_CREDENTIAL_NEEDED_ALREADY_INITIALIZED; } - ttsdc_send_hello(pid, uid, ret, (int)credential_needed); - } + ttsdc_send_hello(pid, uid, ret, (int)credential_needed); + } return 0; } -- 2.7.4