Replace Thread#sleep calls with Thread#onSpinWait
All checks were successful
build-and-test / test (push) Successful in 1m28s
build-and-test / generate-javadoc (push) Successful in 1m36s
build-and-test / build (push) Successful in 1m52s

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();
// 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();
}
};

View file

@ -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) {