I assume `getntptimeofday` is provided by mingw-w64 runtime. Maybe author of 
the test did not want to use winpthreads' `clock_gettime` for the test?

Anyway, I attached a patch which replaces calls to `getntptimeofday` with calls 
to `clock_gettime`. I think the only downside of using `clock_gettime` is that 
if it somehow breaks, it will also make this test to fail.

________________________________
From: LIU Hao
Sent: Friday, January 31, 2025 3:07 PM
To: mingw-w64-public@lists.sourceforge.net; Jonathan Yong; Kirill Makurin
Subject: Re: [Mingw-w64-public] winpthreads and MSVC

在 2025-01-30 19:20, Jonathan Yong 写道:
> The 2 patches look OK to me, I'll wait for feed back from the others.

The second patch introduces a private implementation of `getntptimeofday()` 
that does not write
anything into `*tz`. Although all calls to this function in that file pass null 
pointers for its
second parameter, I would like to say it's not very ideal.

Also, it looks like `getntptimeofday()` isn't a standard function...? Does it 
make sense to change
`getntptimeofday(&tp, NULL)` to `clock_gettime(CLOCK_REALTIME, &tp)` which is 
then defined in
winpthreads so must always exist?


--
Best regards,
LIU Hao
From caad147104e7db6787bb7c8cec005d83e1d7946d Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Fri, 31 Jan 2025 15:30:41 +0900
Subject: [PATCH] tests: mingw-w64-libraries/winpthreads/tests/t_nanosleep.c

Use winpthreads' clock_gettime instead of non-standard getntptimeofday.

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 mingw-w64-libraries/winpthreads/tests/t_nanosleep.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/tests/t_nanosleep.c 
b/mingw-w64-libraries/winpthreads/tests/t_nanosleep.c
index 21c0ceb8d..c876dc7b0 100644
--- a/mingw-w64-libraries/winpthreads/tests/t_nanosleep.c
+++ b/mingw-w64-libraries/winpthreads/tests/t_nanosleep.c
@@ -2,14 +2,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
+#include "pthread_time.h"
 
 #include <windows.h>
 
 #define POW10_3                 1000
 #define POW10_6                 1000000
 
-extern int __cdecl getntptimeofday(struct timespec *tp, struct timezone *tz);
-
 __int64 timespec_diff_as_ms(struct timespec *__old, struct timespec *__new)
 {
     return (__new->tv_sec - __old->tv_sec) * POW10_3
@@ -74,9 +73,9 @@ int main(int argc, char *argv[])
     int rc;
     struct timespec tp, tp2, request = { 1, 0 }, remain;
 
-    getntptimeofday(&tp, NULL);
+    clock_gettime(CLOCK_REALTIME, &tp);
     rc = nanosleep(&request, &remain);
-    getntptimeofday(&tp2, NULL);
+    clock_gettime(CLOCK_REALTIME, &tp2);
 
     if (rc != 0) {
         printf("remain: %d.%09d\n", (int) remain.tv_sec, (int) remain.tv_nsec);
-- 
2.46.1.windows.1

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

Reply via email to