We already moved `WINPTHREAD_API` and `clockid_t` to pthread_compat.h. Also 
move `mode_t` (from sched.h) to and errno constants (from pthread.h) to 
pthread_compat.h.

sched.h and semaphore.h use `WINPTHREAD_SCHED_API` and `WINPTHREAD_SEMA_API` 
instead of `WINPTHREAD_API`. Include pthread_compat.h and use `WINPTHREAD_API` 
instead.

Remove duplicated code from pthread.h. It contains verbatim code from sched.h. 
Simply include sched.h.

- Kirill Makurin
From 63bc936b8cf13ee302cc4be47f1bb10e7e5a38c2 Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Mon, 10 Feb 2025 17:14:48 +0900
Subject: [PATCH 1/6] winpthreads: move declaration of mode_t to
 pthread_compat.h

Keep all MSVC compatibility stuff in pthread_compat.h.

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

diff --git a/mingw-w64-libraries/winpthreads/include/pthread_compat.h 
b/mingw-w64-libraries/winpthreads/include/pthread_compat.h
index 75d30d4a0..28b2209c0 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread_compat.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread_compat.h
@@ -79,6 +79,11 @@ typedef int clockid_t;
 #define __clockid_t_defined 1
 #endif  /* __clockid_t_defined */
 
+#ifndef _MODE_T_
+#define        _MODE_T_
+typedef unsigned short mode_t;
+#endif
+
 #ifdef __GNUC__
 
 #define WINPTHREADS_INLINE inline
diff --git a/mingw-w64-libraries/winpthreads/include/semaphore.h 
b/mingw-w64-libraries/winpthreads/include/semaphore.h
index 8e3fa6f51..0811761c5 100644
--- a/mingw-w64-libraries/winpthreads/include/semaphore.h
+++ b/mingw-w64-libraries/winpthreads/include/semaphore.h
@@ -23,6 +23,8 @@
 #ifndef WIN_PTHREADS_SEMAPHORE_H
 #define WIN_PTHREADS_SEMAPHORE_H
 
+#include "pthread_compat.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -46,11 +48,6 @@ extern "C" {
 
 #define SEM_VALUE_MAX   INT_MAX
 
-#ifndef _MODE_T_
-#define        _MODE_T_
-typedef unsigned short mode_t;
-#endif
-
 typedef void           *sem_t;
 
 #define SEM_FAILED             NULL
-- 
2.46.1.windows.1

