Hello, I have looked at all 32 commits and I have few comments.
I'm writing them inline below.

On Sunday 04 October 2026 03:13:20 Kirill Makurin wrote:
> From b21116335dd76fd8fd156135b50a79ca404839ec Mon Sep 17 00:00:00 2001
> From: Kirill Makurin <[email protected]>
> Date: Sun, 4 Oct 2026 09:46:13 +0900
> Subject: [PATCH 10/32] winpthreads: clock.c: remove static function
>  `lc_set_errno`
> 
> Signed-off-by: Kirill Makurin <[email protected]>
> ---
>  mingw-w64-libraries/winpthreads/src/clock.c | 42 +++++++++++----------
>  1 file changed, 22 insertions(+), 20 deletions(-)
> 
> diff --git a/mingw-w64-libraries/winpthreads/src/clock.c 
> b/mingw-w64-libraries/winpthreads/src/clock.c
> index 312723230..2cd5f9d74 100644
> --- a/mingw-w64-libraries/winpthreads/src/clock.c
> +++ b/mingw-w64-libraries/winpthreads/src/clock.c
> @@ -32,15 +32,6 @@
>   */
>  #define DELTA_EPOCH_IN_100NS INT64_C(116444736000000000)
>  
> -static WINPTHREADS_INLINE int lc_set_errno(int result)
> -{
> -    if (result != 0) {
> -        errno = result;
> -        return -1;
> -    }
> -    return 0;
> -}
> -
>  /**
>   * Get the resolution of the specified clock clock_id and
>   * stores it in the struct timespec pointed to by res.
> @@ -75,7 +66,8 @@ int clock_getres64 (clockid_t clock_id, struct _timespec64 
> *res)
>              LARGE_INTEGER pf;
>  
>              if (QueryPerformanceFrequency(&pf) == 0) {
> -                return lc_set_errno(EINVAL);
> +                _set_errno(EINVAL);

I would suggest to use "errno = EINVAL" instead of calling _set_errno()
function. That function is not available in older CRT libraries and
mingw-w64 provides just an emulation. Also the function itself can fail
and caller should check the return value of _set_errno().

In past we have been already replacing _set_errno() usage by errno= in
existing mingw-w64 codebase. So I think it makes to follow the existing
pattern.

> +                return -1;
>              }
>  
>              res->tv_sec = 0;


> From 178dd1922afe5fe1c1864bb2eb369dd24cbfd25d Mon Sep 17 00:00:00 2001
> From: Kirill Makurin <[email protected]>
> Date: Sun, 4 Oct 2026 09:46:14 +0900
> Subject: [PATCH 24/32] winpthreads: time.c: update `_pthread_time_in_ms`
> 
> Use more MSVC-friendly `unsinged __int64` instead of `unsigned long long`.
> 
> Signed-off-by: Kirill Makurin <[email protected]>
> ---
>  mingw-w64-libraries/winpthreads/src/time.c    | 22 +++++++++++++++----
>  .../winpthreads/src/winpthreads-time.h        |  2 +-
>  2 files changed, 19 insertions(+), 5 deletions(-)
> 
> diff --git a/mingw-w64-libraries/winpthreads/src/time.c 
> b/mingw-w64-libraries/winpthreads/src/time.c
> index 52e093295..7da2f0b2b 100644
> --- a/mingw-w64-libraries/winpthreads/src/time.c
> +++ b/mingw-w64-libraries/winpthreads/src/time.c
> @@ -24,6 +24,7 @@
>  #include "config.h"
>  #endif
>  
> +#include <stdint.h>
>  #include <time.h>
>  
>  #define WIN32_LEAN_AND_MEAN
> @@ -40,16 +41,29 @@
>   * This file contains all time-related definitions used by the library.
>   */
>  
> +#define POW10_4 10000
> +
> +/**
> + * Number of 100ns intervals between the beginning of the Windows epoch
> + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970)
> + */
> +#define DELTA_EPOCH_IN_100NS INT64_C(116444736000000000)

IIRC for __int64 it is not need to include stdint.h and not needed to
use INT64_C. That is also because __int64 support predates stdint.h
support in MSVC.

