We are always dependent on libusb handling events so use the blocking libusb_handle_events in the polling thread and use a bool to know if we should continue polling.
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 72 73 74 75 76 77 78 79
diff --git a/cgminer.c b/cgminer.c
index 79fd2ec..275f0dc 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -175,6 +175,8 @@ char *opt_usb_select = NULL;
int opt_usbdump = -1;
bool opt_usb_list_all;
cgsem_t usb_resource_sem;
+static pthread_t usb_poll_thread;
+static bool usb_polling;
#endif
char *opt_kernel_path;
@@ -3216,6 +3218,8 @@ static void __kill_work(void)
/* Release USB resources in case it's a restart
* and not a QUIT */
if (!opt_scrypt) {
+ usb_polling = false;
+
applog(LOG_DEBUG, "Releasing all USB devices");
usb_cleanup();
@@ -7742,19 +7746,15 @@ static void probe_pools(void)
#ifdef USE_USBUTILS
static void *libusb_poll_thread(void __maybe_unused *arg)
{
- struct timeval tv = { 0, USB_ASYNC_POLL * 1000 };
-
RenameThread("usbpoll");
pthread_detach(pthread_self());
- while (42)
- libusb_handle_events_timeout(NULL, &tv);
+ while (usb_polling)
+ libusb_handle_events(NULL);
return NULL;
}
-static pthread_t usb_poll_thread;
-
static void initialise_usb(void) {
int err = libusb_init(NULL);
if (err) {
@@ -7765,6 +7765,7 @@ static void initialise_usb(void) {
mutex_init(&cgusb_lock);
mutex_init(&cgusbres_lock);
cglock_init(&cgusb_fd_lock);
+ usb_polling = true;
pthread_create(&usb_poll_thread, NULL, libusb_poll_thread, NULL);
}
#else
diff --git a/usbutils.c b/usbutils.c
index 163906d..9506846 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2227,7 +2227,6 @@ static int callback_wait(struct cgpu_info *cgpu, struct usb_transfer *ut, int *t
int ret;
cgtime(&tv_now);
- timeout = timeout + USB_ASYNC_POLL;
ms_to_timespec(&ts_end, timeout);
timeval_to_spec(&ts_now, &tv_now);
timeraddspec(&ts_end, &ts_now);
diff --git a/usbutils.h b/usbutils.h
index 426f29e..19e64c5 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -15,10 +15,6 @@
#include "util.h"
-/* Asynchronous transfers require libusb to be polled at regular intervals.
- * Set the number of milliseconds to poll for incomplete work. */
-#define USB_ASYNC_POLL 10
-
#define EPI(x) (LIBUSB_ENDPOINT_IN | (unsigned char)(x))
#define EPO(x) (LIBUSB_ENDPOINT_OUT | (unsigned char)(x))