/* Static variables */
-static atomic_bool g_is_thread_canceled = false;
-
static char* g_engine_name = NULL;
static int g_engine_update_status = 0;
static atomic_bool g_is_engine_name_changed = false;
static pkgmgr_client* g_pkgmgr = NULL;
static Ecore_Thread* g_pkgmgr_thread = NULL;
static pthread_mutex_t g_pkgmgr_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t g_pkgmgr_cond = PTHREAD_COND_INITIALIZER;
static char* g_language = NULL;
static int g_voice_type = -1;
static void __create_pkgmgr_thread(void* data, Ecore_Thread* thread)
{
SLOG(LOG_INFO, TAG_TTSC, "[DEBUG] create pkgmgr thread");
+ static const long long MAX_TIME_DELAY = 60000000000ll;
+ long long time_delay = 10000000ll;
+ int cnt = 0;
pthread_mutex_lock(&g_pkgmgr_mutex);
- int time_delay = 10000;
- int cnt = 0;
while (NULL == g_pkgmgr) {
/* Checking the thread is canceled or not */
- if (g_is_thread_canceled) {
+ if (EINA_TRUE == ecore_thread_check(g_pkgmgr_thread)) {
SLOG(LOG_INFO, TAG_TTSC, "[INFO] g_pkgmgr_thread is canceled. Exit");
break;
}
g_pkgmgr = NULL;
}
- if (0 == cnt % 5) time_delay *= 2;
+ if (MAX_TIME_DELAY > time_delay && 0 == cnt % 5) time_delay *= 2;
+
+ struct timespec time_sleep;
+ timespec_get(&time_sleep, TIME_UTC);
+ time_sleep.tv_nsec += time_delay % 1000000000;
+ int quotient = time_sleep.tv_nsec / 1000000000;
+ time_sleep.tv_nsec = time_sleep.tv_nsec % 1000000000;
+ time_sleep.tv_sec += time_delay / 1000000000 + quotient;
- usleep(time_delay);
+ pthread_cond_timedwait(&g_pkgmgr_cond, &g_pkgmgr_mutex, &time_sleep);
cnt++;
}
pthread_mutex_unlock(&g_pkgmgr_mutex);
static void __finish_pkgmgr_thread(void* data, Ecore_Thread* thread)
{
SLOG(LOG_INFO, TAG_TTSC, "[DEBUG] Finish pkgmgr thread");
- g_is_thread_canceled = false;
g_pkgmgr_thread = NULL;
}
static void __cancel_pkgmgr_thread(void* data, Ecore_Thread* thread)
{
SLOG(LOG_INFO, TAG_TTSC, "[DEBUG] Cancel pkgmgr thread");
- g_is_thread_canceled = false;
g_pkgmgr_thread = NULL;
}
//LCOV_EXCL_STOP
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);
- ecore_thread_wait(g_reprepare_thread, 0.5); // wait g_reprepare_thread is terminated.
+
+ ecore_thread_wait(g_reprepare_thread, 1.0); // wait g_reprepare_thread is terminated.
+ g_reprepare_thread = NULL;
}
app_manager_unset_app_context_event_cb();
if (NULL != g_pkgmgr_thread) {
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Cancel pkgmgr thread");
- g_is_thread_canceled = true;
+ ecore_thread_cancel(g_pkgmgr_thread);
+
+ pthread_mutex_lock(&g_pkgmgr_mutex);
+ pthread_cond_broadcast(&g_pkgmgr_cond);
+ pthread_mutex_unlock(&g_pkgmgr_mutex);
+
+ ecore_thread_wait(g_pkgmgr_thread, 1.0); // wait g_reprepare_thread is terminated.
+ g_pkgmgr_thread = NULL;
}
if (NULL != g_language) {