hotplug: Wakeup libusb_handle_events on libusb_hotplug_deregister_callback
authorHans de Goede <hdegoede@redhat.com>
Thu, 4 Jul 2013 14:38:22 +0000 (16:38 +0200)
committerHans de Goede <hdegoede@redhat.com>
Fri, 5 Jul 2013 07:06:21 +0000 (09:06 +0200)
This serves 2 purposes:

1) We use lazy free-ing of the callback structure, for it to be actually
free-ed usbi_hotplug_match() needs to be called. This ensures this actually
happens (rather then waiting for a hotplug event to arrive, and not freeing
the callback as long as no such event arrives).

2) It causes libusb_handle_events to return to its caller on a call to
libusb_hotplug_deregister_callback, which is very useful for apps which use
a thread to do their apps (hotplug) event handling, otherwise that thread will
hang when the app tries to stop until some event happens.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
libusb/hotplug.c
libusb/version_nano.h

index 8a8755c..6b04342 100644 (file)
@@ -278,6 +278,8 @@ 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)) {
@@ -295,6 +297,13 @@ 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");
+       }
 }
 
 void usbi_hotplug_deregister_all(struct libusb_context *ctx) {
index fc87a0d..1988fdb 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10769
+#define LIBUSB_NANO 10770