diff options
author | Hans de Goede <hdegoede@redhat.com> | 2013-05-24 16:15:51 +0200 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2013-05-30 14:20:36 +0200 |
commit | cedc7f6e289c427c84a9175045b06614be56ec5a (patch) | |
tree | 50837d92d28e3aac578ba4c20a531c4fc1245b3f /libusb/os/linux_netlink.c | |
parent | 7ced70e14968bd6869a561d2cf8e7ac5a1df8938 (diff) | |
download | libusb-cedc7f6e289c427c84a9175045b06614be56ec5a.tar.gz |
hotplug: Add a hotplug_poll backend function
Apps which were written before hotplug support, may listen for hotplug events
on their own and call libusb_get_device_list on device addition.
In this case libusb_get_device_list will likely return a list without the new
device in there, as the hotplug event thread will still be busy enumerating
the device, which may take a while, or may not even have seen the event yet.
To avoid this add a new hotplug_poll backend function and make
libusb_get_device_list call a this before copying ctx->usb_devs to the user.
In this function the backend should ensure any pending hotplug events are
fully processed before returning.
This patch implements hotplug_poll for linux, it should probably be also
implemented for darwin.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'libusb/os/linux_netlink.c')
-rw-r--r-- | libusb/os/linux_netlink.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/libusb/os/linux_netlink.c b/libusb/os/linux_netlink.c index 7b1fdcd..3a68f69 100644 --- a/libusb/os/linux_netlink.c +++ b/libusb/os/linux_netlink.c @@ -241,3 +241,14 @@ static void *linux_netlink_event_thread_main(void *arg) return NULL; } + +void linux_netlink_hotplug_poll(void) +{ + int r; + + usbi_mutex_static_lock(&linux_hotplug_lock); + do { + r = linux_netlink_read_message(); + } while (r == 0); + usbi_mutex_static_unlock(&linux_hotplug_lock); +} |