try a different approach to fix the windows monotonic counter
parent
c84f46fe8b
commit
7077cb4bfb
|
@ -43,9 +43,8 @@ u64 nano_count()
|
||||||
{
|
{
|
||||||
LARGE_INTEGER count;
|
LARGE_INTEGER count;
|
||||||
LARGE_INTEGER frequency;
|
LARGE_INTEGER frequency;
|
||||||
static u32 hi_correction = 0;
|
static u32 hi = 0;
|
||||||
static u32 hi = 0xffffffff;
|
static u32 lo = 0;
|
||||||
static u32 lo = 0xffffffff;
|
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
ret = QueryPerformanceCounter(&count);
|
ret = QueryPerformanceCounter(&count);
|
||||||
if(ret == 0)
|
if(ret == 0)
|
||||||
|
@ -54,14 +53,13 @@ u64 nano_count()
|
||||||
if(ret == 0)
|
if(ret == 0)
|
||||||
fatal_error("QueryPerformanceFrequency", 0);
|
fatal_error("QueryPerformanceFrequency", 0);
|
||||||
|
|
||||||
if((u32)count.LowPart < lo && (u32)count.HighPart == hi)
|
printf("hi = %u, lo = %u\n", hi, lo);
|
||||||
hi_correction++;
|
|
||||||
|
|
||||||
hi = count.HighPart;
|
if(count.LowPart < lo)
|
||||||
|
hi += 1;
|
||||||
lo = count.LowPart;
|
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)
|
void sleep_nanos(u64 nsec)
|
||||||
|
|
Loading…
Reference in New Issue