Changed timing strategy, got ~2x better performance
This commit is contained in:
parent
f9114248d1
commit
b9ae1990e8
|
@ -100,10 +100,20 @@ public abstract class IndependentTimedDevice extends TimedDevice {
|
|||
}
|
||||
}
|
||||
|
||||
public static int SLEEP_PRECISION_LIMIT = 100;
|
||||
public void sleepUntil(Long time) {
|
||||
if (time != null) {
|
||||
while (System.nanoTime() < time) {
|
||||
Thread.onSpinWait();
|
||||
int waitTime = (int) ((time - System.nanoTime()) / 1000000);
|
||||
if (waitTime >= SLEEP_PRECISION_LIMIT) {
|
||||
try {
|
||||
Thread.sleep(waitTime);
|
||||
} catch (InterruptedException ex) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Thread.onSpinWait();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue