From 07c635a0ed402d6fb7c309c83dbdb9c21fad93bc Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Mon, 16 May 2016 08:02:02 -0700 Subject: mtp: Use libusb interruption mechanism Now that libusb 1.0.21 is finally out, there is a way to explicitly interrupt a thread that is waiting for events. This allows us to use a long timeout on our event waiting, which we can interrupt, rather than a short, one second, timeout. The only nuance is that we need to link against libusb directly to be able to use the interrupt mechanism. This is a little bit ugly, but is necessary unless libmtp wraps the interruption call. --- daemon/gvfsbackendmtp.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'daemon/gvfsbackendmtp.c') diff --git a/daemon/gvfsbackendmtp.c b/daemon/gvfsbackendmtp.c index 7570b6ab..dddc4d56 100644 --- a/daemon/gvfsbackendmtp.c +++ b/daemon/gvfsbackendmtp.c @@ -34,6 +34,9 @@ #include #include +#if HAVE_LIBUSB +#include +#endif #include "gvfsbackendmtp.h" #include "gvfsicon.h" @@ -76,7 +79,11 @@ * Constants ************************************************/ +#if HAVE_LIBUSB +#define EVENT_POLL_PERIOD { 3600, 0 } +#else #define EVENT_POLL_PERIOD { 1, 0 } +#endif /************************************************ * Private Types @@ -959,6 +966,10 @@ do_unmount (GVfsBackend *backend, GVfsJobUnmount *job, g_atomic_int_set (&op_backend->unmount_started, TRUE); +#if HAVE_LIBUSB + libusb_interrupt_event_handler (NULL); +#endif + #ifdef HAVE_LIBMTP_1_1_12 /* Thread will terminate after flag is set. */ g_thread_join (op_backend->event_thread); -- cgit v1.2.1