From 3438039c5e8a976a1380a98672598f81bbcc06e3 Mon Sep 17 00:00:00 2001 From: jdpurcell Date: Sun, 4 Jan 2015 21:52:44 +0000 Subject: [PATCH] Low CPU Throttle: Different sleep timing on OS X. --- BizHawk.Client.EmuHawk/Throttle.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/BizHawk.Client.EmuHawk/Throttle.cs b/BizHawk.Client.EmuHawk/Throttle.cs index f7bfef8530..ea17e7279e 100644 --- a/BizHawk.Client.EmuHawk/Throttle.cs +++ b/BizHawk.Client.EmuHawk/Throttle.cs @@ -361,11 +361,19 @@ namespace BizHawk.Client.EmuHawk int sleepy = (int)((timePerFrame - elapsedTime) * 1000 / afsfreq); if (cfg_lowcpumode && (sleepy >= 2 || paused)) { +#if WINDOWS // The actual sleep time on Windows is always at least the requested time, plus a // bit of oversleep which usually does not exceed the timer period as specified in // timeBeginPeriod. So we'll subtract 1 ms from the sleep time to avoid sleeping // longer than desired. - Thread.Sleep(Math.Max(sleepy - 1, 1)); + sleepy -= 1; +#else + // The actual sleep time on OS X with Mono is always at least the request time, + // plus a bit of oversleep which usually does not exceed 25% of the requested time. + // So we'll scale the sleep time back to account for that 25%. + sleepy = sleepy * 4 / 5; +#endif + Thread.Sleep(Math.Max(sleepy, 1)); // The original mode in the following 'else' block initially existed before the // call to timeBeginPeriod was added, which may explain its aversion to sleeping