Fallback to gettimeofday, if clock_gettime supports monotonic yet fails to get the time.
v2: Fix gettimeofday fallback. Signed-off-by: Emil Velikov <emil.l.veli...@gmail.com> --- tests/util/piglit-util.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c index 5180bb8..b089944 100644 --- a/tests/util/piglit-util.c +++ b/tests/util/piglit-util.c @@ -662,15 +662,26 @@ piglit_time_is_monotonic(void) int64_t piglit_time_get_nano(void) { +#if !defined(_WIN32) #ifdef PIGLIT_HAS_POSIX_CLOCK_MONOTONIC struct timespec t; int r = clock_gettime(CLOCK_MONOTONIC, &t); - if (r >= 0) + + if (r == 0 || (r == -1 && errno != EINVAL)) return (t.tv_sec * INT64_C(1000000000)) + t.tv_nsec; - else - return -1LL; +#endif + struct timeval tv; + + gettimeofday(&tv, NULL); + return tv.tv_usec * INT64_C(1000) + tv.tv_sec * INT64_C(1000000000); #else - return -1LL; + static LARGE_INTEGER frequency; + LARGE_INTEGER counter; + + if (!frequency.QuadPart) + QueryPerformanceFrequency(&frequency); + QueryPerformanceCounter(&counter); + return counter.QuadPart * INT64_C(1000000000)/frequency.QuadPart; #endif } -- 2.1.3 _______________________________________________ Piglit mailing list Piglit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/piglit