Commit 9d8e3df0a8f0fed49961061a8077728effa8975d

Con Kolivas 2013-10-25T04:07:09

Add usb transfer cancellation on shutdown and documentation regarding where cancellable transfers are suitable.

diff --git a/cgminer.c b/cgminer.c
index 07bd790..d7d91ef 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3931,6 +3931,9 @@ static void restart_threads(void)
 	mutex_unlock(&restart_lock);
 
 #ifdef USE_USBUTILS
+	/* Cancels any cancellable usb transfers. Flagged as such it means they
+	 * are usualy waiting on a read result and it's safe to abort the read
+	 * early. */
 	cancel_usb_transfers();
 #endif
 }
@@ -7814,6 +7817,9 @@ static void *libusb_poll_thread(void __maybe_unused *arg)
 	while (usb_polling)
 		libusb_handle_events_timeout_completed(NULL, &tv_end, NULL);
 
+	/* Cancel any cancellable usb transfers */
+	cancel_usb_transfers();
+
 	/* Keep event handling going until there are no async transfers in
 	 * flight. */
 	do {
diff --git a/usbutils.c b/usbutils.c
index 90e890a..5811413 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2217,6 +2217,10 @@ struct usb_transfer {
 	struct list_head list;
 };
 
+/* Cancellable transfers should only be labelled as such if it is safe for them
+ * to effectively mimic timing out early. This flag is usually used to signify
+ * a read is waiting on a non-critical response that takes a long time and the
+ * driver wishes it be aborted if work restart message has been sent. */
 void cancel_usb_transfers(void)
 {
 	struct usb_transfer *ut;