From 61cb40dc5fdc6cc22dd6a200ce2333f43d3a836a Mon Sep 17 00:00:00 2001 From: Cheoleun Moon Date: Thu, 24 Jan 2019 11:02:53 +0900 Subject: [PATCH] Use mutex_lock to access g_dp_event_thread_id Change-Id: I8c72f5ea5683e41192251ada63628c8fe1ff42b4 Signed-off-by: Cheoleun Moon --- provider-interface/download-provider-interface.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/provider-interface/download-provider-interface.c b/provider-interface/download-provider-interface.c index 401e3a8..8cacf66 100755 --- a/provider-interface/download-provider-interface.c +++ b/provider-interface/download-provider-interface.c @@ -299,8 +299,8 @@ static void *__dp_event_manager(void *arg) g_dp_client->notify = open(notify_fifo, O_RDONLY, 0600); if (g_dp_client->notify < 0) { TRACE_ERROR("[CRITICAL] failed to ESTABILISH IPC %s", notify_fifo); - g_dp_event_thread_id = 0; CLIENT_MUTEX_LOCK(&g_function_mutex); + g_dp_event_thread_id = 0; __clear_interface(); CLIENT_MUTEX_UNLOCK(&g_function_mutex); return 0; @@ -311,13 +311,16 @@ static void *__dp_event_manager(void *arg) pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); while (g_dp_client != NULL && g_dp_client->notify >= 0) { + CLIENT_MUTEX_LOCK(&g_function_mutex); if (g_dp_event_thread_id <= 0 || pthread_self() != g_dp_event_thread_id) { TRACE_ERROR("competitive threads self:%lu global:%lu", pthread_self(), g_dp_event_thread_id); // another thread may work. just terminate + CLIENT_MUTEX_UNLOCK(&g_function_mutex); break; } + CLIENT_MUTEX_UNLOCK(&g_function_mutex); // blocking fifo. dp_ipc_event_fmt eventinfo; @@ -327,8 +330,8 @@ static void *__dp_event_manager(void *arg) (eventinfo.id <= 0 && eventinfo.errorcode == DP_ERROR_CLIENT_DOWN)) { TRACE_INFO("expelled by provider"); - g_dp_event_thread_id = 0; CLIENT_MUTEX_LOCK(&g_function_mutex); + g_dp_event_thread_id = 0; __clear_interface(); CLIENT_MUTEX_UNLOCK(&g_function_mutex); return 0; @@ -364,7 +367,9 @@ static void *__dp_event_manager(void *arg) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); } // while + CLIENT_MUTEX_LOCK(&g_function_mutex); g_dp_event_thread_id = 0; // set 0 to not call pthread_cancel + CLIENT_MUTEX_UNLOCK(&g_function_mutex); TRACE_DEBUG("thread end by itself"); return 0; } -- 2.7.4