static pthread_mutex_t g_w_init_mutex = PTHREAD_MUTEX_INITIALIZER;
static Ecore_Thread* g_w_prepare_thread = NULL;
-static int g_w_prepare_canceled = 0;
+static bool g_ask_to_cancel_preparing = false;
+static bool g_is_prepare_thread_alive = false;
static int g_daemon_pid = 0;
return VC_ERROR_INVALID_STATE;
}
- g_w_prepare_canceled = 1;
+ g_ask_to_cancel_preparing = true;
vc_state_e state;
vc_widget_client_get_state(vc_w, &state);
SLOG(LOG_INFO, TAG_VCW, "@@@ Start prepare thread");
int ret = -1, retry_count = 0;
vc_h vc_w = (vc_h)data;
+ g_is_prepare_thread_alive = true;
/* Send hello */
while (0 != ret) {
- if (g_w_prepare_canceled) {
+ if (g_ask_to_cancel_preparing) {
SLOG(LOG_WARN, TAG_VCW, "[WARNING] Thread is canceled.");
+ __vc_widget_internal_unprepare(vc_w);
+ ecore_main_loop_thread_safe_call_async(__vc_widget_delete_focus_event_handler, NULL);
+ g_is_prepare_thread_alive = false;
return;
}
if (retry_count == 30) {
SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request hello !!");
ecore_main_loop_thread_safe_call_async(__vc_widget_delete_focus_event_handler, NULL);
+ g_is_prepare_thread_alive = false;
return;
}
ret = -1;
retry_count = 0;
while (0 != ret) {
- if (g_w_prepare_canceled) {
+ if (g_ask_to_cancel_preparing) {
SLOG(LOG_WARN, TAG_VCW, "[WARNING] Thread is canceled.");
+ __vc_widget_internal_unprepare(vc_w);
+ ecore_main_loop_thread_safe_call_async(__vc_widget_delete_focus_event_handler, NULL);
+ g_is_prepare_thread_alive = false;
return;
}
if (retry_count == 10) {
SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to connect daemon !!");
+ __vc_widget_internal_unprepare(vc_w);
ecore_main_loop_thread_safe_call_async(__vc_widget_delete_focus_event_handler, NULL);
+ g_is_prepare_thread_alive = false;
return;
}
ret = __vc_widget_connect_daemon((void*)vc_w);
}
SLOG(LOG_DEBUG, TAG_VCW, "@@@");
-
+ g_is_prepare_thread_alive = false;
return;
}
static void __end_prepare_thread(void *data, Ecore_Thread *thread)
{
- g_w_prepare_thread = NULL;
SLOG(LOG_DEBUG, TAG_VCW, "@@@ End prepare thread");
+ g_w_prepare_thread = NULL;
}
static void __cancel_prepare_thread(void *data, Ecore_Thread *thread)
{
SLOG(LOG_DEBUG, TAG_VCW, "@@@ Cancel prepare thread");
g_w_prepare_thread = NULL;
- g_w_prepare_canceled = 1;
}
int vc_widget_prepare(vc_h vc_w)
return VC_ERROR_NONE;
}
+ pthread_mutex_lock(&g_w_init_mutex);
vc_state_e state;
if (0 != vc_widget_client_get_state(vc_w, &state)) {
SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
SLOG(LOG_DEBUG, TAG_VCW, "@@@");
+ pthread_mutex_unlock(&g_w_init_mutex);
return VC_ERROR_INVALID_STATE;
}
if (state != VC_STATE_INITIALIZED) {
SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'");
SLOG(LOG_DEBUG, TAG_VCW, "@@@");
+ pthread_mutex_unlock(&g_w_init_mutex);
return VC_ERROR_INVALID_STATE;
}
if (NULL == widget) {
SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get widget handle");
SLOG(LOG_DEBUG, TAG_VCW, "@@@");
+ pthread_mutex_unlock(&g_w_init_mutex);
return VC_ERROR_INVALID_STATE;
}
// Check ecore thread
if (g_w_prepare_thread && !ecore_thread_check(g_w_prepare_thread)) {
- ecore_thread_cancel(g_w_prepare_thread);
- g_w_prepare_thread = NULL;
+ SLOG(LOG_INFO, TAG_VCW, "[INFO] prepare_thread is already runnning");
+ pthread_mutex_unlock(&g_w_init_mutex);
+ return VC_ERROR_NONE;
}
- g_w_prepare_canceled = 0;
+ g_ask_to_cancel_preparing = false;
g_w_prepare_thread = ecore_thread_run(__start_prepare_thread, __end_prepare_thread, __cancel_prepare_thread, (void*)vc_w);
SLOG(LOG_DEBUG, TAG_VCW, "@@@");
-
+ pthread_mutex_unlock(&g_w_init_mutex);
return VC_ERROR_NONE;
}
return VC_ERROR_NONE;
}
- int prev_thread_count = ecore_thread_active_get();
- int curr_thread_count = prev_thread_count;
+ pthread_mutex_lock(&g_w_init_mutex);
int count = 0;
- SLOG(LOG_INFO, TAG_VCW, "[Widget] Current thread count(%d)", curr_thread_count);
-
+ SLOG(LOG_WARN, TAG_VCW, "[Widget] prepare_thread info(%p), check(%d)", g_w_prepare_thread, ecore_thread_check(g_w_prepare_thread));
if (g_w_prepare_thread && !ecore_thread_check(g_w_prepare_thread)) {
- SLOG(LOG_WARN, TAG_VCW, "[WARNING] Thread is alive. Call cancel thread.");
- ecore_thread_cancel(g_w_prepare_thread);
+ bool ret = ecore_thread_cancel(g_w_prepare_thread);
+ g_ask_to_cancel_preparing = true;
+ SLOG(LOG_WARN, TAG_VCW, "[WARNING] Thread is alive. The cancel_thread is called, ret(%d)", ret);
}
- SLOG(LOG_WARN, TAG_VCW, "[Widget] thread info %d %d %d", curr_thread_count, prev_thread_count - curr_thread_count, !ecore_thread_check(g_w_prepare_thread));
- SLOG(LOG_WARN, TAG_VCW, "[Widget] thread count %d", count);
- while (0 < curr_thread_count && 1 != prev_thread_count - curr_thread_count && !ecore_thread_check(g_w_prepare_thread)) {
+ while (g_is_prepare_thread_alive) {
usleep(50000);
if (100 == count) {
- SLOG(LOG_WARN, TAG_VCW, "[WARNING!!] Thread is blocked, cnt(%d), thread count(%d)", count, curr_thread_count);
+ SLOG(LOG_WARN, TAG_VCW, "[WARNING!!] Thread is blocked, cnt(%d)", count);
break;
- } else if (0 == count % 5) {
- SLOG(LOG_WARN, TAG_VCW, "[WARNING!!] Thread is alive, cnt(%d), thread count(%d)", count, curr_thread_count);
+ } else if (0 != count && 0 == count % 5) {
+ SLOG(LOG_WARN, TAG_VCW, "[WARNING!!] Thread is alive, cnt(%d)", count);
}
count++;
- curr_thread_count = ecore_thread_active_get();
}
- g_w_prepare_thread = NULL;
+ SLOG(LOG_WARN, TAG_VCW, "[Widget] prepare_thread is terminated");
vc_state_e state;
if (0 != vc_widget_client_get_state(vc_w, &state)) {
SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available");
SLOG(LOG_DEBUG, TAG_VCW, "@@@");
+ pthread_mutex_unlock(&g_w_init_mutex);
return VC_ERROR_INVALID_STATE;
}
if (state != VC_STATE_READY) {
SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'READY', state(%d)", state);
SLOG(LOG_DEBUG, TAG_VCW, "@@@");
+ pthread_mutex_unlock(&g_w_init_mutex);
return VC_ERROR_INVALID_STATE;
}
g_w_notify_state_timer = ecore_timer_add(0, __vc_widget_notify_state_changed, vc_w);
SLOG(LOG_DEBUG, TAG_VCW, "@@@");
-
+ pthread_mutex_unlock(&g_w_init_mutex);
return VC_ERROR_NONE;
}