Keep the libusb event handle polling thread active until there are no async usb transfers in progress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/cgminer.c b/cgminer.c
index 293163f..31fa6e1 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -7798,16 +7798,23 @@ static void probe_pools(void)
#ifdef USE_USBUTILS
static void *libusb_poll_thread(void __maybe_unused *arg)
{
- struct timeval tv_end = {0, 100000};
+ struct timeval tv_end = {1, 0};
+ bool inprogress = false;
RenameThread("usbpoll");
while (usb_polling)
libusb_handle_events_timeout_completed(NULL, &tv_end, NULL);
- /* One longer poll on shut down to enable drivers to hopefully cleanly
- * shut down. */
- tv_end.tv_sec = 1;
- libusb_handle_events_timeout_completed(NULL, &tv_end, NULL);
+
+ /* Keep event handling going until there are no async transfers in
+ * flight. */
+ do {
+ libusb_handle_events_timeout_completed(NULL, &tv_end, NULL);
+
+ cg_rlock(&cgusb_fd_lock);
+ inprogress = !!cgusb_transfers;
+ cg_runlock(&cgusb_fd_lock);
+ } while (inprogress);
return NULL;
}
diff --git a/usbutils.h b/usbutils.h
index ff136e4..68031e5 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -117,6 +117,8 @@
#define DEFAULT_EP_IN 0
#define DEFAULT_EP_OUT 1
+int cgusb_transfers;
+
struct usb_epinfo {
uint8_t att;
uint16_t size;