Improve time/sleep accuracy on Windows

It's now almost as good as Linux thanks to a Windows 8+ API.
This commit is contained in:
Justine Tunney 2023-11-18 01:57:44 -08:00
parent 72ac5f18d9
commit 8caf1b48a9
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
9 changed files with 76 additions and 31 deletions

View file

@ -40,7 +40,11 @@ static dontinline int __clk_tck_init(void) {
size_t len;
struct clockinfo_netbsd clock;
if (IsWindows()) {
x = 1000;
// MSVC defines CLK_TCK as 1000 but 1ms is obviously not the
// scheduling quantum Windows actually uses. If we define it
// as 30 rather than 1000, then clock_nanosleep is much more
// accurately able to predict the duration of its busy waits
x = 30;
} else if (IsXnu() || IsOpenbsd()) {
x = 100;
} else if (IsFreebsd()) {