Replace Thread#sleep calls with Thread#onSpinWait
This commit is contained in:
parent
0d4fa85c91
commit
a3ca81498e
2 changed files with 8 additions and 11 deletions
|
@ -137,10 +137,9 @@ public final class Logger {
|
|||
flushLogMessages();
|
||||
|
||||
// Sleep for whatever has been configured
|
||||
try {
|
||||
//noinspection BusyWait
|
||||
Thread.sleep(EngineConfiguration.getInstance().getLoggerPollingSpeed());
|
||||
} catch (Exception ignored) {}
|
||||
long sleepDuration = System.currentTimeMillis() + EngineConfiguration.getInstance().getLoggerPollingSpeed();
|
||||
while (System.currentTimeMillis() < sleepDuration)
|
||||
Thread.onSpinWait();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -113,13 +113,11 @@ public abstract class ApiManagementClass {
|
|||
splitDeltaTime.add(renderTime + sleepDuration);
|
||||
|
||||
// Busy wait unless V-Sync is enabled
|
||||
if (WindowingSubsystemConfiguration.getInstance().getVsyncMode() == VsyncMode.OFF)
|
||||
try {
|
||||
//noinspection BusyWait // true, true, but there's no other way to do it
|
||||
Thread.sleep(sleepDuration);
|
||||
} catch (InterruptedException exception) {
|
||||
logger.crash("Rendering loop got interrupted. This is unsupported behaviour", exception);
|
||||
}
|
||||
if (WindowingSubsystemConfiguration.getInstance().getVsyncMode() == VsyncMode.OFF && WindowingSubsystemConfiguration.getInstance().getMaximumFramesPerSecond() >= 1) {
|
||||
sleepDuration += System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() < sleepDuration)
|
||||
Thread.onSpinWait();
|
||||
}
|
||||
|
||||
// Calculate delta time and frame count every second
|
||||
if (System.currentTimeMillis() >= reportDuration + 1000) {
|
||||
|
|
Loading…
Reference in a new issue