On Thu, May 02, 2019 at 08:47:29AM -0500, Ken Thomases wrote:
On May 2, 2019, at 3:45 AM, Huw Davies <huw(a)codeweavers.com> wrote:
-NTSTATUS WINAPI NtQuerySystemTime( PLARGE_INTEGER Time ) +NTSTATUS WINAPI NtQuerySystemTime( LARGE_INTEGER *time ) { - struct timeval now; +#if defined(HAVE_CLOCK_GETTIME) + struct timespec ts; + static clockid_t clock_id = -1;
- gettimeofday( &now, 0 ); - Time->QuadPart = now.tv_sec * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970; - Time->QuadPart += now.tv_usec * 10; + if (clock_id == -1) + { + struct timespec res; + + /* Use CLOCK_REALTIME_COARSE if it has 1 ms or better resolution */ + if (!clock_getres( CLOCK_REALTIME_COARSE, &res ) && res.tv_sec == 0 && res.tv_nsec <= 1000000) + clock_id = CLOCK_REALTIME_COARSE; + else + clock_id = CLOCK_REALTIME;
Having clock_gettime() doesn't necessarily imply having CLOCK_REALTIME_COARSE. It seems that baseline POSIX only requires CLOCK_REALTIME.
Good point, thanks! Huw.