Commit 26a0ea5bdf9566c50df3884692fa274f24998f78

Con Kolivas 2014-02-26T23:30:48

Provide a usb_detect_one wrapper which only plugs one device at a time, breaking out otherwise.

diff --git a/usbutils.c b/usbutils.c
index 316e31e..db2835a 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2184,7 +2184,8 @@ static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv,
 	return NULL;
 }
 
-void usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struct libusb_device *, struct usb_find_devices *))
+void __usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struct libusb_device *, struct usb_find_devices *),
+		  bool single)
 {
 	libusb_device **list;
 	ssize_t count, i;
@@ -2244,6 +2245,8 @@ void usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struc
 				}
 				free(found);
 			}
+			if (single)
+				break;
 		}
 	}
 
diff --git a/usbutils.h b/usbutils.h
index c7b86ea..c47e41e 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -430,7 +430,10 @@ struct cgpu_info *usb_alloc_cgpu(struct device_drv *drv, int threads);
 struct cgpu_info *usb_free_cgpu(struct cgpu_info *cgpu);
 void usb_uninit(struct cgpu_info *cgpu);
 bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found);
-void usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struct libusb_device *, struct usb_find_devices *));
+void __usb_detect(struct device_drv *drv, struct cgpu_info *(*device_detect)(struct libusb_device *, struct usb_find_devices *),
+		  bool single);
+#define usb_detect(drv, cgpu) __usb_detect(drv, cgpu, false)
+#define usb_detect_one(drv, cgpu) __usb_detect(drv, cgpu, true)
 struct api_data *api_usb_stats(int *count);
 void update_usb_stats(struct cgpu_info *cgpu);
 void usb_reset(struct cgpu_info *cgpu);