Use mutex_lock to access g_dp_event_thread_id 38/198338/2 submit/tizen/20190124.035615
authorCheoleun Moon <chleun.moon@samsung.com>
Thu, 24 Jan 2019 02:02:53 +0000 (11:02 +0900)
committerCheoleun Moon <chleun.moon@samsung.com>
Thu, 24 Jan 2019 02:06:44 +0000 (11:06 +0900)
Change-Id: I8c72f5ea5683e41192251ada63628c8fe1ff42b4
Signed-off-by: Cheoleun Moon <chleun.moon@samsung.com>
provider-interface/download-provider-interface.c

index 401e3a8..8cacf66 100755 (executable)
@@ -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;
 }