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/hotplug.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/hotplug.c')
-rw-r--r-- | libusb/hotplug.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/libusb/hotplug.c b/libusb/hotplug.c index 9ecb2c7..9171f2c 100644 --- a/libusb/hotplug.c +++ b/libusb/hotplug.c @@ -203,6 +203,27 @@ void usbi_hotplug_match(struct libusb_context *ctx, struct libusb_device *dev, /* the backend is expected to call the callback for each active transfer */ } +void usbi_hotplug_notification(struct libusb_context *ctx, struct libusb_device *dev, + libusb_hotplug_event event) +{ + libusb_hotplug_message *message = calloc(1, sizeof(*message)); + + if (!message) { + usbi_err(ctx, "error allocating hotplug message"); + return; + } + + message->event = event; + message->device = dev; + + /* Take the event data lock and add this message to the list. */ + usbi_mutex_lock(&ctx->event_data_lock); + list_add_tail(&message->list, &ctx->hotplug_msgs); + usbi_mutex_unlock(&ctx->event_data_lock); + + usbi_signal_event(ctx); +} + int API_EXPORTED libusb_hotplug_register_callback(libusb_context *ctx, libusb_hotplug_event events, libusb_hotplug_flag flags, int vendor_id, int product_id, int dev_class, @@ -285,8 +306,6 @@ void API_EXPORTED libusb_hotplug_deregister_callback (struct libusb_context *ctx libusb_hotplug_callback_handle handle) { struct libusb_hotplug_callback *hotplug_cb; - libusb_hotplug_message message; - ssize_t ret; /* check for hotplug support */ if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) { @@ -305,12 +324,7 @@ void API_EXPORTED libusb_hotplug_deregister_callback (struct libusb_context *ctx } usbi_mutex_unlock(&ctx->hotplug_cbs_lock); - /* wakeup handle_events to do the actual free */ - memset(&message, 0, sizeof(message)); - ret = usbi_write(ctx->hotplug_pipe[1], &message, sizeof(message)); - if (sizeof(message) != ret) { - usbi_err(ctx, "error writing hotplug message"); - } + usbi_hotplug_notification(ctx, NULL, 0); } void usbi_hotplug_deregister_all(struct libusb_context *ctx) { |