If we're compiling for Windows 6 (Vista, Server 2008) or later, the
GetTickCount64 [1] function is available.
Note that MSVC as of version 19.39 doesn't provide
__attribute__((constructor)), or the __typeof__ extension.

[1]: 
https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-gettickcount64

Signed-off-by: Antonin Décimo <anto...@tarides.com>
---
 mingw-w64-libraries/winpthreads/src/misc.c | 29 +++++++++++++++-------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/src/misc.c 
b/mingw-w64-libraries/winpthreads/src/misc.c
index 83caf262f..f9239045d 100644
--- a/mingw-w64-libraries/winpthreads/src/misc.c
+++ b/mingw-w64-libraries/winpthreads/src/misc.c
@@ -24,15 +24,6 @@
 #include "pthread.h"
 #include "misc.h"
 
-static ULONGLONG (*GetTickCount64FuncPtr) (VOID);
-
-static void __attribute__((constructor)) ctor (void)
-{
-  HMODULE mod = GetModuleHandle("kernel32.dll");
-  if (mod)
-    GetTickCount64FuncPtr = (__typeof__(GetTickCount64FuncPtr)) 
GetProcAddress(mod, "GetTickCount64");
-}
-
 unsigned long long _pthread_time_in_ms(void)
 {
     FILETIME ft;
@@ -61,6 +52,25 @@ unsigned long long _pthread_rel_time_in_ms(const struct 
timespec *ts)
     return t1 - t2;
 }
 
+#if defined(_WIN32_WINNT) && defined(_WIN32_WINNT_WIN6) \
+    && _WIN32_WINNT >= _WIN32_WINNT_WIN6
+static unsigned long long
+_pthread_get_tick_count (long long *frequency)
+{
+  UNREFERENCED_PARAMETER(frequency);
+  return GetTickCount64 ();
+}
+
+#else
+static ULONGLONG (*GetTickCount64FuncPtr) (VOID);
+
+static void __attribute__((constructor)) ctor (void)
+{
+  HMODULE mod = GetModuleHandle("kernel32.dll");
+  if (mod)
+    GetTickCount64FuncPtr = (__typeof__(GetTickCount64FuncPtr)) 
GetProcAddress(mod, "GetTickCount64");
+}
+
 static unsigned long long
 _pthread_get_tick_count (long long *frequency)
 {
@@ -83,6 +93,7 @@ _pthread_get_tick_count (long long *frequency)
   /* Fallback */
   return GetTickCount ();
 }
+#endif
 
 /* A wrapper around WaitForSingleObject() that ensures that
  * the wait function does not time out before the time
-- 
2.43.0



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to