> +
>  VOID (WINAPI *_pthread_get_system_time_best_as_file_time) (LPFILETIME) = 
> NULL;
>  ULONGLONG (WINAPI *_pthread_get_tick_count_64) (VOID) = NULL;
>  
> -unsigned long long _pthread_time_in_ms (void)
> +unsigned __int64 _pthread_time_in_ms (void)
>  {
> -  FILETIME ft;
> +  FILETIME fileTime;
> +
> +  _pthread_get_system_time_best_as_file_time (&fileTime);
>  
> -  GetSystemTimeAsFileTime (&ft);
> +  ULARGE_INTEGER value = {
> +    .HighPart = fileTime.dwHighDateTime,
> +    .LowPart  = fileTime.dwLowDateTime
> +  };
>  
> -  return (((unsigned long long) ft.dwHighDateTime << 32) + ft.dwLowDateTime 
> - 0x19DB1DED53E8000ULL) / 10000ULL;
> +  return (value.QuadPart - DELTA_EPOCH_IN_100NS) / POW10_4;
>  }
>  
>  unsigned long long _pthread_time_in_ms_from_timespec (const struct 
> _timespec64 *ts)


> From 86764ffc2d53caefec530a2ead9899ae7ff1f502 Mon Sep 17 00:00:00 2001
> From: Kirill Makurin <[email protected]>
> Date: Sun, 4 Oct 2026 09:46:15 +0900
> Subject: [PATCH 31/32] winpthreads: time.c: update runtime checks logic
> 
> Move runtime checks for time-related function from `winpthreads_init` in 
> misc.c
> to new `winpthreads_time_init` in time.c; call the latter from the former.
> 
> The looked up functions now stored in local `TimeApi` structure in time.c,
> instaed of global variables with external linkage.
> 
> The following functions are looked up at runtime:
> 
> 1. `GetSystemTimeAsFileTime`, which is available since Windows NT 3.51;
>   if not available, it is replaced with a simple wrapper around
>   `GetSystemTime` and `SystemTimeToFileTime`.
> 
> 2. `GetSystemTimePreciseAsFileTime`, which is available since Windows 8;
>   if not available, use `GetSystemTimeAsFileTime` or its replacement.
> 
> 3. `GetSystemTimeAdjustment`, which is available since Windows NT 3.5;
>   if not available, it is replaced with a simple stub which always fails.
> 
> 4. `GetSystemTimeAdjustmentPrecise`, which is available since Windows 10;
>   if not available, use a wrapper around `GetSystemTimeAdjustment`.
> 
> 5. `GetTickCount64`, which is available since Windows Vista;
>   if not available, use a wrapper around `GetTickCount`.
> 
> Signed-off-by: Kirill Makurin <[email protected]>
> ---
>  mingw-w64-libraries/winpthreads/src/misc.c    |  12 +-
>  mingw-w64-libraries/winpthreads/src/time.c    | 217 ++++++++++++++++--
>  .../winpthreads/src/winpthreads-time.h        |  16 +-
>  3 files changed, 206 insertions(+), 39 deletions(-)
> 
> diff --git a/mingw-w64-libraries/winpthreads/src/misc.c 
> b/mingw-w64-libraries/winpthreads/src/misc.c
> index fa97e051c..8492035f8 100644
> --- a/mingw-w64-libraries/winpthreads/src/misc.c
> +++ b/mingw-w64-libraries/winpthreads/src/misc.c
> @@ -51,21 +51,11 @@ static void winpthreads_init(void)
>          _pthread_get_handle_information =
>              (BOOL (WINAPI *)(HANDLE, LPDWORD))(void*) GetProcAddress(mod, 
> "GetHandleInformation");
>  
> -        _pthread_get_tick_count_64 =
> -            (ULONGLONG (WINAPI *)(VOID))(void*) GetProcAddress(mod, 
> "GetTickCount64");
> -
>          _pthread_set_thread_description =
>              (HRESULT (WINAPI *)(HANDLE, PCWSTR))(void*) GetProcAddress(mod, 
> "SetThreadDescription");
>  
> -        /* <1us precision on Windows 10 */
> -        _pthread_get_system_time_best_as_file_time =
> -            (void (WINAPI *)(LPFILETIME))(void*) GetProcAddress(mod, 
> "GetSystemTimePreciseAsFileTime");
>      }
>  
> -    if (!_pthread_get_system_time_best_as_file_time)
> -        /* >15ms precision on Windows 10 */
> -        _pthread_get_system_time_best_as_file_time = GetSystemTimeAsFileTime;
> -
>      /* Although SetThreadDescription lives in kernel32.dll, on Windows 
> Server 2016,
>       * Windows 10 LTSB 2016 and Windows 10 version 1607, it was only 
> available in
>       * kernelbase.dll. So, load it from there for maximum coverage.
> @@ -79,6 +69,8 @@ static void winpthreads_init(void)
>                  (HRESULT (WINAPI *)(HANDLE, PCWSTR))(void*) 
> GetProcAddress(mod, "SetThreadDescription");
>          }
>      }
> +
> +    winpthreads_time_init();
>  }
>  #if defined(__GNUC__) && __GNUC__ >= 9 && !defined(__clang__)
>  #pragma GCC diagnostic pop
> diff --git a/mingw-w64-libraries/winpthreads/src/time.c 
> b/mingw-w64-libraries/winpthreads/src/time.c
> index 3e2e99dbc..e6e2e531a 100644
> --- a/mingw-w64-libraries/winpthreads/src/time.c
> +++ b/mingw-w64-libraries/winpthreads/src/time.c
> @@ -85,8 +85,193 @@
>   */
>  #define DELTA_EPOCH_IN_100NS INT64_C(116444736000000000)
>  
> -VOID (WINAPI *_pthread_get_system_time_best_as_file_time) (LPFILETIME) = 
> NULL;
> -ULONGLONG (WINAPI *_pthread_get_tick_count_64) (VOID) = NULL;
> +/*******************************************************************************
> + * In order to provide the best coverage in terms of backward compatibility
> + * and feature support, we lookup functions which may not be available on 
> older
> + * Windows versions at runtime, and use them if they are available.
> + *
> + * If some function is not available, we provide a simple replacement or 
> stub.
> + */
> +
> +/**
> + * Function type corresponding to `GetSystemTimeAsFileTime` and
> + * `GetSystemTimePreciseAsFileTime`.
> + */
> +typedef VOID (WINAPI *FuncGetSystemTimeAsFileTime) (FILETIME *);
> +
> +/**
> + * Function type corresponding to `GetSystemTimeAdjustment`.
> + */
> +typedef BOOL (WINAPI *FuncGetSystemTimeAdjustment) (DWORD *, DWORD *, BOOL 
> *);
> +
> +/**
> + * Function type corresponding to `GetSystemTimeAdjustmentPrecise`.
> + */
> +typedef BOOL (WINAPI *FuncGetSystemTimeAdjustmentPrecise) (DWORD64 *, 
> DWORD64 *, BOOL *);
> +
> +/**
> + * Function type corresponding to `GetTickCount64`.
> + */
> +typedef ULONGLONG (WINAPI *FuncGetTickCount64) (VOID);
> +
> +/**
> + * Functions which are looked up at runtime.
> + */
> +typedef struct TimeApi {
> +  /**
> +   * Function `GetSystemTimeAsFileTime` is available since Windows NT 3.51.
> +   */
> +  FuncGetSystemTimeAsFileTime PtrGetSystemTimeAsFileTime;
> +  /**
> +   * Function `GetSystemTimePreciseAsFileTime` is available since Windows 8.
> +   */
> +  FuncGetSystemTimeAsFileTime PtrGetSystemTimePreciseAsFileTime;
> +  /**
> +   * Function `GetSystemTimeAdjustment` is available since Windows NT 3.5.
> +   */
> +  FuncGetSystemTimeAdjustment PtrGetSystemTimeAdjustment;
> +  /**
> +   * Function `GetSystemTimeAdjustmentPrecise` is available since Windows 10.
> +   */
> +  FuncGetSystemTimeAdjustmentPrecise PtrGetSystemTimeAdjustmentPrecise;
> +  /**
> +   * Function `GetTickCount64` is available since Windows Vista.
> +   */
> +  FuncGetTickCount64 PtrGetTickCount64;
> +} TimeApi;
> +
> +static TimeApi WinpthreadsTimeApi;
> +
> +/**
> + * Replacement for `GetSystemTimeAsFileTime`;
> + * a wrapper around `GetSystemTime` and `SystemTimeToFileTime`
> + */
> +static VOID WINAPI WinpthreadsGetSystemTimeAsFileTime (FILETIME *fileTime) {
> +  SYSTEMTIME systemTime;
> +
> +  GetSystemTime (&systemTime);
> +
> +  /**
> +   * If call to `SystemTimeToFileTime` fails, store Unix epoch in `fileTime`.
> +   */
> +  if (unlikely (!SystemTimeToFileTime (&systemTime, fileTime))) {
> +    fileTime->dwHighDateTime = (ULARGE_INTEGER) {.QuadPart = 
> DELTA_EPOCH_IN_100NS}.HighPart;
> +    fileTime->dwLowDateTime  = (ULARGE_INTEGER) {.QuadPart = 
> DELTA_EPOCH_IN_100NS}.LowPart;
> +  }
> +}

