Skip to content

Commit

Permalink
Avoid busy loop in driver
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmarinov committed Oct 27, 2017
1 parent 7b5f9a7 commit 8ea5058
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import info.martinmarinov.usbxfer.UsbHiSpeedBulk;

public class UsbBulkSource implements ByteSource {
private final static int INITIAL_DELAY_BEFORE_BACKOFF = 10_000;
private final static int INITIAL_DELAY_BEFORE_BACKOFF = 1_000;
private final static int MAX_BACKOFF = 10;

private final UsbDeviceConnection usbDeviceConnection;
Expand Down Expand Up @@ -65,6 +65,8 @@ public void readNext(ByteSink sink) throws IOException, InterruptedException {
backoff++;
if (backoff > 0) {
Thread.sleep(backoff);
} else {
if (backoff % 3 == 0) Thread.sleep(1);
}
if (backoff > MAX_BACKOFF) {
backoff = MAX_BACKOFF;
Expand Down

0 comments on commit 8ea5058

Please sign in to comment.