Commit 7ae878aa53a73c38a4ce0683bc6e2cfa0e4dd5b9

Con Kolivas 2013-12-08T12:44:45

Initialise usb locks within usbutils.c instead of exporting them.

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)