Skip to content

Commit 766d647

Browse files
committed
shims: correct _dispatch_uptime for Windows
This should use `QueryUnbiasedInterruptTime` `QueryPerformanceCounter` is roughly in units of of TSC frequency. We would need to use `QueryPerformanceFrequency` to convert that into nanoseconds. Additionally, `QueryPerformanceCounter` includes time spent during suspend, which is not what is desired. Switch to `QueryUnbiasedInterruptTime` to get something close to `CLOCK_MONOTONIC` on Linux.
1 parent 55195b7 commit 766d647

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/shims/time.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@ _dispatch_uptime(void)
149149
struct timespec ts;
150150
dispatch_assume_zero(clock_gettime(CLOCK_UPTIME, &ts));
151151
return _dispatch_timespec_to_nano(ts);
152-
#elif TARGET_OS_WIN32
153-
LARGE_INTEGER now;
154-
return QueryPerformanceCounter(&now) ? now.QuadPart : 0;
152+
#elif defined(_WIN32)
153+
ULONGLONG ullUnbiasedTime;
154+
QueryUnbiasedInterruptTime(&ullUnbiasedTime);
155+
return ullUnbiasedTime * 100;
155156
#else
156157
#error platform needs to implement _dispatch_uptime()
157158
#endif

0 commit comments

Comments
 (0)