From: Paweł Szewczyk Date: Fri, 16 Mar 2018 16:18:40 +0000 (+0100) Subject: Fix mtp exit X-Git-Tag: accepted/tizen/unified/20180406.144331~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e60e0d7651a397e509bda76ea140ec0a294cbd2f;p=platform%2Fcore%2Fconnectivity%2Fmtp-responder.git Fix mtp exit 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 --- diff --git a/src/mtp_event_handler.c b/src/mtp_event_handler.c index 0dbf921..417c748 100755 --- a/src/mtp_event_handler.c +++ b/src/mtp_event_handler.c @@ -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; diff --git a/src/mtp_init.c b/src/mtp_init.c index 2f749a1..02a7b1b 100755 --- a/src/mtp_init.c +++ b/src/mtp_init.c @@ -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; }