diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2014-11-17 23:53:13 -0800 |
---|---|---|
committer | Chris Dickens <chris.dickens@hp.com> | 2014-12-19 11:21:24 -0800 |
commit | 3b371f1a6ab30bdebdadfcde1b96a9b98fb806ca (patch) | |
tree | a670f3735a809e60a62ea422dd0f10eba3ef5959 /libusb/core.c | |
parent | f5795bfa0e5d9e2ccd1e031d02269f041101aca7 (diff) | |
download | libusb-3b371f1a6ab30bdebdadfcde1b96a9b98fb806ca.tar.gz |
core: Eliminate hotplug pipe, using list and event pipe instead
To further consolidate libusb internal events, this change removes
the hotplug pipe. Hotplug messages are now kept in a list within the
context, and the event pipe is signalled when a new hotplug message
is added. When handling events, the hotplug messages will be processed
from the list instead of from a separate pipe.
This change is greatly beneficial for the Windows/WinCE backends which
do not allow pipes to be used in the WaitFor* functions.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Diffstat (limited to 'libusb/core.c')
-rw-r--r-- | libusb/core.c | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/libusb/core.c b/libusb/core.c index 13100da..626fabc 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -684,12 +684,8 @@ struct libusb_device *usbi_alloc_device(struct libusb_context *ctx, void usbi_connect_device(struct libusb_device *dev) { - libusb_hotplug_message message; - ssize_t ret; + struct libusb_context *ctx = DEVICE_CTX(dev); - memset(&message, 0, sizeof(message)); - message.event = LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED; - message.device = dev; dev->attached = 1; usbi_mutex_lock(&dev->ctx->usb_devs_lock); @@ -697,25 +693,17 @@ void usbi_connect_device(struct libusb_device *dev) usbi_mutex_unlock(&dev->ctx->usb_devs_lock); /* Signal that an event has occurred for this device if we support hotplug AND - * the hotplug pipe is ready. This prevents an event from getting raised during - * initial enumeration. */ - if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) && dev->ctx->hotplug_pipe[1] > 0) { - ret = usbi_write(dev->ctx->hotplug_pipe[1], &message, sizeof(message)); - if (sizeof (message) != ret) { - usbi_err(DEVICE_CTX(dev), "error writing hotplug message"); - } + * the hotplug message list is ready. This prevents an event from getting raised + * during initial enumeration. */ + if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) && dev->ctx->hotplug_msgs.next) { + usbi_hotplug_notification(ctx, dev, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED); } } void usbi_disconnect_device(struct libusb_device *dev) { - libusb_hotplug_message message; - struct libusb_context *ctx = dev->ctx; - ssize_t ret; + struct libusb_context *ctx = DEVICE_CTX(dev); - memset(&message, 0, sizeof(message)); - message.event = LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT; - message.device = dev; usbi_mutex_lock(&dev->lock); dev->attached = 0; usbi_mutex_unlock(&dev->lock); @@ -725,14 +713,11 @@ void usbi_disconnect_device(struct libusb_device *dev) usbi_mutex_unlock(&ctx->usb_devs_lock); /* Signal that an event has occurred for this device if we support hotplug AND - * the hotplug pipe is ready. This prevents an event from getting raised during - * initial enumeration. libusb_handle_events will take care of dereferencing the - * device. */ - if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) && dev->ctx->hotplug_pipe[1] > 0) { - ret = usbi_write(dev->ctx->hotplug_pipe[1], &message, sizeof(message)); - if (sizeof(message) != ret) { - usbi_err(DEVICE_CTX(dev), "error writing hotplug message"); - } + * the hotplug message list is ready. This prevents an event from getting raised + * during initial enumeration. libusb_handle_events will take care of dereferencing + * the device. */ + if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) && dev->ctx->hotplug_msgs.next) { + usbi_hotplug_notification(ctx, dev, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT); } } |