Replace Thread#sleep calls with Thread#onSpinWait

This commit is contained in:
JeremyStar™ 2024-08-30 03:06:36 +02:00
parent 0d4fa85c91
commit a3ca81498e
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 8 additions and 11 deletions

View file

@ -137,10 +137,9 @@ public final class Logger {
flushLogMessages(); flushLogMessages();
// Sleep for whatever has been configured // Sleep for whatever has been configured
try { long sleepDuration = System.currentTimeMillis() + EngineConfiguration.getInstance().getLoggerPollingSpeed();
//noinspection BusyWait while (System.currentTimeMillis() < sleepDuration)
Thread.sleep(EngineConfiguration.getInstance().getLoggerPollingSpeed()); Thread.onSpinWait();
} catch (Exception ignored) {}
} }
}; };

View file

@ -113,13 +113,11 @@ public abstract class ApiManagementClass {
splitDeltaTime.add(renderTime + sleepDuration); splitDeltaTime.add(renderTime + sleepDuration);
// Busy wait unless V-Sync is enabled // Busy wait unless V-Sync is enabled
if (WindowingSubsystemConfiguration.getInstance().getVsyncMode() == VsyncMode.OFF) if (WindowingSubsystemConfiguration.getInstance().getVsyncMode() == VsyncMode.OFF && WindowingSubsystemConfiguration.getInstance().getMaximumFramesPerSecond() >= 1) {
try { sleepDuration += System.currentTimeMillis();
//noinspection BusyWait // true, true, but there's no other way to do it while (System.currentTimeMillis() < sleepDuration)
Thread.sleep(sleepDuration); Thread.onSpinWait();
} catch (InterruptedException exception) { }
logger.crash("Rendering loop got interrupted. This is unsupported behaviour", exception);
}
// Calculate delta time and frame count every second // Calculate delta time and frame count every second
if (System.currentTimeMillis() >= reportDuration + 1000) { if (System.currentTimeMillis() >= reportDuration + 1000) {