From 7077cb4bfb63b56a3df3beded3078c26acf1e061 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 22 Dec 2009 14:36:33 -0600 Subject: [PATCH] try a different approach to fix the windows monotonic counter --- vm/os-windows-nt.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/vm/os-windows-nt.cpp b/vm/os-windows-nt.cpp index b781ced02f..6aabe92d71 100755 --- a/vm/os-windows-nt.cpp +++ b/vm/os-windows-nt.cpp @@ -43,9 +43,8 @@ u64 nano_count() { LARGE_INTEGER count; LARGE_INTEGER frequency; - static u32 hi_correction = 0; - static u32 hi = 0xffffffff; - static u32 lo = 0xffffffff; + static u32 hi = 0; + static u32 lo = 0; BOOL ret; ret = QueryPerformanceCounter(&count); if(ret == 0) @@ -54,14 +53,13 @@ u64 nano_count() if(ret == 0) fatal_error("QueryPerformanceFrequency", 0); - if((u32)count.LowPart < lo && (u32)count.HighPart == hi) - hi_correction++; + printf("hi = %u, lo = %u\n", hi, lo); - hi = count.HighPart; + if(count.LowPart < lo) + hi += 1; lo = count.LowPart; - count.HighPart += hi_correction; - return count.QuadPart*(1000000000/frequency.QuadPart); + return (((u64)hi << 32) | (u64)lo)*(1000000000/frequency.QuadPart); } void sleep_nanos(u64 nsec)