Slightly more efficient spinning

This commit is contained in:
DBotThePony 2024-02-04 20:36:22 +07:00
parent f0c816da1f
commit cae0a89ea2
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -56,7 +56,11 @@ class ExecutionSpinner(private val executor: MailboxExecutorService, private val
while (diff > 0L) {
executor.executeQueuedTasks()
diff = timeUntilNextFrame()
if (diff > SYSTEM_SCHEDULER_RESOLUTION) LockSupport.parkNanos(500_000L)
if (diff >= SYSTEM_SCHEDULER_RESOLUTION * 2L)
LockSupport.parkNanos(diff - SYSTEM_SCHEDULER_RESOLUTION)
else if (diff > SYSTEM_SCHEDULER_RESOLUTION)
LockSupport.parkNanos(SYSTEM_SCHEDULER_RESOLUTION)
}
val mark = System.nanoTime()
@ -96,7 +100,7 @@ class ExecutionSpinner(private val executor: MailboxExecutorService, private val
bindings.NtQueryTimerResolution(minimum, maximum, current)
SYSTEM_SCHEDULER_RESOLUTION = current[0] * 150L // give some room for error
SYSTEM_SCHEDULER_RESOLUTION = current[0] * 100L
LOGGER.info("NtQueryTimerResolution(): {} ns/{} ns/{} ns min/max/current", minimum[0] * 100L, maximum[0] * 100L, current[0] * 100L)
}
}