From aa919be47a7ae70c25851621884aecc87dd5e188 Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Mon, 10 Feb 2025 17:17:02 +0900
Subject: [PATCH 2/6] winpthreads: use WINPTHREAD_API instead of
 WINPTHREAD_SCHED_API in sched.h

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 .../winpthreads/include/sched.h               | 24 ++++---------------
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/include/sched.h 
b/mingw-w64-libraries/winpthreads/include/sched.h
index 14e4c87f5..9c6430d96 100644
--- a/mingw-w64-libraries/winpthreads/include/sched.h
+++ b/mingw-w64-libraries/winpthreads/include/sched.h
@@ -51,25 +51,11 @@ struct sched_param {
 extern "C" {
 #endif
 
-#if defined(IN_WINPTHREAD)
-#  if defined(DLL_EXPORT) && !defined(WINPTHREAD_EXPORT_ALL_DEBUG)
-#    define WINPTHREAD_SCHED_API  __declspec(dllexport)  /* building the DLL  
*/
-#  else
-#    define WINPTHREAD_SCHED_API  /* building the static library  */
-#  endif
-#else
-#  if defined(WINPTHREADS_USE_DLLIMPORT)
-#    define WINPTHREAD_SCHED_API  __declspec(dllimport)  /* user wants 
explicit `dllimport`  */
-#  else
-#    define WINPTHREAD_SCHED_API  /* the default; auto imported in case of DLL 
 */
-#  endif
-#endif
-
-WINPTHREAD_SCHED_API int sched_yield(void);
-WINPTHREAD_SCHED_API int sched_get_priority_min(int pol);
-WINPTHREAD_SCHED_API int sched_get_priority_max(int pol);
-WINPTHREAD_SCHED_API int sched_getscheduler(pid_t pid);
-WINPTHREAD_SCHED_API int sched_setscheduler(pid_t pid, int pol, const struct 
sched_param *param);
+WINPTHREAD_API int sched_yield(void);
+WINPTHREAD_API int sched_get_priority_min(int pol);
+WINPTHREAD_API int sched_get_priority_max(int pol);
+WINPTHREAD_API int sched_getscheduler(pid_t pid);
+WINPTHREAD_API int sched_setscheduler(pid_t pid, int pol, const struct 
sched_param *param);
 
 #ifdef __cplusplus
 }
-- 
2.46.1.windows.1

From 5b1215c19fb66fd18adc6e430c67cb23ef59e32d Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Mon, 10 Feb 2025 17:20:03 +0900
Subject: [PATCH 3/6] winpthreads: use WINPTHREAD_API instead of
 WINPTHREAD_SEMA_API in semaphore.h

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 .../winpthreads/include/semaphore.h           | 36 ++++++-------------
 1 file changed, 11 insertions(+), 25 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/include/semaphore.h 
b/mingw-w64-libraries/winpthreads/include/semaphore.h
index 0811761c5..50630ea5e 100644
--- a/mingw-w64-libraries/winpthreads/include/semaphore.h
+++ b/mingw-w64-libraries/winpthreads/include/semaphore.h
@@ -29,20 +29,6 @@
 extern "C" {
 #endif
 
-#if defined(IN_WINPTHREAD)
-#  if defined(DLL_EXPORT) && !defined(WINPTHREAD_EXPORT_ALL_DEBUG)
-#    define WINPTHREAD_SEMA_API  __declspec(dllexport)  /* building the DLL  */
-#  else
-#    define WINPTHREAD_SEMA_API  /* building the static library  */
-#  endif
-#else
-#  if defined(WINPTHREADS_USE_DLLIMPORT)
-#    define WINPTHREAD_SEMA_API  __declspec(dllimport)  /* user wants explicit 
`dllimport`  */
-#  else
-#    define WINPTHREAD_SEMA_API  /* the default; auto imported in case of DLL  
*/
-#  endif
-#endif
-
 /* Set this to 0 to disable it */
 #define USE_SEM_CriticalSection_SpinCount      100
 
@@ -52,28 +38,28 @@ typedef void                *sem_t;
 
 #define SEM_FAILED             NULL
 
-WINPTHREAD_SEMA_API int sem_init(sem_t * sem, int pshared, unsigned int value);
+WINPTHREAD_API int sem_init(sem_t * sem, int pshared, unsigned int value);
 
-WINPTHREAD_SEMA_API int sem_destroy(sem_t *sem);
+WINPTHREAD_API int sem_destroy(sem_t *sem);
 
-WINPTHREAD_SEMA_API int sem_trywait(sem_t *sem);
+WINPTHREAD_API int sem_trywait(sem_t *sem);
 
-WINPTHREAD_SEMA_API int sem_wait(sem_t *sem);
+WINPTHREAD_API int sem_wait(sem_t *sem);
 
-WINPTHREAD_SEMA_API int sem_timedwait(sem_t * sem, const struct timespec *t);
+WINPTHREAD_API int sem_timedwait(sem_t * sem, const struct timespec *t);
 
-WINPTHREAD_SEMA_API int sem_post(sem_t *sem);
+WINPTHREAD_API int sem_post(sem_t *sem);
 
-WINPTHREAD_SEMA_API int sem_post_multiple(sem_t *sem, int count);
+WINPTHREAD_API int sem_post_multiple(sem_t *sem, int count);
 
 /* yes, it returns a semaphore (or SEM_FAILED) */
-WINPTHREAD_SEMA_API sem_t * sem_open(const char * name, int oflag, mode_t 
mode, unsigned int value);
+WINPTHREAD_API sem_t * sem_open(const char * name, int oflag, mode_t mode, 
unsigned int value);
 
-WINPTHREAD_SEMA_API int sem_close(sem_t * sem);
+WINPTHREAD_API int sem_close(sem_t * sem);
 
-WINPTHREAD_SEMA_API int sem_unlink(const char * name);
+WINPTHREAD_API int sem_unlink(const char * name);
 
-WINPTHREAD_SEMA_API int sem_getvalue(sem_t * sem, int * sval);
+WINPTHREAD_API int sem_getvalue(sem_t * sem, int * sval);
 
 #ifdef __cplusplus
 }
-- 
2.46.1.windows.1

From 5adf6ffdbb74e9e0336c89da2fa99d295c79bc67 Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Mon, 10 Feb 2025 17:24:34 +0900
Subject: [PATCH 4/6] winpthreads: move includes under header guard in sched.h

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 mingw-w64-libraries/winpthreads/include/sched.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/include/sched.h 
b/mingw-w64-libraries/winpthreads/include/sched.h
index 9c6430d96..76c8d1d44 100644
--- a/mingw-w64-libraries/winpthreads/include/sched.h
+++ b/mingw-w64-libraries/winpthreads/include/sched.h
@@ -19,6 +19,8 @@
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    DEALINGS IN THE SOFTWARE.
 */
+#ifndef WIN_PTHREADS_SCHED_H
+#define WIN_PTHREADS_SCHED_H
 
 #include <stddef.h>
 #include <errno.h>
@@ -32,9 +34,6 @@
 
 #include "pthread_compat.h"
 
-#ifndef WIN_PTHREADS_SCHED_H
-#define WIN_PTHREADS_SCHED_H
-
 #ifndef SCHED_OTHER
 /* Some POSIX realtime extensions, mostly stubbed */
 #define SCHED_OTHER     0
-- 
2.46.1.windows.1

From cb5374ffb6a36f608ae822716a7666f4ba44f985 Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Mon, 10 Feb 2025 17:29:12 +0900
Subject: [PATCH 5/6] winpthreads: remove duplicated code from pthread.h

pthread.h contains most of the contents of sched.h verbatim.
Remove it and include sched.h instead.

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 .../winpthreads/include/pthread.h             | 21 +------------------
 .../winpthreads/include/sched.h               |  3 ---
 2 files changed, 1 insertion(+), 23 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/include/pthread.h 
b/mingw-w64-libraries/winpthreads/include/pthread.h
index e6a89a95d..8eb8e6d0c 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread.h
@@ -71,6 +71,7 @@
 #include <sys/timeb.h>
 
 #include "pthread_compat.h"
+#include "sched.h"
 
 #ifdef _MSC_VER
 #include "pthread_time.h"
@@ -224,26 +225,6 @@ struct _pthread_cleanup
         if ((E)) _pthread_cup.func((pthread_once_t *)_pthread_cup.arg); \
     } while (0)
 
