diff options
author | Daniel Drake <dsd@gentoo.org> | 2008-05-29 17:26:26 +0100 |
---|---|---|
committer | Daniel Drake <dsd@gentoo.org> | 2008-05-29 17:26:26 +0100 |
commit | 2d3a1111caff40ebb87983c861ff548cdc9e5946 (patch) | |
tree | 1f412e2b3adb99ca4387617e08362d97679b4bb0 | |
parent | 514bb8790cfe8b93ccfff82bc17081b1030acce0 (diff) | |
download | libusb-2d3a1111caff40ebb87983c861ff548cdc9e5946.tar.gz |
Temporary workaround for event handling serialization issue
Ludovic Rousseau pointed out that libusb_unlock_events() is not called
when a thread gets terminated with a signal, meaning that event waiters
will not be woken up in this case.
Add a temporary hack to libusb_event_handler_active() so that at least
the other threads will realise on the next iteration of their event
handling loop.
The real fix will likely involve reworking most of this.
-rw-r--r-- | libusb/io.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/libusb/io.c b/libusb/io.c index 6ed19c1..4e85bdf 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -1145,7 +1145,21 @@ API_EXPORTED void libusb_unlock_events(void) */ API_EXPORTED int libusb_event_handler_active(void) { - return event_handler_active; + int r; + + if (!event_handler_active) + return 0; + + /* FIXME: temporary hack to ensure thread didn't quit (e.g. due to signal) + * without libusb_unlock_events being triggered */ + r = pthread_mutex_trylock(&events_lock); + if (r == 0) { + event_handler_active = 0; + pthread_mutex_unlock(&events_lock); + return 0; + } + + return 1; } /** \ingroup poll |