Initialise usb locks within usbutils.c instead of exporting them.
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 80 81 82 83 84 85 86 87 88 89
diff --git a/cgminer.c b/cgminer.c
index 690afa6..b28c9ba 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -208,12 +208,6 @@ int hotplug_time = 5;
pthread_mutex_t lockstat_lock;
#endif
-#ifdef USE_USBUTILS
-pthread_mutex_t cgusb_lock;
-pthread_mutex_t cgusbres_lock;
-cglock_t cgusb_fd_lock;
-#endif
-
pthread_mutex_t hash_lock;
static pthread_mutex_t *stgd_lock;
pthread_mutex_t console_lock;
@@ -7818,14 +7812,13 @@ static void *libusb_poll_thread(void __maybe_unused *arg)
static void initialise_usb(void) {
int err = libusb_init(NULL);
+
if (err) {
fprintf(stderr, "libusb_init() failed err %d", err);
fflush(stderr);
quit(1, "libusb_init() failed");
}
- mutex_init(&cgusb_lock);
- mutex_init(&cgusbres_lock);
- cglock_init(&cgusb_fd_lock);
+ initialise_usblocks();
usb_polling = true;
pthread_create(&usb_poll_thread, NULL, libusb_poll_thread, NULL);
}
diff --git a/miner.h b/miner.h
index 28798db..b2c1718 100644
--- a/miner.h
+++ b/miner.h
@@ -1049,12 +1049,6 @@ extern int opt_queue;
extern int opt_scantime;
extern int opt_expiry;
-#ifdef USE_USBUTILS
-extern pthread_mutex_t cgusb_lock;
-extern pthread_mutex_t cgusbres_lock;
-extern cglock_t cgusb_fd_lock;
-#endif
-
extern cglock_t control_lock;
extern pthread_mutex_t hash_lock;
extern pthread_mutex_t console_lock;
diff --git a/usbutils.c b/usbutils.c
index a4999f9..1320169 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -18,6 +18,10 @@
#include "miner.h"
#include "usbutils.h"
+static pthread_mutex_t cgusb_lock;
+static pthread_mutex_t cgusbres_lock;
+static cglock_t cgusb_fd_lock;
+
#define NODEV(err) ((err) != LIBUSB_SUCCESS && (err) != LIBUSB_ERROR_TIMEOUT)
#define NOCONTROLDEV(err) ((err) < 0 && NODEV(err))
@@ -3627,3 +3631,10 @@ void *usb_resource_thread(void __maybe_unused *userdata)
return NULL;
}
+
+void initialise_usblocks(void)
+{
+ mutex_init(&cgusb_lock);
+ mutex_init(&cgusbres_lock);
+ cglock_init(&cgusb_fd_lock);
+}
diff --git a/usbutils.h b/usbutils.h
index a83f164..0b883bd 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -408,6 +408,7 @@ void usb_set_dev_start(struct cgpu_info *cgpu);
void usb_cleanup();
void usb_initialise();
void *usb_resource_thread(void *userdata);
+void initialise_usblocks(void);
#define usb_read(cgpu, buf, bufsiz, read, cmd) \
_usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false, false)