diff options
author | Hans de Goede <hdegoede@redhat.com> | 2013-07-04 16:38:22 +0200 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2013-07-05 09:06:21 +0200 |
commit | ac41bfc0fdcf2229fbeb19cdf802cc6b551fd365 (patch) | |
tree | 6ed0898e2ce20dda2e28644e2d83ab56f6adc3e4 | |
parent | f50592979811a00d52305ea02b420cb9cacc99b4 (diff) | |
download | libusb-ac41bfc0fdcf2229fbeb19cdf802cc6b551fd365.tar.gz |
hotplug: Wakeup libusb_handle_events on libusb_hotplug_deregister_callback
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>
-rw-r--r-- | libusb/hotplug.c | 9 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 10 insertions, 1 deletions
diff --git a/libusb/hotplug.c b/libusb/hotplug.c index 8a8755c..6b04342 100644 --- a/libusb/hotplug.c +++ b/libusb/hotplug.c @@ -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) { diff --git a/libusb/version_nano.h b/libusb/version_nano.h index fc87a0d..1988fdb 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10769 +#define LIBUSB_NANO 10770 |