From: VBS Date: Thu, 26 Dec 2024 11:50:06 +0000 (+0900) Subject: Call request_tidl_connect in subthread X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=34e77a3745d7bdda904c46111aecb91cbf4dd48c;p=platform%2Fcore%2Fuifw%2Ftts.git Call request_tidl_connect in subthread - Issue: There is a case that it takes long time when requesting of tidl connection is invoked. Because of this behavior, the main thread is blocked. - Solution: We change to request tidl connection in subthread. Change-Id: I2be9a192fd57930d8e90bd9afb078232e78a6fd2 Signed-off-by: VBS --- diff --git a/client/tts_tidl.c b/client/tts_tidl.c index 3e29e16e..2bf1e467 100644 --- a/client/tts_tidl.c +++ b/client/tts_tidl.c @@ -37,7 +37,9 @@ static GList* g_tidl_infos = NULL; static GSList *g_destruction_scheduled_handles = NULL; static Ecore_Idler *g_destroy_handles_idler = NULL; +static Ecore_Thread *g_connect_thread = NULL; +static pthread_mutex_t g_info_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t g_rpc_h_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -356,6 +358,7 @@ int tts_tidl_stop_listening(unsigned int uid) static void __request_tidl_connect(tts_tidl_info_s* info) { if (info->connection_requesting) { + SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Request for connection is already done"); return; } @@ -491,6 +494,43 @@ static int __check_and_prepare_rpc_port(tts_tidl_info_s* info) return __reset_rpc_port(info, engine_id); } +static void __start_connect_thread(void* data, Ecore_Thread* thread) +{ + SLOG(LOG_INFO, TAG_TTSC, "[TIDL] Start connect thread"); + pthread_mutex_lock(&g_info_mutex); + + unsigned int uid = (uintptr_t)data; + + tts_client_s* client = tts_client_get_by_uid(uid); + if (NULL == client) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client"); + pthread_mutex_unlock(&g_info_mutex); + return; + } + + tts_tidl_info_s* info = __get_tidl_info_s(uid); + if (NULL == info) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get tidl info"); + pthread_mutex_unlock(&g_info_mutex); + return; + } + + __request_tidl_connect(info); + pthread_mutex_unlock(&g_info_mutex); +} + +static void __end_connect_thread(void* data, Ecore_Thread* thread) +{ + SLOG(LOG_INFO, TAG_TTSC, "[TIDL] End connect thread"); + g_connect_thread = NULL; +} + +static void __cancel_connect_thread(void* data, Ecore_Thread* thread) +{ + SLOG(LOG_INFO, TAG_TTSC, "[TIDL] Cancel connect thread"); + g_connect_thread = NULL; +} + int tts_tidl_request_hello(unsigned int uid, tts_mode_e mode, tts_playing_mode_e playing_mode, int registered_event_mask) { SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_hello"); @@ -508,7 +548,20 @@ int tts_tidl_request_hello(unsigned int uid, tts_mode_e mode, tts_playing_mode_e if (!info->connected) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not Connected"); - __request_tidl_connect(info); + if (NULL != g_connect_thread) { + SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Connect thread is already running"); + return TTS_ERROR_OPERATION_FAILED; + } + + /* check whether request for connection is done or not */ + if (info->connection_requesting) { + SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Request for connection is already done"); + return TTS_ERROR_OPERATION_FAILED; + } + + SLOG(LOG_INFO, TAG_TTSC, "[INFO] Create g_connect_thread. ecore thread run"); + g_connect_thread = ecore_thread_run(__start_connect_thread, __end_connect_thread, __cancel_connect_thread, (void*)uid); + return TTS_ERROR_OPERATION_FAILED; }