From d151901049417aabe44e56a3511e742b86f63506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 14 Dec 2022 15:40:32 +0800 Subject: [PATCH] Common: improve resolution of `ffTimeGetTick` --- src/common/time.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/common/time.h b/src/common/time.h index a765e7834..797461cbd 100644 --- a/src/common/time.h +++ b/src/common/time.h @@ -6,20 +6,23 @@ #include #ifdef _WIN32 #include - #include + #include #else - #include #include #endif static inline uint64_t ffTimeGetTick() //In msec { #ifdef _WIN32 - return GetTickCount64(); + LARGE_INTEGER frequency; + QueryPerformanceFrequency(&frequency); + LARGE_INTEGER start; + QueryPerformanceCounter(&start); + return (uint64_t)(start.QuadPart * 1000 / frequency.QuadPart); #else - struct timeval timeNow; - gettimeofday(&timeNow, NULL); - return (uint64_t)((timeNow.tv_sec * 1000) + (timeNow.tv_usec / 1000)); + struct timespec timeNow; + clock_gettime(CLOCK_MONOTONIC, &timeNow); + return (uint64_t)((timeNow.tv_sec * 1000) + (timeNow.tv_nsec / 1000000)); #endif }