-#ifndef SCHED_OTHER
-/* Some POSIX realtime extensions, mostly stubbed */
-#define SCHED_OTHER     0
-#define SCHED_FIFO      1
-#define SCHED_RR        2
-#define SCHED_MIN       SCHED_OTHER
-#define SCHED_MAX       SCHED_RR
-
-struct sched_param {
-  int sched_priority;
-};
-
-WINPTHREAD_API int sched_yield(void);
-WINPTHREAD_API int sched_get_priority_min(int pol);
-WINPTHREAD_API int sched_get_priority_max(int pol);
-WINPTHREAD_API int sched_getscheduler(pid_t pid);
-WINPTHREAD_API int sched_setscheduler(pid_t pid, int pol, const struct 
sched_param *param);
-
-#endif
-
 typedef struct pthread_attr_t pthread_attr_t;
 struct pthread_attr_t
 {
diff --git a/mingw-w64-libraries/winpthreads/include/sched.h 
b/mingw-w64-libraries/winpthreads/include/sched.h
index 76c8d1d44..758d81891 100644
--- a/mingw-w64-libraries/winpthreads/include/sched.h
+++ b/mingw-w64-libraries/winpthreads/include/sched.h
@@ -34,7 +34,6 @@
 
 #include "pthread_compat.h"
 
-#ifndef SCHED_OTHER
 /* Some POSIX realtime extensions, mostly stubbed */
 #define SCHED_OTHER     0
 #define SCHED_FIFO      1
@@ -60,8 +59,6 @@ WINPTHREAD_API int sched_setscheduler(pid_t pid, int pol, 
const struct sched_par
 }
 #endif
 
-#endif
-
 #ifndef sched_rr_get_interval
 #define sched_rr_get_interval(_p, _i) \
   ( errno = ENOTSUP, (int) -1 )
-- 
2.46.1.windows.1

From ae6fe9cfc1cada6073a49ce5d988d159a3f120d2 Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Mon, 10 Feb 2025 17:33:33 +0900
Subject: [PATCH 6/6] winpthreads: move definitions of error codes to
 pthread_compat.h

Keep compatibility stuff in pthread_compat.h

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

diff --git a/mingw-w64-libraries/winpthreads/include/pthread.h 
b/mingw-w64-libraries/winpthreads/include/pthread.h
index 8eb8e6d0c..36b2f6cae 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread.h
@@ -93,17 +93,6 @@ extern "C" {
 /* Compatibility stuff: */
 #define RWLS_PER_THREAD                                                8
 
-/* Error-codes.  */
-#ifndef ETIMEDOUT
-#define ETIMEDOUT      138
-#endif
-#ifndef ENOTSUP
-#define ENOTSUP                129
-#endif
-#ifndef EWOULDBLOCK
-#define EWOULDBLOCK    140
-#endif
-
 /* pthread specific defines.  */
 
 #define PTHREAD_CANCEL_DISABLE 0
diff --git a/mingw-w64-libraries/winpthreads/include/pthread_compat.h 
b/mingw-w64-libraries/winpthreads/include/pthread_compat.h
index 28b2209c0..96118722d 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread_compat.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread_compat.h
@@ -84,6 +84,17 @@ typedef int clockid_t;
 typedef unsigned short mode_t;
 #endif
 
+/* Error-codes.  */
+#ifndef ETIMEDOUT
+#define ETIMEDOUT      138
+#endif
+#ifndef ENOTSUP
+#define ENOTSUP                129
+#endif
+#ifndef EWOULDBLOCK
+#define EWOULDBLOCK    140
+#endif
+
 #ifdef __GNUC__
 
 #define WINPTHREADS_INLINE inline
-- 
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