Skip to content

Commit 1ad3b0e

Browse files
authored
Merge pull request #2916 from readdle/5.3-mach-absolute-time-win
[5.3] Make mach_absolute_time implementation consistent with libdispatch
2 parents c955ad7 + cc42108 commit 1ad3b0e

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

CoreFoundation/Base.subproj/CoreFoundation_Prefix.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,9 @@ CF_EXPORT void OSMemoryBarrier();
215215

216216
CF_INLINE uint64_t mach_absolute_time() {
217217
#if TARGET_OS_WIN32
218-
LARGE_INTEGER count;
219-
QueryPerformanceCounter(&count);
220-
// mach_absolute_time is unsigned, but this function returns a signed value.
221-
return (uint64_t)count.QuadPart;
218+
ULONGLONG ullTime;
219+
QueryUnbiasedInterruptTimePrecise(&ullTime);
220+
return ullTime;
222221
#else
223222
struct timespec ts;
224223
clock_gettime(CLOCK_MONOTONIC, &ts);

CoreFoundation/NumberDate.subproj/CFDate.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,10 @@ CF_PRIVATE void __CFDateInitialize(void) {
171171
__CFTSRRate = (1.0E9 / (double)info.numer) * (double)info.denom;
172172
__CF1_TSRRate = 1.0 / __CFTSRRate;
173173
#elif TARGET_OS_WIN32
174-
LARGE_INTEGER freq;
175-
if (!QueryPerformanceFrequency(&freq)) {
176-
HALT;
177-
}
178-
__CFTSRRate = (double)freq.QuadPart;
174+
// We are using QueryUnbiasedInterruptTimePrecise as time source.
175+
// It returns result in system time units of 100 nanoseconds.
176+
// To get seconds we need to divide the value by 1e7 (10000000).
177+
__CFTSRRate = 1.0e7;
179178
__CF1_TSRRate = 1.0 / __CFTSRRate;
180179
#elif TARGET_OS_LINUX || TARGET_OS_BSD
181180
struct timespec res;

0 commit comments

Comments
 (0)