Fix mtp exit 07/172907/3
authorPaweł Szewczyk <p.szewczyk@samsung.com>
Fri, 16 Mar 2018 16:18:40 +0000 (17:18 +0100)
committersaerome kim <saerome.kim@samsung.com>
Thu, 5 Apr 2018 10:02:39 +0000 (10:02 +0000)
This allows to call exit function from event handler thread. Without it
the g_main_loop could hang after event handler stopped.

Also debug info was fixed: the "mtp terminated" message appears when mtp
is actualy terminating.

Change-Id: I970bc927221374705b66aadf24ec0bdc49dac601
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
src/mtp_event_handler.c
src/mtp_init.c

index 0dbf921..417c748 100755 (executable)
@@ -274,9 +274,10 @@ static void *__thread_event_handler(void *arg)
                }
        }
 
-       DBG("######### MTP TERMINATED #########");
+       DBG("Event handler terminated");
        close(g_pipefd[0]);
        close(g_pipefd[1]);
+       mtp_end_event();
 
        _util_thread_exit("__thread_event_handler thread is over.");
        return NULL;
index 2f749a1..02a7b1b 100755 (executable)
@@ -67,7 +67,7 @@ static void __mtp_exit(void)
        long cur_time;
 
        DBG("## Terminate all threads");
-       if (g_eh_thrd) {
+       if (g_eh_thrd && g_eh_thrd != pthread_self()) {
                _eh_send_event_req_to_eh_thread(EVENT_USB_REMOVED, 0, 0, NULL);
                if (_util_thread_join(g_eh_thrd, NULL) == FALSE)
                        ERR("_util_thread_join() Fail");
@@ -84,6 +84,9 @@ static void __mtp_exit(void)
 
        g_main_loop_quit(g_mainloop);
 
+       if (g_eh_thrd == pthread_self())
+               _util_thread_exit("Event handler stopped itself");
+
        return;
 }
 
@@ -505,5 +508,7 @@ int main(int argc, char *argv[])
        _eh_deregister_notification_callbacks();
        media_content_disconnect();
 
+       DBG("######### MTP TERMINATED #########");
+
        return MTP_ERROR_NONE;
 }