-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Windows WaitableTimer with high resolution if available #16
Comments
Seems promising. We'll need to look into:
|
This documentation explains how to use Windows timer objects. Seems like the timer can be created with |
Rust 1.75.0 std now does this. What's missing is for spin-sleep to detect at runtime if the Windows version actually supports this (if not we can fallback to current 1ms behaviour). To do this i think we can try once to create a high res timer and use the success/fail of that call to indicate support. If supported, and on rust >= 1.75 we can use std::thread::sleep with a much tighter accuracy configured. I'll run some tests to find a decent default accuracy for high-res win timers. As this relies on compilation with rust 1.75 this should become the min rust-version (even though the existing policy is latest stable, we want a stronger indication that 1.75 must be used). |
Alternatively we could just do the sleeping using the windows api and we wouldn't have any particular requirement on rust version, which may be nicer overall. |
Windows introduced a flag to create a "high resolution" timer in Windows 10, version 1803. On my system I can get 500µs resolution with it without fiddling with
timeBeginPeriod
.https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-createwaitabletimerexw
The text was updated successfully, but these errors were encountered: