You make a good point here.

Move both guarded declaration of `clockid_t` and definition of `WINPTHREAD_API 
` to pthread_compat.h and include it from both pthread.h and pthread_time.h.

How does this look?

- Kirill Makurin

________________________________
From: LIU Hao <lh_mo...@126.com>
Sent: Sunday, February 9, 2025 4:46 PM
To: Kirill Makurin <outlook_b86d28ccc28c7...@outlook.com>; 
mingw-w64-public@lists.sourceforge.net <mingw-w64-public@lists.sourceforge.net>
Subject: Re: [Mingw-w64-public] make sure WINPTHREAD_API is correctly defined 
in pthread_time.h

在 2025-02-09 03:18, Kirill Makurin 写道:
> I think the idea of including pthread_time.h through pthread_compat.h from 
> pthread.h is to make
> `clock_gettime` and other time functions available for MSVC users without 
> explicitly
> including pthread_time.h, which is a non-standard header file.
>
> Declaration of `clockid_t` in pthread_compat.h may be removed since it is 
> also declared in both
> pthread_time.h and pthread.h anyway. Some functions in pthread.h and sched.h 
> have an argument of
> type `pid_t` and this type is not declared in Microsoft header files.
>
> We could move definition of `WINPTHREAD_API ` in pthread.h just above 
> `#include "pthread_compat.h"`
> to not duplicate it in pthread_time.h, but I think it could be useful to make 
> pthread_time.h usable
> on its own.

This makes sense. However, wouldn't a more reasonable choice is to `#include 
"pthread_compat.h"` in
pthread_time.h, not the other way around?



--
Best regards,
LIU Hao
From 541e73d76bb3684e332e547b6cca36f116152c8b Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Sun, 9 Feb 2025 17:21:14 +0900
Subject: [PATCH 1/3] winpthreads: do not include pthread_time.h from
 pthread_compat.h

- remove redundant declaration of clockid_t from pthread_compat.h
- explicitly include pthread_time.h from pthread.h when compiling with MSVC

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 mingw-w64-libraries/winpthreads/include/pthread.h        | 4 ++++
 mingw-w64-libraries/winpthreads/include/pthread_compat.h | 3 ---
 mingw-w64-libraries/winpthreads/include/pthread_time.h   | 3 ++-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/include/pthread.h 
b/mingw-w64-libraries/winpthreads/include/pthread.h
index b1b5c8165..2d5b5b66a 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread.h
@@ -72,6 +72,10 @@
 
 #include "pthread_compat.h"
 
+#ifdef _MSC_VER
+#include "pthread_time.h"
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/mingw-w64-libraries/winpthreads/include/pthread_compat.h 
b/mingw-w64-libraries/winpthreads/include/pthread_compat.h
index 63f5f495f..9ab9dea77 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread_compat.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread_compat.h
@@ -68,14 +68,11 @@
 
 #elif _MSC_VER
 
-#include "pthread_time.h"
-
 #ifdef _WIN64
 typedef __int64 pid_t;
 #else
 typedef int     pid_t;
 #endif
-typedef int clockid_t;
 
 #define WINPTHREADS_INLINE __inline
 #define WINPTHREADS_ATTRIBUTE(X) __declspec X
diff --git a/mingw-w64-libraries/winpthreads/include/pthread_time.h 
b/mingw-w64-libraries/winpthreads/include/pthread_time.h
index eec416844..175618f4d 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread_time.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread_time.h
@@ -25,6 +25,8 @@
 #ifndef WIN_PTHREADS_TIME_H
 #define WIN_PTHREADS_TIME_H
 
+#include "pthread_compat.h"
+
 /* Posix timers are supported */
 #ifndef _POSIX_TIMERS
 #define _POSIX_TIMERS           200809L
@@ -99,4 +101,3 @@ WINPTHREAD_API int __cdecl clock_settime(clockid_t clock_id, 
const struct timesp
 #endif
 
 #endif /* WIN_PTHREADS_TIME_H */
-
-- 
2.46.1.windows.1

From fbd45d2a0be8af68b097640cd20439c78ce76117 Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Sun, 9 Feb 2025 17:26:40 +0900
Subject: [PATCH 2/3] winpthreads: move declaration of clockid_t to
 pthread_compat.h

- remove redundant declarations of clockid_t from pthread.h and pthread_time.h

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 mingw-w64-libraries/winpthreads/include/pthread.h        | 5 -----
 mingw-w64-libraries/winpthreads/include/pthread_compat.h | 5 +++++
 mingw-w64-libraries/winpthreads/include/pthread_time.h   | 5 -----
 3 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/include/pthread.h 
b/mingw-w64-libraries/winpthreads/include/pthread.h
index 2d5b5b66a..f24ad1371 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread.h
@@ -397,11 +397,6 @@ WINPTHREAD_API int 
pthread_condattr_init(pthread_condattr_t *a);
 WINPTHREAD_API int pthread_condattr_getpshared(const pthread_condattr_t *a, 
int *s);
 WINPTHREAD_API int pthread_condattr_setpshared(pthread_condattr_t *a, int s);
 
-#ifndef __clockid_t_defined
-typedef int clockid_t;
-#define __clockid_t_defined 1
-#endif  /* __clockid_t_defined */
-
 WINPTHREAD_API int pthread_condattr_getclock (const pthread_condattr_t *attr,
        clockid_t *clock_id);
 WINPTHREAD_API int pthread_condattr_setclock(pthread_condattr_t *attr,
diff --git a/mingw-w64-libraries/winpthreads/include/pthread_compat.h 
b/mingw-w64-libraries/winpthreads/include/pthread_compat.h
index 9ab9dea77..5fea3c7a2 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread_compat.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread_compat.h
@@ -60,6 +60,11 @@
 #ifndef WIN_PTHREADS_PTHREAD_COMPAT_H
 #define WIN_PTHREADS_PTHREAD_COMPAT_H
 
+#ifndef __clockid_t_defined
+typedef int clockid_t;
+#define __clockid_t_defined 1
+#endif  /* __clockid_t_defined */
+
 #ifdef __GNUC__
 
 #define WINPTHREADS_INLINE inline
diff --git a/mingw-w64-libraries/winpthreads/include/pthread_time.h 
b/mingw-w64-libraries/winpthreads/include/pthread_time.h
index 175618f4d..a01edb081 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread_time.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread_time.h
@@ -47,11 +47,6 @@
 #define _POSIX_THREAD_CPUTIME   200809L
 #endif
 
-#ifndef __clockid_t_defined
-typedef int clockid_t;
-#define __clockid_t_defined 1
-#endif  /* __clockid_t_defined */
-
 #ifndef TIMER_ABSTIME
 #define TIMER_ABSTIME   1
 #endif
-- 
2.46.1.windows.1

From 8a61e9b83023544127b3d77b769f53fb3298fe64 Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Sun, 9 Feb 2025 17:32:17 +0900
Subject: [PATCH 3/3] winpthreads: move definition of WINPTHREAD_API to
 pthread_compat.h

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 mingw-w64-libraries/winpthreads/include/pthread.h  | 14 --------------
 .../winpthreads/include/pthread_compat.h           | 14 ++++++++++++++
 .../winpthreads/include/pthread_time.h             |  9 ---------
 3 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/include/pthread.h 
b/mingw-w64-libraries/winpthreads/include/pthread.h
index f24ad1371..e6a89a95d 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread.h
@@ -87,20 +87,6 @@ extern "C" {
 /* MSB 8-bit major version, 8-bit minor version, 16-bit patch level.  */
 #define __WINPTHREADS_VERSION 0x00050000
 
-#if defined(IN_WINPTHREAD)
-#  if defined(DLL_EXPORT)
-#    define WINPTHREAD_API  __declspec(dllexport)  /* building the DLL  */
-#  else
-#    define WINPTHREAD_API  /* building the static library  */
-#  endif
-#else
-#  if defined(WINPTHREADS_USE_DLLIMPORT)
-#    define WINPTHREAD_API  __declspec(dllimport)  /* user wants explicit 
`dllimport`  */
-#  else
-#    define WINPTHREAD_API  /* the default; auto imported in case of DLL  */
-#  endif
-#endif
-
 /* #define WINPTHREAD_DBG 1 */
 
 /* Compatibility stuff: */
diff --git a/mingw-w64-libraries/winpthreads/include/pthread_compat.h 
b/mingw-w64-libraries/winpthreads/include/pthread_compat.h
index 5fea3c7a2..75d30d4a0 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread_compat.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread_compat.h
@@ -60,6 +60,20 @@
 #ifndef WIN_PTHREADS_PTHREAD_COMPAT_H
 #define WIN_PTHREADS_PTHREAD_COMPAT_H
 
+#if defined(IN_WINPTHREAD)
+#  if defined(DLL_EXPORT)
+#    define WINPTHREAD_API  __declspec(dllexport)  /* building the DLL  */
+#  else
+#    define WINPTHREAD_API  /* building the static library  */
+#  endif
+#else
+#  if defined(WINPTHREADS_USE_DLLIMPORT)
+#    define WINPTHREAD_API  __declspec(dllimport)  /* user wants explicit 
`dllimport`  */
+#  else
+#    define WINPTHREAD_API  /* the default; auto imported in case of DLL  */
+#  endif
+#endif
+
 #ifndef __clockid_t_defined
 typedef int clockid_t;
 #define __clockid_t_defined 1
diff --git a/mingw-w64-libraries/winpthreads/include/pthread_time.h 
b/mingw-w64-libraries/winpthreads/include/pthread_time.h
index a01edb081..72f8446a6 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread_time.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread_time.h
@@ -75,13 +75,6 @@
 extern "C" {
 #endif
 
-/* Make sure we provide default for WINPTHREAD_API, if not defined.  */
-#pragma push_macro("WINPTHREAD_API")
-#ifndef WINPTHREAD_API
-#define WINPTHREAD_API
-#endif
-
-/* These should really be dllimport'ed if using winpthread dll */
 WINPTHREAD_API int __cdecl nanosleep(const struct timespec *request, struct 
timespec *remain);
 
 WINPTHREAD_API int __cdecl clock_nanosleep(clockid_t clock_id, int flags, 
const struct timespec *request, struct timespec *remain);
@@ -89,8 +82,6 @@ WINPTHREAD_API int __cdecl clock_getres(clockid_t clock_id, 
struct timespec *res
 WINPTHREAD_API int __cdecl clock_gettime(clockid_t clock_id, struct timespec 
*tp);
 WINPTHREAD_API int __cdecl clock_settime(clockid_t clock_id, const struct 
timespec *tp);
 
-#pragma pop_macro("WINPTHREAD_API")
-
 #ifdef __cplusplus
 }
 #endif
-- 
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