This function is used and needed only for 32-bit x86 builds.
So for other platforms this function should be hidden inside
the "#ifdef _M_IX86" to prevent including dead / bloat code.

Same for some functions below.

> +
> +/**
> + * Replacement for `GetSystemTimeAdjustment`;
> + * a simple stab that always fails.
> + */
> +static BOOL WINAPI WinpthreadsGetSystemTimeAdjustment (DWORD *adjustment, 
> DWORD *increment, BOOL *disable) {
> +  SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
> +  return FALSE;
> +  UNREFERENCED_PARAMETER (adjustment);
> +  UNREFERENCED_PARAMETER (increment);
> +  UNREFERENCED_PARAMETER (disable);
> +}
> +
> +/**
> + * Replacement for `WinpthreadsGetSystemTimeAdjustmentPrecise`;
> + * a simple wrapper around `GetSystemTimeAdjustment`.
> + */
> +static BOOL WINAPI WinpthreadsGetSystemTimeAdjustmentPrecise (DWORD64 
> *adjustment, DWORD64 *increment, BOOL *disabled) {
> +  DWORD dwAdjustment;
> +  DWORD dwIncrement;
> +
> +  /**
> +   * Function `GetSystemTimeAdjustment` is available on Win9x systems,
> +   * but it always fails.
> +   *
> +   * It may also point to our `WinpthreadsGetSystemTimeAdjustment` stub.
> +   */
> +  if (!WinpthreadsTimeApi.PtrGetSystemTimeAdjustment (&dwAdjustment, 
> &dwIncrement, disabled)) {
> +    return FALSE;
> +  }
> +
> +  *adjustment = dwAdjustment;
> +  *increment  = dwIncrement;
> +
> +  return TRUE;
> +}
> +
> +/**
> + * Replacement for `GetTickCount64`;
> + * a simple wrapper around `GetTickCount`.
> + */
> +static ULONGLONG WINAPI WinpthreadsGetTickCount64 (VOID) {
> +  return GetTickCount ();
> +}
> +
> +/**
> + * Time-related data.
> + */
> +typedef struct TimeImpl {
> +/**
> + * If set, then `GetSystemTimePreciseAsFileTime` is available.
> + */
> +#define HIGH_RESOLUTION_SYSTEM_TIME 0x01
> +  int Flags;
> +} TimeImpl;
> +
> +static TimeImpl WinpthreadsTimeImpl = {
> +  .Flags = 0,
> +};
> +
> +/**
> + * Check if `bit` is set in `WinpthreadsTimeImpl.Flags`
> + */
> +#define WINPTHREADS_TIME_HAVE(bit) (WinpthreadsTimeImpl.Flags & (bit))
> +
> +void winpthreads_time_init (void) {
> +  HMODULE kernel32 = GetModuleHandleA ("kernel32.dll");
> +
> +  FuncGetSystemTimeAsFileTime        ptrGetSystemTimeAsFileTime        = 
> NULL;
> +  FuncGetSystemTimeAsFileTime        ptrGetSystemTimePreciseAsFileTime = 
> NULL;
> +  FuncGetSystemTimeAdjustment        ptrGetSystemTimeAdjustment        = 
> NULL;
> +  FuncGetSystemTimeAdjustmentPrecise ptrGetSystemTimeAdjustmentPrecise = 
> NULL;
> +  FuncGetTickCount64                 ptrGetTickCount64                 = 
> NULL;
> +
> +  if (kernel32 != NULL) {
> +    ptrGetSystemTimeAsFileTime        = (FuncGetSystemTimeAsFileTime) 
> (UINT_PTR) GetProcAddress (kernel32, "GetSystemTimeAsFileTime");
> +    ptrGetSystemTimePreciseAsFileTime = (FuncGetSystemTimeAsFileTime) 
> (UINT_PTR) GetProcAddress (kernel32, "GetSystemTimePreciseAsFileTime");
> +    ptrGetSystemTimeAdjustment        = (FuncGetSystemTimeAdjustment) 
> (UINT_PTR) GetProcAddress (kernel32, "GetSystemTimeAdjustment");
> +    ptrGetSystemTimeAdjustmentPrecise = (FuncGetSystemTimeAdjustmentPrecise) 
> (UINT_PTR) GetProcAddress (kernel32, "GetSystemTimeAdjustmentPrecise");
> +    ptrGetTickCount64                 = (FuncGetTickCount64) (UINT_PTR) 
> GetProcAddress (kernel32, "GetTickCount64");
> +  }
> +
> +  if (ptrGetSystemTimeAsFileTime != NULL) {
> +    WinpthreadsTimeApi.PtrGetSystemTimeAsFileTime = 
> ptrGetSystemTimeAsFileTime;
> +  } else {
> +    WinpthreadsTimeApi.PtrGetSystemTimeAsFileTime = 
> WinpthreadsGetSystemTimeAsFileTime;
> +  }
> +
> +  if (ptrGetSystemTimePreciseAsFileTime != NULL) {
> +    WinpthreadsTimeImpl.Flags                           |= 
> HIGH_RESOLUTION_SYSTEM_TIME;
> +    WinpthreadsTimeApi.PtrGetSystemTimePreciseAsFileTime = 
> ptrGetSystemTimePreciseAsFileTime;
> +  } else {
> +    WinpthreadsTimeApi.PtrGetSystemTimePreciseAsFileTime = 
> WinpthreadsTimeApi.PtrGetSystemTimeAsFileTime;
> +  }
> +
> +  if (ptrGetSystemTimeAdjustment != NULL) {
> +    WinpthreadsTimeApi.PtrGetSystemTimeAdjustment = 
> ptrGetSystemTimeAdjustment;
> +  } else {
> +    WinpthreadsTimeApi.PtrGetSystemTimeAdjustment = 
> WinpthreadsGetSystemTimeAdjustment;
> +  }
> +
> +  if (ptrGetSystemTimeAdjustmentPrecise != NULL) {
> +    WinpthreadsTimeApi.PtrGetSystemTimeAdjustmentPrecise = 
> ptrGetSystemTimeAdjustmentPrecise;
> +  } else {
> +    WinpthreadsTimeApi.PtrGetSystemTimeAdjustmentPrecise = 
> WinpthreadsGetSystemTimeAdjustmentPrecise;
> +  }
> +
> +  if (ptrGetTickCount64 != NULL) {
> +    WinpthreadsTimeApi.PtrGetTickCount64 = ptrGetTickCount64;
> +  } else {
> +    WinpthreadsTimeApi.PtrGetTickCount64 = WinpthreadsGetTickCount64;
> +  }
> +}
>  
>  
> /*******************************************************************************
>   * Private Functions.


_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to