Cancel cancellable usb transfers on work restart messages.
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
diff --git a/cgminer.c b/cgminer.c
index d298241..07bd790 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3929,6 +3929,10 @@ static void restart_threads(void)
mutex_lock(&restart_lock);
pthread_cond_broadcast(&restart_cond);
mutex_unlock(&restart_lock);
+
+#ifdef USE_USBUTILS
+ cancel_usb_transfers();
+#endif
}
static void set_curblock(char *hexstr, unsigned char *hash)
diff --git a/usbutils.c b/usbutils.c
index f5ccbd6..90e890a 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2217,6 +2217,22 @@ struct usb_transfer {
struct list_head list;
};
+void cancel_usb_transfers(void)
+{
+ struct usb_transfer *ut;
+ int cancellations = 0;
+
+ cg_rlock(&cgusb_fd_lock);
+ list_for_each_entry(ut, &ct_list, list) {
+ libusb_cancel_transfer(ut->transfer);
+ cancellations++;
+ }
+ cg_runlock(&cgusb_fd_lock);
+
+ if (cancellations)
+ applog(LOG_DEBUG, "Cancelled %d USB transfers", cancellations);
+}
+
static void init_usb_transfer(struct usb_transfer *ut)
{
cgsem_init(&ut->cgsem);
diff --git a/usbutils.h b/usbutils.h
index 2750c09..2253337 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -356,6 +356,7 @@ enum usb_cmds {
struct device_drv;
struct cgpu_info;
+void cancel_usb_transfers(void);
void usb_all(int level);
const char *usb_cmdname(enum usb_cmds cmd);
void usb_applog(struct cgpu_info *bflsc, enum usb_cmds cmd, char *msg, int amount, int err);
@@ -409,6 +410,9 @@ void *usb_resource_thread(void *userdata);
#define usb_read_once_timeout(cgpu, buf, bufsiz, read, timeout, cmd) \
_usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, true, false)
+#define usb_read_once_timeout_cancellable(cgpu, buf, bufsiz, read, timeout, cmd) \
+ _usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, true, true)
+
#define usb_read_ii_once_timeout(cgpu, intinfo, buf, bufsiz, read, timeout, cmd) \
_usb_read(cgpu, intinfo, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, true, false)