usbutils allow a short wait for resources to be released
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
diff --git a/usbutils.c b/usbutils.c
index 5fa7175..b75869f 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2368,12 +2368,14 @@ int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRe
void usb_cleanup()
{
struct cgpu_info *cgpu;
+ int count;
int i;
hotplug_time = 0;
nmsleep(10);
+ count = 0;
for (i = 0; i < total_devices; i++) {
cgpu = devices[i];
switch (cgpu->drv->drv_id) {
@@ -2383,11 +2385,40 @@ void usb_cleanup()
case DRIVER_ICARUS:
case DRIVER_AVALON:
release_cgpu(cgpu);
+ count++;
break;
default:
break;
}
}
+
+ /*
+ * Must attempt to wait for the resource thread to release coz
+ * during a restart it won't automatically release them in linux
+ */
+ if (count) {
+ struct timeval start, now;
+
+ cgtime(&start);
+ while (42) {
+ nmsleep(50);
+
+ mutex_lock(&cgusbres_lock);
+
+ if (!res_work_head)
+ break;
+
+ cgtime(&now);
+ if (tdiff(&now, &start) > 0.366) {
+ applog(LOG_WARNING,
+ "usb_cleanup gave up waiting for resource thread");
+ break;
+ }
+
+ mutex_unlock(&cgusbres_lock);
+ }
+ mutex_unlock(&cgusbres_lock);
+ }
}
void usb_initialise()