Merge branch 'master' into libusbx
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
diff --git a/cgminer.c b/cgminer.c
index 872dffe..c2a9133 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -7795,7 +7795,7 @@ static void probe_pools(void)
#ifdef USE_USBUTILS
static void *libusb_poll_thread(void __maybe_unused *arg)
{
- struct timeval tv_end = {0, 200000};
+ struct timeval tv_end = {1, 0};
RenameThread("usbpoll");
diff --git a/usbutils.c b/usbutils.c
index 320838a..f1ff4e2 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2268,6 +2268,11 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
#endif
unsigned char buf[512];
+ /* Prevent any further transfers during shutdown to allow the polling
+ * thread to be shut down after all existing transfers are complete */
+ if (unlikely(cgpu->shutdown))
+ return LIBUSB_SUCCESS;
+
usb_epinfo = &(cgpu->usbdev->found->intinfos[intinfo].epinfos[epinfo]);
endpoint = usb_epinfo->ep;
@@ -2708,7 +2713,7 @@ out_noerrmsg:
/* As we do for bulk reads, emulate a sync function for control transfers using
* our own timeouts that takes the same parameters as libusb_control_transfer.
*/
-static int usb_control_transfer(libusb_device_handle *dev_handle, uint8_t bmRequestType,
+static int usb_control_transfer(struct cgpu_info *cgpu, libusb_device_handle *dev_handle, uint8_t bmRequestType,
uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
unsigned char *buffer, uint16_t wLength, unsigned int timeout)
{
@@ -2716,6 +2721,9 @@ static int usb_control_transfer(libusb_device_handle *dev_handle, uint8_t bmRequ
unsigned char buf[70];
int err, transferred;
+ if (unlikely(cgpu->shutdown))
+ return LIBUSB_SUCCESS;
+
init_usb_transfer(&ut);
libusb_fill_control_setup(buf, bmRequestType, bRequest, wValue,
wIndex, wLength);
@@ -2796,8 +2804,8 @@ int __usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bReques
}
STATS_TIMEVAL(&tv_start);
cg_rlock(&cgusb_fd_lock);
- err = usb_control_transfer(usbdev->handle, request_type,
- bRequest, wValue, wIndex, buf, (uint16_t)siz, timeout);
+ err = usb_control_transfer(cgpu, usbdev->handle, request_type, bRequest,
+ wValue, wIndex, buf, (uint16_t)siz, timeout);
cg_runlock(&cgusb_fd_lock);
STATS_TIMEVAL(&tv_finish);
USB_STATS(cgpu, &tv_start, &tv_finish, err, MODE_CTRL_WRITE, cmd, SEQ0, timeout);
@@ -2878,9 +2886,8 @@ int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRe
memset(tbuf, 0, 64);
STATS_TIMEVAL(&tv_start);
cg_rlock(&cgusb_fd_lock);
- err = usb_control_transfer(usbdev->handle, request_type,
- bRequest, wValue, wIndex,
- tbuf, (uint16_t)bufsiz, timeout);
+ err = usb_control_transfer(cgpu, usbdev->handle, request_type, bRequest,
+ wValue, wIndex, tbuf, (uint16_t)bufsiz, timeout);
cg_runlock(&cgusb_fd_lock);
STATS_TIMEVAL(&tv_finish);
USB_STATS(cgpu, &tv_start, &tv_finish, err, MODE_CTRL_READ, cmd, SEQ0, timeout);