summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Hjelm <hjelmn@me.com>2014-05-12 17:36:46 -0600
committerNathan Hjelm <hjelmn@me.com>2014-05-12 17:40:12 -0600
commit26dab3d6808a00c28a0d222c8f6625d4e719a5b2 (patch)
treeb28ffe88ed7314bb3320d7931374d920b3942d10
parent3893c4fcc92765cfa934e8762b7951fe8648ef7e (diff)
downloadlibusb-26dab3d6808a00c28a0d222c8f6625d4e719a5b2.tar.gz
darwin: initial implemenations of the hotplug_poll function
This implementation makes use of the IOKitWaitQuiet which waits until all IOKit processing is complete. The performance won't necessarily be great but it should help codes that have not yet or cannot move to the libusb hotplug API. Signed-off-by: Nathan Hjelm <hjelmn@me.com>
-rw-r--r--libusb/os/darwin_usb.c20
-rw-r--r--libusb/version_nano.h2
2 files changed, 17 insertions, 5 deletions
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index 0607c70..9bd183e 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -284,6 +284,8 @@ static void darwin_devices_detached (void *ptr, io_iterator_t rem_devices) {
UInt64 session;
int ret;
+ usbi_mutex_lock(&active_contexts_lock);
+
while ((device = IOIteratorNext (rem_devices)) != 0) {
/* get the location from the i/o registry */
ret = get_ioregistry_value_number (device, CFSTR("sessionID"), kCFNumberSInt64Type, &session);
@@ -291,8 +293,6 @@ static void darwin_devices_detached (void *ptr, io_iterator_t rem_devices) {
if (!ret)
continue;
- usbi_mutex_lock(&active_contexts_lock);
-
list_for_each_entry(ctx, &active_contexts_list, list, struct libusb_context) {
usbi_dbg ("notifying context %p of device disconnect", ctx);
@@ -304,9 +304,20 @@ static void darwin_devices_detached (void *ptr, io_iterator_t rem_devices) {
libusb_unref_device(dev);
}
}
-
- usbi_mutex_unlock(&active_contexts_lock);
}
+
+ usbi_mutex_unlock(&active_contexts_lock);
+}
+
+void darwin_hotplug_poll (void)
+{
+ /* not sure if 5 seconds will be too long/short but it should work ok */
+ mach_timespec_t timeout = {.tv_sec = 5, .tv_nsec = 0};
+
+ /* since a kernel thread may nodify the IOInterators used for
+ * hotplug notidication we can't just clear the iterators.
+ * instead just wait until all IOService providers are quiet */
+ (void) IOKitWaitQuiet (kIOMasterPortDefault, &timeout);
}
static void darwin_clear_iterator (io_iterator_t iter) {
@@ -1959,6 +1970,7 @@ const struct usbi_os_backend darwin_backend = {
.get_device_descriptor = darwin_get_device_descriptor,
.get_active_config_descriptor = darwin_get_active_config_descriptor,
.get_config_descriptor = darwin_get_config_descriptor,
+ .hotplug_poll = darwin_hotplug_poll,
.open = darwin_open,
.close = darwin_close,
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index ea3ff7c..43d1ae3 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 10886
+#define LIBUSB_NANO 10887