]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
xz/Windows: Ensure that clock_gettime() isn't used with MinGW-w64.
authorLasse Collin <lasse.collin@tukaani.org>
Sun, 24 Sep 2023 19:58:53 +0000 (22:58 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Sun, 22 Oct 2023 15:59:45 +0000 (18:59 +0300)
This commit alone doesn't change anything in the real-world:

  - configure.ac currently checks for clock_gettime() only
    when using pthreads.

  - CMakeLists.txt doesn't check for clock_gettime() on Windows.

So clock_gettime() wasn't used with MinGW-w64 before either.

clock_gettime() provides monotonic time and it's better than
gettimeofday() in this sense. But clock_gettime() is defined
in winpthreads, and liblzma or xz needs nothing else from
winpthreads. By avoiding clock_gettime(), we avoid the dependency on
libwinpthread-1.dll or the need to link against the static version.

As a bonus, GetTickCount64() and MinGW-w64's gettimeofday() can be
faster than clock_gettime(CLOCK_MONOTONIC, &tv). The resolution
is more than good enough for the progress indicator in xz.

src/xz/mytime.c

index ddfd5deb532f8727e3a29e5b977a7825691ccf1d..4d8da513481d02156f9de20e309e346c97380c36 100644 (file)
@@ -14,7 +14,7 @@
 
 #if defined(MYTHREAD_VISTA) || defined(_MSC_VER)
        // Nothing
-#elif defined(HAVE_CLOCK_GETTIME)
+#elif defined(HAVE_CLOCK_GETTIME) && !defined(__MINGW32__)
 #      include <time.h>
 #else
 #      include <sys/time.h>
@@ -59,7 +59,12 @@ mytime_now(void)
        // there's no reason to avoid a WinVista API here either.
        return GetTickCount64();
 
-#elif defined(HAVE_CLOCK_GETTIME)
+#elif defined(HAVE_CLOCK_GETTIME) && !defined(__MINGW32__)
+       // MinGW-w64: clock_gettime() is defined in winpthreads but we need
+       // nothing else from winpthreads. By avoiding clock_gettime(), we
+       // avoid the dependency on libwinpthread-1.dll or the need to link
+       // against the static version. The downside is that the fallback
+       // method, gettimeofday(), doesn't provide monotonic time.
        struct timespec tv;
 
 #      ifdef HAVE_CLOCK_MONOTONIC