File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 3030
3131void ares__tvnow (ares_timeval_t * now )
3232{
33- /* GetTickCount64() is available on Windows Vista and higher */
34- ULONGLONG milliseconds = GetTickCount64 ();
33+ /* QueryPerformanceCounters() has been around since Windows 2000, though
34+ * significant fixes were made in later versions. Documentation states
35+ * 1 microsecond or better resolution with a rollover not less than 100 years.
36+ * This differs from GetTickCount{64}() which has a resolution between 10 and
37+ * 16 ms. */
38+ LARGE_INTEGER freq ;
39+ LARGE_INTEGER current ;
3540
36- now -> sec = (ares_int64_t )milliseconds / 1000 ;
37- now -> usec = (unsigned int )(milliseconds % 1000 ) * 1000 ;
41+ /* Not sure how long it takes to get the frequency, I see it recommended to
42+ * cache it */
43+ QueryPerformanceFrequency (& freq );
44+ QueryPerformanceCounter (& current );
45+
46+ now -> sec = current .QuadPart / freq .QuadPart ;
47+ /* We want to prevent overflows so we get the remainder, then multiply to
48+ * microseconds before dividing */
49+ now -> usec = (unsigned int )(((current .QuadPart % freq .QuadPart ) * 1000000 ) /
50+ freq .QuadPart );
3851}
3952
4053#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC )
You can’t perform that action at this time.
0 commit comments