diff options
author | Hans de Goede <hdegoede@redhat.com> | 2013-10-18 20:05:38 +0200 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2013-11-19 10:25:12 +0100 |
commit | 980b904bc062d22a02a845ba67e0d08aead26b83 (patch) | |
tree | e9b25bb9c97ce089a5b7616217b8c56eeac8821b | |
parent | ef5168b9f2244297ca206394ac35a054812b308e (diff) |
usbredirhost: Add usbredirhost_wait_for_cancel_completion helper
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r-- | usbredirhost/usbredirhost.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/usbredirhost/usbredirhost.c b/usbredirhost/usbredirhost.c index c41ca5f..4ec8aca 100644 --- a/usbredirhost/usbredirhost.c +++ b/usbredirhost/usbredirhost.c @@ -220,6 +220,7 @@ static void LIBUSB_CALL usbredirhost_iso_packet_complete( static void LIBUSB_CALL usbredirhost_buffered_packet_complete( struct libusb_transfer *libusb_transfer); static int usbredirhost_cancel_pending_urbs(struct usbredirhost *host); +static void usbredirhost_wait_for_cancel_completion(struct usbredirhost *host); static void usbredirhost_clear_device(struct usbredirhost *host); static void usbredirhost_log(void *priv, int level, const char *msg) @@ -816,21 +817,11 @@ int usbredirhost_set_device(struct usbredirhost *host, static void usbredirhost_clear_device(struct usbredirhost *host) { - int wait; - struct timeval tv; - if (!host->dev) return; - wait = usbredirhost_cancel_pending_urbs(host); - while (wait) { - memset(&tv, 0, sizeof(tv)); - tv.tv_usec = 2500; - libusb_handle_events_timeout(host->ctx, &tv); - LOCK(host); - wait = host->cancels_pending || host->transfers_head.next; - UNLOCK(host); - } + if (usbredirhost_cancel_pending_urbs(host)) + usbredirhost_wait_for_cancel_completion(host); usbredirhost_release(host, 1); @@ -1272,6 +1263,22 @@ static int usbredirhost_cancel_pending_urbs(struct usbredirhost *host) return wait; } +/* Called from close and parser read callbacks */ +void usbredirhost_wait_for_cancel_completion(struct usbredirhost *host) +{ + int wait; + struct timeval tv; + + do { + memset(&tv, 0, sizeof(tv)); + tv.tv_usec = 2500; + libusb_handle_events_timeout(host->ctx, &tv); + LOCK(host); + wait = host->cancels_pending || host->transfers_head.next; + UNLOCK(host); + } while (wait); +} + /* Only called from read callbacks */ static void usbredirhost_cancel_pending_urbs_on_interface( struct usbredirhost *host, int i) |