summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Szewczyk <p.szewczyk@samsung.com>2018-03-16 17:18:40 +0100
committersaerome kim <saerome.kim@samsung.com>2018-04-05 10:02:39 +0000
commite60e0d7651a397e509bda76ea140ec0a294cbd2f (patch)
tree288ddc30cf2b0a53f7a527f7f2f088bff31875f6
parentf3e40f271ca8c93b1027fb8dec237a3cae831857 (diff)
downloadmtp-responder-e60e0d7651a397e509bda76ea140ec0a294cbd2f.tar.gz
mtp-responder-e60e0d7651a397e509bda76ea140ec0a294cbd2f.tar.bz2
mtp-responder-e60e0d7651a397e509bda76ea140ec0a294cbd2f.zip
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 <p.szewczyk@samsung.com>
-rwxr-xr-xsrc/mtp_event_handler.c3
-rwxr-xr-xsrc/mtp_init.c7
2 files changed, 8 insertions, 2 deletions
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;
}