windows: finer granularity for sleep
The Windows scheduler tends to work on 16ms bounaries, which is not good for sleeping (as part of an animation, say) for times near or less than 16ms. Change rktio to request more fine-grained scheduling temporarily when trying to sleep for a short time.
This commit is contained in:
parent
c754bd851e
commit
2f22a5638d
|
@ -1228,6 +1228,23 @@ void rkio_reset_sleep_backoff(rktio_t *rktio)
|
|||
rktio->made_progress = 1;
|
||||
}
|
||||
|
||||
static void prepare_windows_sleep(DWORD msec)
|
||||
{
|
||||
/* The default scheduling granilaity is usually 16ms, which
|
||||
means that a request to sleep 16ms could easily end up being 31ms,
|
||||
and a request to sleep 2ms is likely at least 16ms. We can
|
||||
request a finer granularity of scheduling, but do that only
|
||||
temporarily, because it may slow down the rest of the system. */
|
||||
if (msec < 32)
|
||||
timeBeginPeriod((msec >> 2) | 1);
|
||||
}
|
||||
|
||||
static void finish_windows_sleep(DWORD msec)
|
||||
{
|
||||
if (msec < 32)
|
||||
timeEndPeriod((msec >> 1) | 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/******************** Main sleep function *****************/
|
||||
|
@ -1304,7 +1321,14 @@ void rktio_sleep(rktio_t *rktio, float nsecs, rktio_poll_set_t *fds, rktio_ltps_
|
|||
# endif
|
||||
#else
|
||||
# ifdef RKTIO_SYSTEM_WINDOWS
|
||||
Sleep((DWORD)(nsecs * 1000));
|
||||
{
|
||||
DWORD msecs = nsecs * 1000;
|
||||
if (msecs > 0) {
|
||||
prepare_windows_sleep(msecs);
|
||||
Sleep(msecs);
|
||||
finish_windows_sleep(msecs);
|
||||
}
|
||||
}
|
||||
# else
|
||||
# ifndef NO_SLEEP
|
||||
# ifndef NO_USLEEP
|
||||
|
@ -1455,7 +1479,9 @@ void rktio_sleep(rktio_t *rktio, float nsecs, rktio_poll_set_t *fds, rktio_ltps_
|
|||
msec = INFINITE;
|
||||
}
|
||||
|
||||
prepare_windows_sleep(msec);
|
||||
result = MsgWaitForMultipleObjects(count, array, FALSE, msec, fds->wait_event_mask);
|
||||
finish_windows_sleep(msec);
|
||||
}
|
||||
clean_up_wait(rktio, result, array, rps, rcount);
|
||||
rktio_collapse_win_fd(fds); /* cleans up */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
INCS = /I.. /I..\..\rktio /I..\librktio /I..\..\worksp\cs /I$(SCHEME_DIR)\$(MACHINE)\boot\$(MACHINE)
|
||||
|
||||
RKTIO_LIB = ..\..\build\librktio.lib
|
||||
BASE_WIN32_LIBS = WS2_32.lib Shell32.lib User32.lib
|
||||
BASE_WIN32_LIBS = WS2_32.lib Shell32.lib User32.lib Winmm.lib
|
||||
WIN32_LIBS = $(BASE_WIN32_LIBS) RpCrt4.lib Ole32.lib Advapi32.lib
|
||||
SCHEME_LIB_FULL = $(SCHEME_DIR)\$(MACHINE)\boot\$(MACHINE)\$(SCHEME_LIB)
|
||||
|
||||
|
|
|
@ -288,7 +288,7 @@
|
|||
(define dll "../../../lib/libracket3mxxxxxxx.dll")
|
||||
(define exe (format "../../../Racket~a.exe" suffix))
|
||||
|
||||
(define libs "kernel32.lib user32.lib ws2_32.lib shell32.lib advapi32.lib")
|
||||
(define libs "kernel32.lib user32.lib ws2_32.lib shell32.lib advapi32.lib winmm.lib")
|
||||
|
||||
(define (link-dll objs delayloads sys-libs dll link-options exe?)
|
||||
(let ([ms (if (file-exists? dll)
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/MACHINE:I386"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib Winmm.lib"
|
||||
OutputFile="..\..\..\lib\libracketxxxxxxx.dll"
|
||||
SuppressStartupBanner="true"
|
||||
GenerateDebugInformation="true"
|
||||
|
@ -91,7 +91,7 @@
|
|||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/MACHINE:X64"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib Winmm.lib"
|
||||
OutputFile="..\..\..\lib\libracketxxxxxxx.dll"
|
||||
SuppressStartupBanner="true"
|
||||
GenerateDebugInformation="true"
|
||||
|
@ -137,7 +137,7 @@
|
|||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/MACHINE:I386"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib Winmm.lib"
|
||||
OutputFile="..\..\..\lib\libracketxxxxxxx.dll"
|
||||
SuppressStartupBanner="true"
|
||||
GenerateDebugInformation="true"
|
||||
|
@ -181,7 +181,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib Winmm.lib"
|
||||
OutputFile="..\..\..\lib\libracketxxxxxxx.dll"
|
||||
SuppressStartupBanner="true"
|
||||
GenerateDebugInformation="true"
|
||||
|
@ -224,7 +224,7 @@
|
|||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/MACHINE:I386"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib Winmm.lib"
|
||||
OutputFile="..\..\..\lib\libracketxxxxxxx.dll"
|
||||
SuppressStartupBanner="true"
|
||||
GenerateDebugInformation="true"
|
||||
|
@ -266,7 +266,7 @@
|
|||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/MACHINE:X64"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib Winmm.lib"
|
||||
OutputFile="..\..\..\lib\libracketxxxxxxx.dll"
|
||||
SuppressStartupBanner="true"
|
||||
GenerateDebugInformation="true"
|
||||
|
@ -312,7 +312,7 @@
|
|||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/MACHINE:I386"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib Winmm.lib"
|
||||
OutputFile="..\..\..\lib\libracketxxxxxxx.dll"
|
||||
SuppressStartupBanner="true"
|
||||
GenerateDebugInformation="true"
|
||||
|
@ -356,7 +356,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib"
|
||||
AdditionalDependencies="WS2_32.lib Shell32.lib User32.lib Winmm.lib"
|
||||
OutputFile="..\..\..\lib\libracketxxxxxxx.dll"
|
||||
SuppressStartupBanner="true"
|
||||
GenerateDebugInformation="true"
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
<Culture>0x0409</Culture>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>WS2_32.lib;Shell32.lib;User32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>WS2_32.lib;Shell32.lib;User32.lib;Winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>..\..\..\lib\libracketxxxxxxx.dll</OutputFile>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
|
Loading…
Reference in New Issue
Block a user