mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-06-26 00:29:30 +00:00
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) {
|
public void sleepUntil(Long time) {
|
||||||
if (time != null) {
|
if (time != null) {
|
||||||
while (System.nanoTime() < time) {
|
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
Block a user