This is the updated patch series. Some patches have been reordered and new patches have been added. Some patches have been updated.
New patches are: 0002.txt-0005.txt and 0010.txt. 0002.txt: Get rid of now unused `WINPTHREAD_DBG` macro. All code guarded by this macro has been removed. In addition, private definition of `assert` and (unused) `fixme` macros in misc.h has also been removed. For affected source files, assert.h has been included. 0003.txt: Internal header file `winpthread_internal.h` has been removed. This file declared two functions: `__pth_gpointer_locked` and `pthread_delay_np_ms`. The `__pth_gpointer_locked` is also declared in thread.h, all its users already had thread.h included. Since `pthread_delay_np_ms` is defined in thread.c, its declaration has been moved to thread.h. An underscore has been prepended to the name of this function to explicitly mark it as internal. 0004.txt: Remove ref.c and ref.h. They are empty. 0005.txt: Move definition of `WIN32_LEAN_AND_MEAN` from Makefile.am to source files. I took freedom to group and reorder includes in source file and internal header files. 0010.txt: Silence `-Wprio-ctor-dtor` warning in misc.c which results from `__attribute__((constructor(0)))`. Changes: New macro `WINPTHREADS_TIME_BITS` was added to pthread_compat.h which will expand into either `32` or `64` depending on state of ` _USE_32BIT_TIME_T` and `_TIME_BITS` macros. `SIZEOF_TIME_T` is no longer used. Few macros named `WINPTHREAD_*_DECL` were added in pthread_compat.h. They are used to conditionally declare some functions either as external (with __declspec(dllexport) in case when building DLL) or static inline (for client code). Function definitions in header files now also used to provide external version when corresponding source file is compiled. - Kirill Makurin
From 04b76b913bdf1ec0b27ef7c6e9525cf46ddc8ad4 Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Tue, 22 Apr 2025 09:20:39 +0900 Subject: [PATCH 01/11] winpthreads: fix `make dist` libwinpthread_la_SOURCES lists header files which are no longer present in the source tree. This causes `make dist` to fail. Explicitly add `build-aux/windres-rc` to EXTRA_DIST. Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- mingw-w64-libraries/winpthreads/Makefile.am | 35 ++++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/mingw-w64-libraries/winpthreads/Makefile.am b/mingw-w64-libraries/winpthreads/Makefile.am index 6b0338af0..c3f0c8d68 100644 --- a/mingw-w64-libraries/winpthreads/Makefile.am +++ b/mingw-w64-libraries/winpthreads/Makefile.am @@ -6,13 +6,34 @@ ACLOCAL_AMFLAGS = -I m4 lib_LTLIBRARIES = libwinpthread.la -include_HEADERS = include/pthread.h include/sched.h include/semaphore.h include/pthread_unistd.h include/pthread_time.h include/pthread_compat.h include/pthread_signal.h +include_HEADERS = \ + include/pthread.h \ + include/pthread_compat.h \ + include/pthread_signal.h \ + include/pthread_time.h \ + include/pthread_unistd.h \ + include/sched.h \ + include/semaphore.h + +libwinpthread_la_SOURCES = \ + src/barrier.c src/barrier.h \ + src/clock.c \ + src/cond.c src/cond.h \ + src/misc.c src/misc.h \ + src/mutex.c \ + src/nanosleep.c \ + src/ref.c src/ref.h \ + src/rwlock.c src/rwlock.h \ + src/sem.c src/sem.h \ + src/spinlock.c \ + src/sched.c \ + src/thread.c src/thread.h \ + src/winpthread_internal.h \ + src/wpth_ver.h \ + src/version.rc + libwinpthread_la_CPPFLAGS = -I$(srcdir)/include -DIN_WINPTHREAD -DWINPTHREAD_DBG=1 libwinpthread_la_LDFLAGS = -no-undefined -version-info 1:0:0 -libwinpthread_la_SOURCES = \ - src/barrier.h src/cond.h src/misc.h src/mutex.h src/rwlock.h src/spinlock.h src/thread.h src/ref.h src/sem.h src/wpth_ver.h \ - src/barrier.c src/cond.c src/misc.c src/mutex.c src/rwlock.c src/spinlock.c src/thread.c src/ref.c src/sem.c src/sched.c \ - src/winpthread_internal.h src/clock.c src/nanosleep.c src/version.rc if MSVC AM_CFLAGS += -nologo @@ -29,6 +50,10 @@ fakelib_libgcc_s_a_SOURCES = fakelib_libgcc_eh_a_SOURCES = endif +# Extra files to add into archive with `make dist` +EXTRA_DIST = \ + build-aux/windres-rc + # Tell libtool how to use the resource compiler .rc.lo: $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --tag=RC --mode=compile $(RC) $(RCFLAGS) -i $< -o $@ -- 2.46.1.windows.1
From 1b409a5a62d941fb49e5d054a75bacf7ee8bcad8 Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Tue, 22 Apr 2025 10:46:11 +0900 Subject: [PATCH 02/11] winpthreads: remove WINPTHREAD_DBG macro The `WINPTHREAD_DBG` macro guards internal functions which are no longer used. Code guarded by this macro has been removed. This commit also removed private definition of `assert` macro from misc.h. assert.h has been included from affected source files. Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- mingw-w64-libraries/winpthreads/Makefile.am | 2 +- .../winpthreads/include/pthread.h | 2 - mingw-w64-libraries/winpthreads/src/barrier.c | 13 +++-- mingw-w64-libraries/winpthreads/src/cond.c | 36 ++------------ mingw-w64-libraries/winpthreads/src/cond.h | 6 +-- mingw-w64-libraries/winpthreads/src/misc.h | 29 ------------ mingw-w64-libraries/winpthreads/src/rwlock.c | 47 +++++-------------- mingw-w64-libraries/winpthreads/src/rwlock.h | 3 -- mingw-w64-libraries/winpthreads/src/thread.c | 38 ++------------- mingw-w64-libraries/winpthreads/src/thread.h | 4 -- 10 files changed, 28 insertions(+), 152 deletions(-) diff --git a/mingw-w64-libraries/winpthreads/Makefile.am b/mingw-w64-libraries/winpthreads/Makefile.am index c3f0c8d68..cf78f4cc9 100644 --- a/mingw-w64-libraries/winpthreads/Makefile.am +++ b/mingw-w64-libraries/winpthreads/Makefile.am @@ -32,7 +32,7 @@ libwinpthread_la_SOURCES = \ src/wpth_ver.h \ src/version.rc -libwinpthread_la_CPPFLAGS = -I$(srcdir)/include -DIN_WINPTHREAD -DWINPTHREAD_DBG=1 +libwinpthread_la_CPPFLAGS = -I$(srcdir)/include -DIN_WINPTHREAD libwinpthread_la_LDFLAGS = -no-undefined -version-info 1:0:0 if MSVC diff --git a/mingw-w64-libraries/winpthreads/include/pthread.h b/mingw-w64-libraries/winpthreads/include/pthread.h index 4a5822427..7f0be9ea4 100644 --- a/mingw-w64-libraries/winpthreads/include/pthread.h +++ b/mingw-w64-libraries/winpthreads/include/pthread.h @@ -86,8 +86,6 @@ extern "C" { /* MSB 8-bit major version, 8-bit minor version, 16-bit patch level. */ #define __WINPTHREADS_VERSION 0x00050000 -/* #define WINPTHREAD_DBG 1 */ - /* Compatibility stuff: */ #define RWLS_PER_THREAD 8 diff --git a/mingw-w64-libraries/winpthreads/src/barrier.c b/mingw-w64-libraries/winpthreads/src/barrier.c index e973aaaa7..f3b5c4664 100644 --- a/mingw-w64-libraries/winpthreads/src/barrier.c +++ b/mingw-w64-libraries/winpthreads/src/barrier.c @@ -20,12 +20,13 @@ DEALINGS IN THE SOFTWARE. */ +#include <assert.h> #include <windows.h> #include <stdio.h> #include <malloc.h> #include "pthread.h" #include "barrier.h" -#include "ref.h" +#include "ref.h" #include "misc.h" static pthread_spinlock_t barrier_global = PTHREAD_SPINLOCK_INITIALIZER; @@ -34,9 +35,7 @@ static WINPTHREADS_ATTRIBUTE((noinline)) int barrier_unref(volatile pthread_barrier_t *barrier, int res) { pthread_spin_lock(&barrier_global); -#ifdef WINPTHREAD_DBG assert((((barrier_t *)*barrier)->valid == LIFE_BARRIER) && (((barrier_t *)*barrier)->busy > 0)); -#endif ((barrier_t *)*barrier)->busy -= 1; pthread_spin_unlock(&barrier_global); return res; @@ -64,7 +63,7 @@ barrier_ref_destroy(volatile pthread_barrier_t *barrier, pthread_barrier_t *bDes *bDestroy = NULL; pthread_spin_lock(&barrier_global); - + if (!barrier || !*barrier || ((barrier_t *)*barrier)->valid != LIFE_BARRIER) r = EINVAL; else { barrier_t *b_ = (barrier_t *)*barrier; @@ -92,15 +91,15 @@ int pthread_barrier_destroy(pthread_barrier_t *b_) pthread_barrier_t bDestroy; barrier_t *b; int r; - + while ((r = barrier_ref_destroy(b_,&bDestroy)) == EBUSY) Sleep(0); - + if (r) return r; b = (barrier_t *)bDestroy; - + pthread_mutex_lock(&b->m); if (sem_destroy(&b->sems[0]) != 0) diff --git a/mingw-w64-libraries/winpthreads/src/cond.c b/mingw-w64-libraries/winpthreads/src/cond.c index 813648f0e..cad966ee0 100644 --- a/mingw-w64-libraries/winpthreads/src/cond.c +++ b/mingw-w64-libraries/winpthreads/src/cond.c @@ -52,41 +52,13 @@ typedef struct sCondWaitHelper { int do_sema_b_wait_intern (HANDLE sema, int nointerrupt, DWORD timeout); -#ifdef WINPTHREAD_DBG -static int print_state = 0; -static FILE *fo; -void cond_print_set(int state, FILE *f) -{ - if (f) fo = f; - if (!fo) fo = stdout; - print_state = state; -} - -void cond_print(volatile pthread_cond_t *c, char *txt) -{ - if (!print_state) return; - cond_t *c_ = (cond_t *)*c; - if (c_ == NULL) { - fprintf(fo,"C%p %lu %s\n",(void *)*c,GetCurrentThreadId(),txt); - } else { - fprintf(fo,"C%p %lu V=%0X w=%ld %s\n", - (void *)*c, - GetCurrentThreadId(), - (int)c_->valid, - c_->waiters_count_, - txt - ); - } -} -#endif - static pthread_spinlock_t cond_locked = PTHREAD_SPINLOCK_INITIALIZER; static int cond_static_init (pthread_cond_t *c) { int r = 0; - + pthread_spin_lock (&cond_locked); if (c == NULL) r = EINVAL; @@ -218,7 +190,7 @@ pthread_cond_init (pthread_cond_t *c, const pthread_condattr_t *a) _c->sema_b = CreateSemaphore (NULL, /* no security */ 0, /* initially 0 */ 0x7fffffff, /* max count */ - NULL); + NULL); if (_c->sema_q == NULL || _c->sema_b == NULL) { if (_c->sema_q != NULL) CloseHandle (_c->sema_q); @@ -356,7 +328,7 @@ pthread_cond_broadcast (pthread_cond_t *c) { cond_t *_c; int r; - int relCnt = 0; + int relCnt = 0; if (!c || !*c) return EINVAL; @@ -751,5 +723,5 @@ do_sema_b_release(HANDLE sema, LONG count,CRITICAL_SECTION *cs, LONG *val) } InterlockedExchangeAdd(val, -count); LeaveCriticalSection(cs); - return EINVAL; + return EINVAL; } diff --git a/mingw-w64-libraries/winpthreads/src/cond.h b/mingw-w64-libraries/winpthreads/src/cond.h index 5e869e957..9eda22369 100644 --- a/mingw-w64-libraries/winpthreads/src/cond.h +++ b/mingw-w64-libraries/winpthreads/src/cond.h @@ -40,7 +40,7 @@ typedef struct cond_t cond_t; struct cond_t { - unsigned int valid; + unsigned int valid; int busy; LONG waiters_count_; /* Number of waiting threads. */ LONG waiters_count_unblock_; /* Number of waiting threads whitch can be unblocked. */ @@ -56,8 +56,4 @@ struct cond_t became signaled. */ }; -void cond_print_set(int state, FILE *f); - -void cond_print(volatile pthread_cond_t *c, char *txt); - #endif diff --git a/mingw-w64-libraries/winpthreads/src/misc.h b/mingw-w64-libraries/winpthreads/src/misc.h index a853dd085..f01f1fb55 100644 --- a/mingw-w64-libraries/winpthreads/src/misc.h +++ b/mingw-w64-libraries/winpthreads/src/misc.h @@ -25,35 +25,6 @@ #include "pthread_compat.h" -#ifndef assert - -#ifndef ASSERT_TRACE -# define ASSERT_TRACE 0 -#else -# undef ASSERT_TRACE -# define ASSERT_TRACE 0 -#endif - -# define assert(e) \ - ((e) ? ((ASSERT_TRACE) ? fprintf(stderr, \ - "Assertion succeeded: (%s), file %s, line %d\n", \ - #e, __FILE__, (int) __LINE__), \ - fflush(stderr) : \ - 0) : \ - (fprintf(stderr, "Assertion failed: (%s), file %s, line %d\n", \ - #e, __FILE__, (int) __LINE__), exit(1), 0)) - -# define fixme(e) \ - ((e) ? ((ASSERT_TRACE) ? fprintf(stderr, \ - "Assertion succeeded: (%s), file %s, line %d\n", \ - #e, __FILE__, (int) __LINE__), \ - fflush(stderr) : \ - 0) : \ - (fprintf(stderr, "FIXME: (%s), file %s, line %d\n", \ - #e, __FILE__, (int) __LINE__), 0, 0)) - -#endif - #define PTR2INT(x) ((int)(uintptr_t)(x)) #if SIZE_MAX>UINT_MAX diff --git a/mingw-w64-libraries/winpthreads/src/rwlock.c b/mingw-w64-libraries/winpthreads/src/rwlock.c index 76669dff1..7a4e5839d 100644 --- a/mingw-w64-libraries/winpthreads/src/rwlock.c +++ b/mingw-w64-libraries/winpthreads/src/rwlock.c @@ -20,6 +20,7 @@ DEALINGS IN THE SOFTWARE. */ +#include <assert.h> #include <windows.h> #include <stdio.h> #include <malloc.h> @@ -36,9 +37,7 @@ static WINPTHREADS_ATTRIBUTE((noinline)) int rwlock_static_init(pthread_rwlock_t static WINPTHREADS_ATTRIBUTE((noinline)) int rwl_unref(volatile pthread_rwlock_t *rwl, int res) { pthread_spin_lock(&rwl_global); -#ifdef WINPTHREAD_DBG assert((((rwlock_t *)*rwl)->valid == LIFE_RWLOCK) && (((rwlock_t *)*rwl)->busy > 0)); -#endif ((rwlock_t *)*rwl)->busy--; pthread_spin_unlock(&rwl_global); return res; @@ -87,7 +86,7 @@ static WINPTHREADS_ATTRIBUTE((noinline)) int rwl_ref_destroy(pthread_rwlock_t *r *rDestroy = (pthread_rwlock_t)NULL; pthread_spin_lock(&rwl_global); - + if (!rwl || !*rwl) r = EINVAL; else { rwlock_t *r_ = (rwlock_t *)*rwl; @@ -128,30 +127,6 @@ static int rwlock_free_both_locks(rwlock_t *rwlock, int last_fail) return ret; } -#ifdef WINPTHREAD_DBG -static int print_state = 0; -void rwl_print_set(int state) -{ - print_state = state; -} - -void rwl_print(volatile pthread_rwlock_t *rwl, char *txt) -{ - if (!print_state) return; - rwlock_t *r = (rwlock_t *)*rwl; - if (r == NULL) { - printf("RWL%p %lu %s\n",(void *)*rwl,GetCurrentThreadId(),txt); - } else { - printf("RWL%p %lu V=%0X B=%d r=%ld w=%ld L=%p %s\n", - (void *)*rwl, - GetCurrentThreadId(), - (int)r->valid, - (int)r->busy, - 0L,0L,NULL,txt); - } -} -#endif - static pthread_spinlock_t cond_locked = PTHREAD_SPINLOCK_INITIALIZER; static WINPTHREADS_ATTRIBUTE((noinline)) int rwlock_static_init(pthread_rwlock_t *rw) @@ -165,7 +140,7 @@ static WINPTHREADS_ATTRIBUTE((noinline)) int rwlock_static_init(pthread_rwlock_t } r = pthread_rwlock_init (rw, NULL); pthread_spin_unlock(&cond_locked); - + return r; } @@ -178,7 +153,7 @@ int pthread_rwlock_init (pthread_rwlock_t *rwlock_, const pthread_rwlockattr_t * return EINVAL; *rwlock_ = (pthread_rwlock_t)NULL; if ((rwlock = calloc(1, sizeof(*rwlock))) == NULL) - return ENOMEM; + return ENOMEM; rwlock->valid = DEAD_RWLOCK; rwlock->nex_count = rwlock->nsh_count = rwlock->ncomplete = 0; @@ -203,18 +178,18 @@ int pthread_rwlock_init (pthread_rwlock_t *rwlock_, const pthread_rwlockattr_t * rwlock->valid = LIFE_RWLOCK; *rwlock_ = (pthread_rwlock_t)rwlock; return r; -} +} int pthread_rwlock_destroy (pthread_rwlock_t *rwlock_) { rwlock_t *rwlock; pthread_rwlock_t rDestroy; int r, r2; - + pthread_spin_lock(&cond_locked); r = rwl_ref_destroy(rwlock_,&rDestroy); pthread_spin_unlock(&cond_locked); - + if(r) return r; if(!rDestroy) return 0; /* destroyed a (still) static initialized rwl */ @@ -245,7 +220,7 @@ int pthread_rwlock_destroy (pthread_rwlock_t *rwlock_) rwlock->valid = DEAD_RWLOCK; free((void *)rDestroy); return 0; -} +} int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock_) { @@ -340,7 +315,7 @@ int pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock_) } ret = pthread_mutex_unlock(&rwlock->mex); return rwl_unref(rwlock_,ret); -} +} int pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock_) { @@ -378,7 +353,7 @@ int pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock_) } rwlock->nex_count = 1; return rwl_unref(rwlock_, 0); -} +} int pthread_rwlock_unlock (pthread_rwlock_t *rwlock_) { @@ -409,7 +384,7 @@ int pthread_rwlock_unlock (pthread_rwlock_t *rwlock_) ret = rwlock_free_both_locks(rwlock, 0); } return rwl_unref(rwlock_, ret); -} +} static void st_cancelwrite (void *arg) { diff --git a/mingw-w64-libraries/winpthreads/src/rwlock.h b/mingw-w64-libraries/winpthreads/src/rwlock.h index 2d640faa9..8faf12b9f 100644 --- a/mingw-w64-libraries/winpthreads/src/rwlock.h +++ b/mingw-w64-libraries/winpthreads/src/rwlock.h @@ -43,7 +43,4 @@ struct rwlock_t { #define RWL_SET 0x01 #define RWL_TRY 0x02 -void rwl_print(volatile pthread_rwlock_t *rwl, char *txt); -void rwl_print_set(int state); - #endif diff --git a/mingw-w64-libraries/winpthreads/src/thread.c b/mingw-w64-libraries/winpthreads/src/thread.c index 742a02238..a13e5554d 100644 --- a/mingw-w64-libraries/winpthreads/src/thread.c +++ b/mingw-w64-libraries/winpthreads/src/thread.c @@ -537,34 +537,6 @@ WINPTHREADS_ATTRIBUTE((WINPTHREADS_SECTION(".CRT$XLF"))) extern const PIMAGE_TLS_CALLBACK __xl_f; const PIMAGE_TLS_CALLBACK __xl_f = __dyn_tls_pthread; - -#ifdef WINPTHREAD_DBG -static int print_state = 0; -void thread_print_set (int state) -{ - print_state = state; -} - -void -thread_print (volatile pthread_t t, char *txt) -{ - if (!print_state) - return; - if (!t) - printf("T%p %lu %s\n",NULL,GetCurrentThreadId(),txt); - else - { - printf("T%p %lu V=%0X H=%p %s\n", - (void *) __pth_gpointer_locked (t), - GetCurrentThreadId(), - (__pth_gpointer_locked (t))->valid, - (__pth_gpointer_locked (t))->h, - txt - ); - } -} -#endif - /* Internal collect-once structure. */ typedef struct collect_once_t { pthread_once_t *o; @@ -725,7 +697,7 @@ pthread_delay_np_ms (DWORD to) /* Compatibility routine for pthread-win32. It returns the amount of available CPUs on system. */ int -pthread_num_processors_np(void) +pthread_num_processors_np(void) { int r = 0; DWORD_PTR ProcessAffinityMask, SystemAffinityMask; @@ -742,10 +714,10 @@ pthread_num_processors_np(void) /* Compatiblity routine for pthread-win32. Allows to set amount of used CPUs for process. */ int -pthread_set_num_processors_np(int n) +pthread_set_num_processors_np(int n) { DWORD_PTR ProcessAffinityMask, ProcessNewAffinityMask = 0, SystemAffinityMask; - int r = 0; + int r = 0; /* need at least 1 */ n = n ? n : 1; if (GetProcessAffinityMask (GetCurrentProcess (), &ProcessAffinityMask, &SystemAffinityMask)) @@ -878,7 +850,7 @@ pthread_key_delete (pthread_key_t key) return EINVAL; pthread_rwlock_wrlock (&_pthread_key_lock); - + _pthread_key_dest[key] = NULL; /* Start next search from our location */ @@ -910,7 +882,7 @@ pthread_setspecific (pthread_key_t key, const void *value) { DWORD lasterr = GetLastError (); _pthread_v *t = __pthread_self_lite (); - + pthread_spin_lock (&t->spin_keys); if (key >= t->keymax) diff --git a/mingw-w64-libraries/winpthreads/src/thread.h b/mingw-w64-libraries/winpthreads/src/thread.h index 1603bae58..97bfda77a 100644 --- a/mingw-w64-libraries/winpthreads/src/thread.h +++ b/mingw-w64-libraries/winpthreads/src/thread.h @@ -69,10 +69,6 @@ typedef struct __pthread_idlist { int _pthread_tryjoin(pthread_t t, void **res); void _pthread_setnobreak(int); -#ifdef WINPTHREAD_DBG -void thread_print_set(int state); -void thread_print(volatile pthread_t t, char *txt); -#endif int __pthread_shallcancel(void); WINPTHREAD_API struct _pthread_v * __pth_gpointer_locked (pthread_t id); -- 2.46.1.windows.1
From cd0c2eef1aea17d961be2e9b53de910828590e40 Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Tue, 22 Apr 2025 10:54:57 +0900 Subject: [PATCH 03/11] winpthreads: remove winpthread_internal.h This header file declares two internal functions: - __pth_gpointer_locked, which is also declared in thread.h - pthread_delay_np_ms, which is defined in thread.c Declaration of `pthread_delay_np_ms` has been moved to thread.h so that it is declared in header file associtated with source file it is defined in. `pthread_delay_np_ms` has been renamed to `_pthread_delay_np_ms` to make it explicit that this function is internal. Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- mingw-w64-libraries/winpthreads/Makefile.am | 1 - mingw-w64-libraries/winpthreads/src/cond.c | 3 +-- .../winpthreads/src/nanosleep.c | 4 +-- mingw-w64-libraries/winpthreads/src/thread.c | 5 +--- mingw-w64-libraries/winpthreads/src/thread.h | 1 + .../winpthreads/src/winpthread_internal.h | 27 ------------------- 6 files changed, 5 insertions(+), 36 deletions(-) delete mode 100644 mingw-w64-libraries/winpthreads/src/winpthread_internal.h diff --git a/mingw-w64-libraries/winpthreads/Makefile.am b/mingw-w64-libraries/winpthreads/Makefile.am index cf78f4cc9..8fbdda963 100644 --- a/mingw-w64-libraries/winpthreads/Makefile.am +++ b/mingw-w64-libraries/winpthreads/Makefile.am @@ -28,7 +28,6 @@ libwinpthread_la_SOURCES = \ src/spinlock.c \ src/sched.c \ src/thread.c src/thread.h \ - src/winpthread_internal.h \ src/wpth_ver.h \ src/version.rc diff --git a/mingw-w64-libraries/winpthreads/src/cond.c b/mingw-w64-libraries/winpthreads/src/cond.c index cad966ee0..b0ff65bea 100644 --- a/mingw-w64-libraries/winpthreads/src/cond.c +++ b/mingw-w64-libraries/winpthreads/src/cond.c @@ -34,7 +34,6 @@ #include "cond.h" #include "thread.h" #include "misc.h" -#include "winpthread_internal.h" #include "pthread_compat.h" @@ -135,7 +134,7 @@ __pthread_clock_nanosleep (clockid_t clock_id, int flags, const struct timespec { dw = (DWORD) (delay >= 99999ULL ? 99999ULL : delay); tick = _pthread_time_in_ms (); - pthread_delay_np_ms (dw); + _pthread_delay_np_ms (dw); tick2 = _pthread_time_in_ms (); tick2 -= tick; if (tick2 >= delay) diff --git a/mingw-w64-libraries/winpthreads/src/nanosleep.c b/mingw-w64-libraries/winpthreads/src/nanosleep.c index 0cce4492e..5ee5ef60d 100644 --- a/mingw-w64-libraries/winpthreads/src/nanosleep.c +++ b/mingw-w64-libraries/winpthreads/src/nanosleep.c @@ -9,7 +9,7 @@ #include <windows.h> #include "pthread.h" #include "pthread_time.h" -#include "winpthread_internal.h" +#include "thread.h" #define POW10_3 1000 #define POW10_4 10000 @@ -48,7 +48,7 @@ int nanosleep(const struct timespec *request, struct timespec *remain) else ms = (unsigned long) u64; u64 -= ms; - rc = pthread_delay_np_ms(ms); + rc = _pthread_delay_np_ms(ms); } if (rc != 0) { /* WAIT_IO_COMPLETION (192) */ diff --git a/mingw-w64-libraries/winpthreads/src/thread.c b/mingw-w64-libraries/winpthreads/src/thread.c index a13e5554d..361178fde 100644 --- a/mingw-w64-libraries/winpthreads/src/thread.c +++ b/mingw-w64-libraries/winpthreads/src/thread.c @@ -29,7 +29,6 @@ #include "pthread.h" #include "thread.h" #include "misc.h" -#include "winpthread_internal.h" static _pthread_v *__pthread_self_lite (void); @@ -671,10 +670,8 @@ pthread_delay_np (const struct timespec *interval) return 0; } -int pthread_delay_np_ms (DWORD to); - int -pthread_delay_np_ms (DWORD to) +_pthread_delay_np_ms (DWORD to) { struct _pthread_v *s = __pthread_self_lite (); diff --git a/mingw-w64-libraries/winpthreads/src/thread.h b/mingw-w64-libraries/winpthreads/src/thread.h index 97bfda77a..c38ff2b78 100644 --- a/mingw-w64-libraries/winpthreads/src/thread.h +++ b/mingw-w64-libraries/winpthreads/src/thread.h @@ -71,5 +71,6 @@ int _pthread_tryjoin(pthread_t t, void **res); void _pthread_setnobreak(int); int __pthread_shallcancel(void); WINPTHREAD_API struct _pthread_v * __pth_gpointer_locked (pthread_t id); +int _pthread_delay_np_ms (DWORD to); #endif diff --git a/mingw-w64-libraries/winpthreads/src/winpthread_internal.h b/mingw-w64-libraries/winpthreads/src/winpthread_internal.h deleted file mode 100644 index eb6838c34..000000000 --- a/mingw-w64-libraries/winpthreads/src/winpthread_internal.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Copyright (c) 2011-2016 mingw-w64 project - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -#ifndef WINPTHREAD_INTERNAL_H -#define WINPTHREAD_INTERNAL_H -WINPTHREAD_API struct _pthread_v * __pth_gpointer_locked (pthread_t id); -int pthread_delay_np_ms (DWORD to); -#endif /*WINPTHREAD_INTERNAL_H*/ -- 2.46.1.windows.1
From 42825d7014ec9d232b9a09870cac4cde0a9e870f Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Tue, 22 Apr 2025 11:15:40 +0900 Subject: [PATCH 04/11] winpthreads: remove ref.c and ref.h Internal header file ref.h does not declare any functions. Likewise, ref.c does not define any functions. Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- mingw-w64-libraries/winpthreads/Makefile.am | 1 - mingw-w64-libraries/winpthreads/src/barrier.c | 2 +- mingw-w64-libraries/winpthreads/src/cond.c | 1 - mingw-w64-libraries/winpthreads/src/ref.c | 34 ------------------- mingw-w64-libraries/winpthreads/src/ref.h | 29 ---------------- mingw-w64-libraries/winpthreads/src/rwlock.c | 1 - mingw-w64-libraries/winpthreads/src/sem.c | 3 +- 7 files changed, 2 insertions(+), 69 deletions(-) delete mode 100644 mingw-w64-libraries/winpthreads/src/ref.c delete mode 100644 mingw-w64-libraries/winpthreads/src/ref.h diff --git a/mingw-w64-libraries/winpthreads/Makefile.am b/mingw-w64-libraries/winpthreads/Makefile.am index 8fbdda963..0bcff1a6c 100644 --- a/mingw-w64-libraries/winpthreads/Makefile.am +++ b/mingw-w64-libraries/winpthreads/Makefile.am @@ -22,7 +22,6 @@ libwinpthread_la_SOURCES = \ src/misc.c src/misc.h \ src/mutex.c \ src/nanosleep.c \ - src/ref.c src/ref.h \ src/rwlock.c src/rwlock.h \ src/sem.c src/sem.h \ src/spinlock.c \ diff --git a/mingw-w64-libraries/winpthreads/src/barrier.c b/mingw-w64-libraries/winpthreads/src/barrier.c index f3b5c4664..13e38a2de 100644 --- a/mingw-w64-libraries/winpthreads/src/barrier.c +++ b/mingw-w64-libraries/winpthreads/src/barrier.c @@ -25,8 +25,8 @@ #include <stdio.h> #include <malloc.h> #include "pthread.h" +#include "semaphore.h" #include "barrier.h" -#include "ref.h" #include "misc.h" static pthread_spinlock_t barrier_global = PTHREAD_SPINLOCK_INITIALIZER; diff --git a/mingw-w64-libraries/winpthreads/src/cond.c b/mingw-w64-libraries/winpthreads/src/cond.c index b0ff65bea..ea49255b6 100644 --- a/mingw-w64-libraries/winpthreads/src/cond.c +++ b/mingw-w64-libraries/winpthreads/src/cond.c @@ -30,7 +30,6 @@ #include <time.h> #include "pthread.h" #include "pthread_time.h" -#include "ref.h" #include "cond.h" #include "thread.h" #include "misc.h" diff --git a/mingw-w64-libraries/winpthreads/src/ref.c b/mingw-w64-libraries/winpthreads/src/ref.c deleted file mode 100644 index 0344d457e..000000000 --- a/mingw-w64-libraries/winpthreads/src/ref.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright (c) 2011-2016 mingw-w64 project - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -#include <windows.h> -#include <winternl.h> -#include <stdio.h> -#include "pthread.h" -#include "semaphore.h" -#include "rwlock.h" -#include "cond.h" -#include "barrier.h" -#include "sem.h" -#include "ref.h" -#include "misc.h" - diff --git a/mingw-w64-libraries/winpthreads/src/ref.h b/mingw-w64-libraries/winpthreads/src/ref.h deleted file mode 100644 index 5ca67506f..000000000 --- a/mingw-w64-libraries/winpthreads/src/ref.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - Copyright (c) 2011-2016 mingw-w64 project - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -#ifndef WIN_PTHREADS_REF_H -#define WIN_PTHREADS_REF_H -#include "pthread.h" -#include "semaphore.h" - -#endif - diff --git a/mingw-w64-libraries/winpthreads/src/rwlock.c b/mingw-w64-libraries/winpthreads/src/rwlock.c index 7a4e5839d..0bdfe412f 100644 --- a/mingw-w64-libraries/winpthreads/src/rwlock.c +++ b/mingw-w64-libraries/winpthreads/src/rwlock.c @@ -26,7 +26,6 @@ #include <malloc.h> #include "pthread.h" #include "thread.h" -#include "ref.h" #include "rwlock.h" #include "misc.h" diff --git a/mingw-w64-libraries/winpthreads/src/sem.c b/mingw-w64-libraries/winpthreads/src/sem.c index 340ff69e0..990f10cd6 100644 --- a/mingw-w64-libraries/winpthreads/src/sem.c +++ b/mingw-w64-libraries/winpthreads/src/sem.c @@ -28,7 +28,6 @@ #include "misc.h" #include "semaphore.h" #include "sem.h" -#include "ref.h" int do_sema_b_wait_intern (HANDLE sema, int nointerrupt, DWORD timeout); @@ -350,5 +349,5 @@ sem_getvalue (sem_t *sem, int *sval) *sval = (int) sv->value; pthread_mutex_unlock (&sv->vlock); - return 0; + return 0; } -- 2.46.1.windows.1
From 81f71a4e68b39cec4a3f8b7a70a44667b22d1b5d Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Tue, 22 Apr 2025 12:39:24 +0900 Subject: [PATCH 05/11] winpthreads: move definition of WIN32_LEAN_AND_MEAN from Makefile.am to source files All #include directives in source files and internal header files have been grouped in following order: - CRT header files - Windows API header files - winpthreads' public header files - winpthreads' internal header files In each group, header files are sorted alphabetically. Unnecessary includes have been removed from internal header files. Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- mingw-w64-libraries/winpthreads/Makefile.am | 2 +- mingw-w64-libraries/winpthreads/src/barrier.c | 9 +++++++-- mingw-w64-libraries/winpthreads/src/barrier.h | 2 -- mingw-w64-libraries/winpthreads/src/clock.c | 11 ++++++----- mingw-w64-libraries/winpthreads/src/cond.c | 12 +++++++++--- mingw-w64-libraries/winpthreads/src/cond.h | 2 -- mingw-w64-libraries/winpthreads/src/misc.c | 4 ++++ mingw-w64-libraries/winpthreads/src/misc.h | 2 ++ mingw-w64-libraries/winpthreads/src/mutex.c | 15 ++++++++++----- mingw-w64-libraries/winpthreads/src/nanosleep.c | 5 +++++ mingw-w64-libraries/winpthreads/src/rwlock.c | 13 +++++++++---- mingw-w64-libraries/winpthreads/src/sched.c | 10 +++++++--- mingw-w64-libraries/winpthreads/src/sem.c | 13 +++++++++---- mingw-w64-libraries/winpthreads/src/sem.h | 2 -- mingw-w64-libraries/winpthreads/src/spinlock.c | 6 +++++- mingw-w64-libraries/winpthreads/src/thread.c | 15 ++++++++++----- mingw-w64-libraries/winpthreads/src/thread.h | 2 +- 17 files changed, 85 insertions(+), 40 deletions(-) diff --git a/mingw-w64-libraries/winpthreads/Makefile.am b/mingw-w64-libraries/winpthreads/Makefile.am index 0bcff1a6c..3c1404045 100644 --- a/mingw-w64-libraries/winpthreads/Makefile.am +++ b/mingw-w64-libraries/winpthreads/Makefile.am @@ -1,7 +1,7 @@ SUBDIRS = . tests -AM_CFLAGS = -Wall -DWIN32_LEAN_AND_MEAN +AM_CFLAGS = -Wall ACLOCAL_AMFLAGS = -I m4 lib_LTLIBRARIES = libwinpthread.la diff --git a/mingw-w64-libraries/winpthreads/src/barrier.c b/mingw-w64-libraries/winpthreads/src/barrier.c index 13e38a2de..858dda7d2 100644 --- a/mingw-w64-libraries/winpthreads/src/barrier.c +++ b/mingw-w64-libraries/winpthreads/src/barrier.c @@ -21,11 +21,16 @@ */ #include <assert.h> -#include <windows.h> -#include <stdio.h> #include <malloc.h> +#include <stdio.h> + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +/* public header files */ #include "pthread.h" #include "semaphore.h" +/* internal header files */ #include "barrier.h" #include "misc.h" diff --git a/mingw-w64-libraries/winpthreads/src/barrier.h b/mingw-w64-libraries/winpthreads/src/barrier.h index 5509678be..1d1e83da6 100644 --- a/mingw-w64-libraries/winpthreads/src/barrier.h +++ b/mingw-w64-libraries/winpthreads/src/barrier.h @@ -34,8 +34,6 @@ return EINVAL; \ } while (0) -#include "semaphore.h" - typedef struct barrier_t barrier_t; struct barrier_t { diff --git a/mingw-w64-libraries/winpthreads/src/clock.c b/mingw-w64-libraries/winpthreads/src/clock.c index 954d845b1..16e840fec 100644 --- a/mingw-w64-libraries/winpthreads/src/clock.c +++ b/mingw-w64-libraries/winpthreads/src/clock.c @@ -7,12 +7,13 @@ #include <errno.h> #include <stdint.h> #include <time.h> + +#define WIN32_LEAN_AND_MEAN #include <windows.h> -#ifndef IN_WINPTHREAD -#define IN_WINPTHREAD 1 -#endif -#include "pthread.h" + +/* public header files */ #include "pthread_time.h" +/* internal header files */ #include "misc.h" #define POW10_7 10000000 @@ -172,7 +173,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) return 0; } - case CLOCK_THREAD_CPUTIME_ID: + case CLOCK_THREAD_CPUTIME_ID: { if(0 == GetThreadTimes(GetCurrentThread(), &ct.ft, &et.ft, &kt.ft, &ut.ft)) return lc_set_errno(EINVAL); diff --git a/mingw-w64-libraries/winpthreads/src/cond.c b/mingw-w64-libraries/winpthreads/src/cond.c index ea49255b6..4013bdfbc 100644 --- a/mingw-w64-libraries/winpthreads/src/cond.c +++ b/mingw-w64-libraries/winpthreads/src/cond.c @@ -24,15 +24,21 @@ * Posix Condition Variables for Microsoft Windows. * 22-9-2010 Partly based on the ACE framework implementation. */ -#include <windows.h> -#include <stdio.h> + #include <malloc.h> +#include <stdio.h> #include <time.h> + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +/* public header files */ #include "pthread.h" #include "pthread_time.h" +/* internal header files */ #include "cond.h" -#include "thread.h" #include "misc.h" +#include "thread.h" #include "pthread_compat.h" diff --git a/mingw-w64-libraries/winpthreads/src/cond.h b/mingw-w64-libraries/winpthreads/src/cond.h index 9eda22369..fcf7db355 100644 --- a/mingw-w64-libraries/winpthreads/src/cond.h +++ b/mingw-w64-libraries/winpthreads/src/cond.h @@ -23,8 +23,6 @@ #ifndef WIN_PTHREADS_COND_H #define WIN_PTHREADS_COND_H -#include <windows.h> - #define CHECK_COND(c) \ do { \ if (!(c) || !*c || (*c == PTHREAD_COND_INITIALIZER) \ diff --git a/mingw-w64-libraries/winpthreads/src/misc.c b/mingw-w64-libraries/winpthreads/src/misc.c index c426f59cb..605c8f399 100644 --- a/mingw-w64-libraries/winpthreads/src/misc.c +++ b/mingw-w64-libraries/winpthreads/src/misc.c @@ -20,8 +20,12 @@ DEALINGS IN THE SOFTWARE. */ +#define WIN32_LEAN_AND_MEAN #include <windows.h> + +/* public header files */ #include "pthread.h" +/* internal header files */ #include "misc.h" void (WINAPI *_pthread_get_system_time_best_as_file_time) (LPFILETIME) = NULL; diff --git a/mingw-w64-libraries/winpthreads/src/misc.h b/mingw-w64-libraries/winpthreads/src/misc.h index f01f1fb55..75818b473 100644 --- a/mingw-w64-libraries/winpthreads/src/misc.h +++ b/mingw-w64-libraries/winpthreads/src/misc.h @@ -23,6 +23,8 @@ #ifndef WIN_PTHREADS_MISC_H #define WIN_PTHREADS_MISC_H +#include <limits.h> +/* public header files */ #include "pthread_compat.h" #define PTR2INT(x) ((int)(uintptr_t)(x)) diff --git a/mingw-w64-libraries/winpthreads/src/mutex.c b/mingw-w64-libraries/winpthreads/src/mutex.c index 866e18d94..782c14320 100644 --- a/mingw-w64-libraries/winpthreads/src/mutex.c +++ b/mingw-w64-libraries/winpthreads/src/mutex.c @@ -21,11 +21,16 @@ DEALINGS IN THE SOFTWARE. */ -#include <windows.h> -#include <stdio.h> #include <malloc.h> #include <stdbool.h> +#include <stdio.h> + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +/* public header files */ #include "pthread.h" +/* internal header files */ #include "misc.h" typedef enum { @@ -200,7 +205,7 @@ int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *ts) } int pthread_mutex_unlock(pthread_mutex_t *m) -{ +{ /* Here m might an initialiser of an error-checking or recursive mutex, in which case the behaviour is well-defined, so we can't skip this check. */ mutex_impl_t *mi = mutex_impl(m); @@ -305,9 +310,9 @@ int pthread_mutexattr_gettype(const pthread_mutexattr_t *a, int *type) { if (!a || !type) return EINVAL; - + *type = *a & 3; - + return 0; } diff --git a/mingw-w64-libraries/winpthreads/src/nanosleep.c b/mingw-w64-libraries/winpthreads/src/nanosleep.c index 5ee5ef60d..5b5c5f75c 100644 --- a/mingw-w64-libraries/winpthreads/src/nanosleep.c +++ b/mingw-w64-libraries/winpthreads/src/nanosleep.c @@ -6,9 +6,14 @@ #include <errno.h> #include <time.h> + +#define WIN32_LEAN_AND_MEAN #include <windows.h> + +/* public header files */ #include "pthread.h" #include "pthread_time.h" +/* internal header files */ #include "thread.h" #define POW10_3 1000 diff --git a/mingw-w64-libraries/winpthreads/src/rwlock.c b/mingw-w64-libraries/winpthreads/src/rwlock.c index 0bdfe412f..66c0b212a 100644 --- a/mingw-w64-libraries/winpthreads/src/rwlock.c +++ b/mingw-w64-libraries/winpthreads/src/rwlock.c @@ -21,13 +21,18 @@ */ #include <assert.h> -#include <windows.h> -#include <stdio.h> #include <malloc.h> +#include <stdio.h> + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +/* public header files */ #include "pthread.h" -#include "thread.h" -#include "rwlock.h" +/* internal header files */ #include "misc.h" +#include "rwlock.h" +#include "thread.h" static pthread_spinlock_t rwl_global = PTHREAD_SPINLOCK_INITIALIZER; diff --git a/mingw-w64-libraries/winpthreads/src/sched.c b/mingw-w64-libraries/winpthreads/src/sched.c index 976bcc105..a6ad84534 100644 --- a/mingw-w64-libraries/winpthreads/src/sched.c +++ b/mingw-w64-libraries/winpthreads/src/sched.c @@ -20,12 +20,16 @@ DEALINGS IN THE SOFTWARE. */ -#include <windows.h> #include <stdio.h> -#include "pthread.h" -#include "thread.h" +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +/* public header files */ +#include "pthread.h" +/* internal header files */ #include "misc.h" +#include "thread.h" int sched_get_priority_min(int pol) { diff --git a/mingw-w64-libraries/winpthreads/src/sem.c b/mingw-w64-libraries/winpthreads/src/sem.c index 990f10cd6..4172b1e23 100644 --- a/mingw-w64-libraries/winpthreads/src/sem.c +++ b/mingw-w64-libraries/winpthreads/src/sem.c @@ -20,14 +20,19 @@ DEALINGS IN THE SOFTWARE. */ -#include <windows.h> -#include <stdio.h> #include <malloc.h> +#include <stdio.h> + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +/* public header files */ #include "pthread.h" -#include "thread.h" -#include "misc.h" #include "semaphore.h" +/* internal header files */ +#include "misc.h" #include "sem.h" +#include "thread.h" int do_sema_b_wait_intern (HANDLE sema, int nointerrupt, DWORD timeout); diff --git a/mingw-w64-libraries/winpthreads/src/sem.h b/mingw-w64-libraries/winpthreads/src/sem.h index 3b3ace7f7..ddfc00a65 100644 --- a/mingw-w64-libraries/winpthreads/src/sem.h +++ b/mingw-w64-libraries/winpthreads/src/sem.h @@ -23,8 +23,6 @@ #ifndef WIN_SEM #define WIN_SEM -#include <windows.h> - #define LIFE_SEM 0xBAB1F00D #define DEAD_SEM 0xDEADBEEF diff --git a/mingw-w64-libraries/winpthreads/src/spinlock.c b/mingw-w64-libraries/winpthreads/src/spinlock.c index 224c5a06e..850735e38 100644 --- a/mingw-w64-libraries/winpthreads/src/spinlock.c +++ b/mingw-w64-libraries/winpthreads/src/spinlock.c @@ -21,8 +21,12 @@ DEALINGS IN THE SOFTWARE. */ +#define WIN32_LEAN_AND_MEAN #include <windows.h> + +/* public header files */ #include "pthread.h" +/* internal header files */ #include "misc.h" /* We use the pthread_spinlock_t itself as a lock: @@ -56,7 +60,7 @@ pthread_spin_lock (pthread_spinlock_t *lock) } while (*lk == 0); return 0; } - + int pthread_spin_trylock (pthread_spinlock_t *lock) { diff --git a/mingw-w64-libraries/winpthreads/src/thread.c b/mingw-w64-libraries/winpthreads/src/thread.c index 361178fde..1153da13f 100644 --- a/mingw-w64-libraries/winpthreads/src/thread.c +++ b/mingw-w64-libraries/winpthreads/src/thread.c @@ -20,15 +20,20 @@ DEALINGS IN THE SOFTWARE. */ -#include <windows.h> -#include <strsafe.h> -#include <stdio.h> -#include <stdlib.h> #include <malloc.h> #include <signal.h> +#include <stdio.h> +#include <stdlib.h> + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#include <strsafe.h> + +/* public header files */ #include "pthread.h" -#include "thread.h" +/* internal header files */ #include "misc.h" +#include "thread.h" static _pthread_v *__pthread_self_lite (void); diff --git a/mingw-w64-libraries/winpthreads/src/thread.h b/mingw-w64-libraries/winpthreads/src/thread.h index c38ff2b78..90f9cd39a 100644 --- a/mingw-w64-libraries/winpthreads/src/thread.h +++ b/mingw-w64-libraries/winpthreads/src/thread.h @@ -23,8 +23,8 @@ #ifndef WIN_PTHREAD_H #define WIN_PTHREAD_H -#include <windows.h> #include <setjmp.h> +/* internal header files */ #include "rwlock.h" #define LIFE_THREAD 0xBAB1F00D -- 2.46.1.windows.1
From 8ad6377cfb8c56f9b8f555aab62547239b19a02f Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Tue, 22 Apr 2025 12:57:25 +0900 Subject: [PATCH 06/11] winpthreads: remove unused checks from configure.ac Currently no source files include config.h, which means that results of all tests from configure.ac are unused. Most of the checks were testing for presence of features which are now available with both mingw-w64 and MSVC. config.h is now included from each source file in `src` subdirectory so that new configuration checks can be added in future. Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- mingw-w64-libraries/winpthreads/configure.ac | 9 --------- mingw-w64-libraries/winpthreads/src/barrier.c | 4 ++++ mingw-w64-libraries/winpthreads/src/clock.c | 4 ++++ mingw-w64-libraries/winpthreads/src/cond.c | 4 ++++ mingw-w64-libraries/winpthreads/src/misc.c | 4 ++++ mingw-w64-libraries/winpthreads/src/mutex.c | 4 ++++ mingw-w64-libraries/winpthreads/src/nanosleep.c | 4 ++++ mingw-w64-libraries/winpthreads/src/rwlock.c | 4 ++++ mingw-w64-libraries/winpthreads/src/sched.c | 4 ++++ mingw-w64-libraries/winpthreads/src/sem.c | 4 ++++ mingw-w64-libraries/winpthreads/src/spinlock.c | 4 ++++ mingw-w64-libraries/winpthreads/src/thread.c | 4 ++++ 12 files changed, 44 insertions(+), 9 deletions(-) diff --git a/mingw-w64-libraries/winpthreads/configure.ac b/mingw-w64-libraries/winpthreads/configure.ac index 0ae6f027c..503a1d8e1 100644 --- a/mingw-w64-libraries/winpthreads/configure.ac +++ b/mingw-w64-libraries/winpthreads/configure.ac @@ -35,21 +35,12 @@ LT_INIT([win32-dll]) LT_LANG([Windows Resource]) # Checks for libraries. -# FIXME: Replace `main' with a function in `-lpthread': -#AC_CHECK_LIB([pthread], [main]) # Checks for header files. -AC_CHECK_HEADERS([limits.h sys/timeb.h]) # Checks for typedefs, structures, and compiler characteristics. -AC_C_INLINE -AC_TYPE_SIZE_T # Checks for library functions. -#AC_FUNC_MALLOC -#AC_FUNC_REALLOC -# mingw-w64 should already have them -#AC_CHECK_FUNCS([ftime gettimeofday memset]) AC_CONFIG_FILES([Makefile tests/Makefile]) AC_OUTPUT diff --git a/mingw-w64-libraries/winpthreads/src/barrier.c b/mingw-w64-libraries/winpthreads/src/barrier.c index 858dda7d2..b1be5126a 100644 --- a/mingw-w64-libraries/winpthreads/src/barrier.c +++ b/mingw-w64-libraries/winpthreads/src/barrier.c @@ -20,6 +20,10 @@ DEALINGS IN THE SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <assert.h> #include <malloc.h> #include <stdio.h> diff --git a/mingw-w64-libraries/winpthreads/src/clock.c b/mingw-w64-libraries/winpthreads/src/clock.c index 16e840fec..17aa3dae6 100644 --- a/mingw-w64-libraries/winpthreads/src/clock.c +++ b/mingw-w64-libraries/winpthreads/src/clock.c @@ -4,6 +4,10 @@ * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <errno.h> #include <stdint.h> #include <time.h> diff --git a/mingw-w64-libraries/winpthreads/src/cond.c b/mingw-w64-libraries/winpthreads/src/cond.c index 4013bdfbc..afede3000 100644 --- a/mingw-w64-libraries/winpthreads/src/cond.c +++ b/mingw-w64-libraries/winpthreads/src/cond.c @@ -25,6 +25,10 @@ * 22-9-2010 Partly based on the ACE framework implementation. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <malloc.h> #include <stdio.h> #include <time.h> diff --git a/mingw-w64-libraries/winpthreads/src/misc.c b/mingw-w64-libraries/winpthreads/src/misc.c index 605c8f399..ae7447421 100644 --- a/mingw-w64-libraries/winpthreads/src/misc.c +++ b/mingw-w64-libraries/winpthreads/src/misc.c @@ -20,6 +20,10 @@ DEALINGS IN THE SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #define WIN32_LEAN_AND_MEAN #include <windows.h> diff --git a/mingw-w64-libraries/winpthreads/src/mutex.c b/mingw-w64-libraries/winpthreads/src/mutex.c index 782c14320..20d881513 100644 --- a/mingw-w64-libraries/winpthreads/src/mutex.c +++ b/mingw-w64-libraries/winpthreads/src/mutex.c @@ -21,6 +21,10 @@ DEALINGS IN THE SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <malloc.h> #include <stdbool.h> #include <stdio.h> diff --git a/mingw-w64-libraries/winpthreads/src/nanosleep.c b/mingw-w64-libraries/winpthreads/src/nanosleep.c index 5b5c5f75c..d1c139088 100644 --- a/mingw-w64-libraries/winpthreads/src/nanosleep.c +++ b/mingw-w64-libraries/winpthreads/src/nanosleep.c @@ -4,6 +4,10 @@ * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <errno.h> #include <time.h> diff --git a/mingw-w64-libraries/winpthreads/src/rwlock.c b/mingw-w64-libraries/winpthreads/src/rwlock.c index 66c0b212a..8aa62ec8a 100644 --- a/mingw-w64-libraries/winpthreads/src/rwlock.c +++ b/mingw-w64-libraries/winpthreads/src/rwlock.c @@ -20,6 +20,10 @@ DEALINGS IN THE SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <assert.h> #include <malloc.h> #include <stdio.h> diff --git a/mingw-w64-libraries/winpthreads/src/sched.c b/mingw-w64-libraries/winpthreads/src/sched.c index a6ad84534..0bdcc3ca9 100644 --- a/mingw-w64-libraries/winpthreads/src/sched.c +++ b/mingw-w64-libraries/winpthreads/src/sched.c @@ -20,6 +20,10 @@ DEALINGS IN THE SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <stdio.h> #define WIN32_LEAN_AND_MEAN diff --git a/mingw-w64-libraries/winpthreads/src/sem.c b/mingw-w64-libraries/winpthreads/src/sem.c index 4172b1e23..1226bb829 100644 --- a/mingw-w64-libraries/winpthreads/src/sem.c +++ b/mingw-w64-libraries/winpthreads/src/sem.c @@ -20,6 +20,10 @@ DEALINGS IN THE SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <malloc.h> #include <stdio.h> diff --git a/mingw-w64-libraries/winpthreads/src/spinlock.c b/mingw-w64-libraries/winpthreads/src/spinlock.c index 850735e38..eb21509d6 100644 --- a/mingw-w64-libraries/winpthreads/src/spinlock.c +++ b/mingw-w64-libraries/winpthreads/src/spinlock.c @@ -21,6 +21,10 @@ DEALINGS IN THE SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #define WIN32_LEAN_AND_MEAN #include <windows.h> diff --git a/mingw-w64-libraries/winpthreads/src/thread.c b/mingw-w64-libraries/winpthreads/src/thread.c index 1153da13f..7162ad97e 100644 --- a/mingw-w64-libraries/winpthreads/src/thread.c +++ b/mingw-w64-libraries/winpthreads/src/thread.c @@ -20,6 +20,10 @@ DEALINGS IN THE SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <malloc.h> #include <signal.h> #include <stdio.h> -- 2.46.1.windows.1
From e15f421dc6bad4966afb3b84b2affa30bb669e5f Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Tue, 22 Apr 2025 13:20:45 +0900 Subject: [PATCH 07/11] winpthreads: adjust compiler options when building with MSVC Check for `_MSC_VER` macro instead of checking `$CC` to recognize MSVC-like compilers. `MSC_VER` is alse defined by `clang-cl.exe`. Use `-W3` instead of `-Wall` when building with MSVC-link compilers. The `-Wall` flag is way too noisy. Add a few more *feature* macros when building with MSVC-like compilers. This silences warnings about *unsafe* functions and allows to pass MSVC's `-Zc:__STDC__` compiler option. Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- mingw-w64-libraries/winpthreads/Makefile.am | 7 +++--- mingw-w64-libraries/winpthreads/configure.ac | 24 +++++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/mingw-w64-libraries/winpthreads/Makefile.am b/mingw-w64-libraries/winpthreads/Makefile.am index 3c1404045..6a3828d64 100644 --- a/mingw-w64-libraries/winpthreads/Makefile.am +++ b/mingw-w64-libraries/winpthreads/Makefile.am @@ -1,7 +1,7 @@ SUBDIRS = . tests -AM_CFLAGS = -Wall +AM_CFLAGS = ACLOCAL_AMFLAGS = -I m4 lib_LTLIBRARIES = libwinpthread.la @@ -34,9 +34,10 @@ libwinpthread_la_CPPFLAGS = -I$(srcdir)/include -DIN_WINPTHREAD libwinpthread_la_LDFLAGS = -no-undefined -version-info 1:0:0 if MSVC -AM_CFLAGS += -nologo -libwinpthread_la_CPPFLAGS += -D_CRT_NONSTDC_NO_WARNINGS +AM_CFLAGS += -W3 +libwinpthread_la_CPPFLAGS += -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_DECLARE_NONSTDC_NAMES -D_CRT_SECURE_NO_WARNINGS else +AM_CFLAGS += -Wall libwinpthread_la_CPPFLAGS += -D__USE_MINGW_ANSI_STDIO=0 libwinpthread_la_LDFLAGS += -L$(builddir)/fakelib -Wc,-no-pthread EXTRA_libwinpthread_la_DEPENDENCIES = fakelib/libgcc.a fakelib/libgcc_eh.a fakelib/libgcc_s.a diff --git a/mingw-w64-libraries/winpthreads/configure.ac b/mingw-w64-libraries/winpthreads/configure.ac index 503a1d8e1..45d382136 100644 --- a/mingw-w64-libraries/winpthreads/configure.ac +++ b/mingw-w64-libraries/winpthreads/configure.ac @@ -19,13 +19,25 @@ AC_PROG_CC AM_PROG_AS AM_PROG_AR -AS_CASE([$CC], - [*cl|*cl.exe], - [RC="$am_aux_dir/windres-rc rc.exe" - msvc=true], - [msvc=false]]) +AC_MSG_CHECKING([whether C compiler is MSVC-like compiler]) +AC_COMPILE_IFELSE( + [AC_LANG_SOURCE( + [ +#if !defined (_MSC_VER) +not msvc +#endif + ]) + ], +dnl then + [RC="$am_aux_dir/windres-rc rc.exe"] + [msvc=yes], +dnl else + [msvc=no] +) +AC_MSG_RESULT([$msvc]) + AC_SUBST([RCFLAGS]) -AM_CONDITIONAL([MSVC], [test x$msvc = xtrue]) +AM_CONDITIONAL([MSVC], [test x$msvc = xyes]) # Libtool 2.4 should check them correctly # AC_CHECK_TOOLS([AR],[ar],[:]) -- 2.46.1.windows.1
From fcb46cc85f2ddc7d882f8e0751e605c4801c85d9 Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Tue, 22 Apr 2025 13:26:28 +0900 Subject: [PATCH 08/11] winpthreads: remove some internal functions from pthread.h Declarations of the following functions have been removed from pthread.h: - _pthread_rel_time_in_ms - _pthread_time_in_ms - _pthread_time_in_ms_from_timespec These functions are declared in internal misc.h. Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- mingw-w64-libraries/winpthreads/include/pthread.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/mingw-w64-libraries/winpthreads/include/pthread.h b/mingw-w64-libraries/winpthreads/include/pthread.h index 7f0be9ea4..d06c0c846 100644 --- a/mingw-w64-libraries/winpthreads/include/pthread.h +++ b/mingw-w64-libraries/winpthreads/include/pthread.h @@ -355,9 +355,6 @@ WINPTHREAD_API struct _pthread_cleanup ** pthread_getclean (void); WINPTHREAD_API void * pthread_gethandle (pthread_t t); WINPTHREAD_API void * pthread_getevent (void); -WINPTHREAD_API unsigned long long _pthread_rel_time_in_ms(const struct timespec *ts); -WINPTHREAD_API unsigned long long _pthread_time_in_ms(void); -WINPTHREAD_API unsigned long long _pthread_time_in_ms_from_timespec(const struct timespec *ts); WINPTHREAD_API int _pthread_tryjoin (pthread_t t, void **res); WINPTHREAD_API int pthread_rwlockattr_destroy(pthread_rwlockattr_t *a); WINPTHREAD_API int pthread_rwlockattr_getpshared(pthread_rwlockattr_t *a, int *s); -- 2.46.1.windows.1
From c016fc4dc4a94d8387f131c7148bfe6048b7bb9c Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Tue, 22 Apr 2025 13:32:41 +0900 Subject: [PATCH 09/11] winpthreads: use `mbsrtowcs` instead of `mbstowcs` `pthread_setname_np` function defined in thread.c uses `mbstowcs` function which is not thread-safe. Use `mbsrtowcs` instead. Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- mingw-w64-libraries/winpthreads/src/thread.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mingw-w64-libraries/winpthreads/src/thread.c b/mingw-w64-libraries/winpthreads/src/thread.c index 7162ad97e..e13704bb6 100644 --- a/mingw-w64-libraries/winpthreads/src/thread.c +++ b/mingw-w64-libraries/winpthreads/src/thread.c @@ -28,6 +28,7 @@ #include <signal.h> #include <stdio.h> #include <stdlib.h> +#include <wchar.h> #define WIN32_LEAN_AND_MEAN #include <windows.h> @@ -1859,13 +1860,14 @@ pthread_setname_np (pthread_t thread, const char *name) if (_pthread_set_thread_description != NULL) { - size_t required_size = mbstowcs(NULL, name, 0); + mbstate_t mbs = {0}; + size_t required_size = mbsrtowcs(NULL, &name, 0, &mbs); if (required_size != (size_t)-1) { wchar_t *wname = malloc((required_size + 1) * sizeof(wchar_t)); if (wname != NULL) { - mbstowcs(wname, name, required_size + 1); + mbsrtowcs(wname, &name, required_size + 1, &mbs); _pthread_set_thread_description(tv->h, wname); free(wname); } -- 2.46.1.windows.1
From 83bacea0cd8718d5c6672413fbc727dbd9532cf9 Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Tue, 22 Apr 2025 13:40:32 +0900 Subject: [PATCH 10/11] winpthreads: disable -Wprio-ctor-dtor warning in misc.c Usage of __attribute__((constructor(0))) triggers -Wprio-ctor-dtor warning. Temporary disable this warning with `#pragma GCC diagnostic`. Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- mingw-w64-libraries/winpthreads/src/misc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mingw-w64-libraries/winpthreads/src/misc.c b/mingw-w64-libraries/winpthreads/src/misc.c index ae7447421..1e0d6124a 100644 --- a/mingw-w64-libraries/winpthreads/src/misc.c +++ b/mingw-w64-libraries/winpthreads/src/misc.c @@ -37,6 +37,8 @@ static ULONGLONG (WINAPI *_pthread_get_tick_count_64) (VOID); HRESULT (WINAPI *_pthread_set_thread_description) (HANDLE, PCWSTR) = NULL; #if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wprio-ctor-dtor" __attribute__((constructor(0))) #endif static void winpthreads_init(void) @@ -63,6 +65,9 @@ static void winpthreads_init(void) (HRESULT (WINAPI *)(HANDLE, PCWSTR))(void*) GetProcAddress(mod, "SetThreadDescription"); } } +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic pop +#endif #if defined(_MSC_VER) && !defined(__clang__) /* Force a reference to __xc_t to prevent whole program optimization -- 2.46.1.windows.1
From 2bb6d3f010d3a369c71c308bb1c64486f61e3f77 Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Tue, 22 Apr 2025 16:44:07 +0900 Subject: [PATCH 11/11] winpthreads: add support for _USE_32BIT_TIME_T and _TIME_BITS This patch adds handling for CRT's _USE_32BIT_TIME_T and POSIX _TIME_BITS macros. This patch adds two versions of each public function which uses `struct timespec`. One version with suffix `32`, which uses `struct _timespec32` and one version with suffix `64`, which uses `struct _timespec64`. The plain versions without the suffix are implemented as static inline functions which call explicitly sized version and perform type cast from `struct timespec*` to explicitly sized version of the structure. External symbols for plain versions are still provided. They use either 32- or 64-suffixed version internally. pthread_compat.h: - new macro `WINPTHREADS_TIME_BITS` has been added - new macro `WINPTHREADS_ALWAYS_INLINE` has been added - a few new supplementary macros have been added pthread.h: Function `__pthread_clock_nanosleep` has been removed. winpthreads now provides `clock_nanosleep` with standard POSIX name. Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- .../winpthreads/include/pthread.h | 68 +++++++++-- .../winpthreads/include/pthread_compat.h | 32 ++++- .../winpthreads/include/pthread_time.h | 58 ++++++++- .../winpthreads/include/semaphore.h | 11 +- mingw-w64-libraries/winpthreads/src/clock.c | 112 ++++++++++++++++-- mingw-w64-libraries/winpthreads/src/cond.c | 56 +++------ mingw-w64-libraries/winpthreads/src/misc.c | 4 +- mingw-w64-libraries/winpthreads/src/misc.h | 4 +- mingw-w64-libraries/winpthreads/src/mutex.c | 16 ++- .../winpthreads/src/nanosleep.c | 31 ++++- mingw-w64-libraries/winpthreads/src/rwlock.c | 40 +++++-- mingw-w64-libraries/winpthreads/src/sem.c | 16 ++- mingw-w64-libraries/winpthreads/src/thread.c | 19 ++- 13 files changed, 388 insertions(+), 79 deletions(-) diff --git a/mingw-w64-libraries/winpthreads/include/pthread.h b/mingw-w64-libraries/winpthreads/include/pthread.h index d06c0c846..3ab5db741 100644 --- a/mingw-w64-libraries/winpthreads/include/pthread.h +++ b/mingw-w64-libraries/winpthreads/include/pthread.h @@ -139,7 +139,16 @@ extern "C" { #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE WINPTHREAD_API void * pthread_timechange_handler_np(void * dummy); -WINPTHREAD_API int pthread_delay_np (const struct timespec *interval); +WINPTHREAD_API int pthread_delay32_np (const struct _timespec32 *interval); +WINPTHREAD_API int pthread_delay64_np (const struct _timespec64 *interval); +WINPTHREAD_THREAD_DECL int pthread_delay_np (const struct timespec *interval) +{ +#if WINPTHREADS_TIME_BITS == 32 + return pthread_delay32_np ((const struct _timespec32 *) interval); +#else + return pthread_delay64_np ((const struct _timespec64 *) interval); +#endif +} WINPTHREAD_API int pthread_num_processors_np(void); WINPTHREAD_API int pthread_set_num_processors_np(int n); @@ -269,12 +278,29 @@ WINPTHREAD_API int pthread_detach(pthread_t t); WINPTHREAD_API int pthread_setname_np(pthread_t thread, const char *name); WINPTHREAD_API int pthread_getname_np(pthread_t thread, char *name, size_t len); - WINPTHREAD_API int pthread_rwlock_init(pthread_rwlock_t *rwlock_, const pthread_rwlockattr_t *attr); WINPTHREAD_API int pthread_rwlock_wrlock(pthread_rwlock_t *l); -WINPTHREAD_API int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *ts); +WINPTHREAD_API int pthread_rwlock_timedwrlock32(pthread_rwlock_t *rwlock, const struct _timespec32 *ts); +WINPTHREAD_API int pthread_rwlock_timedwrlock64(pthread_rwlock_t *rwlock, const struct _timespec64 *ts); +WINPTHREAD_RWLOCK_DECL int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *ts) +{ +#if WINPTHREADS_TIME_BITS == 32 + return pthread_rwlock_timedwrlock32 (rwlock, (const struct _timespec32 *) ts); +#else + return pthread_rwlock_timedwrlock64 (rwlock, (const struct _timespec64 *) ts); +#endif +} WINPTHREAD_API int pthread_rwlock_rdlock(pthread_rwlock_t *l); -WINPTHREAD_API int pthread_rwlock_timedrdlock(pthread_rwlock_t *l, const struct timespec *ts); +WINPTHREAD_API int pthread_rwlock_timedrdlock32(pthread_rwlock_t *l, const struct _timespec32 *ts); +WINPTHREAD_API int pthread_rwlock_timedrdlock64(pthread_rwlock_t *l, const struct _timespec64 *ts); +WINPTHREAD_RWLOCK_DECL int pthread_rwlock_timedrdlock(pthread_rwlock_t *l, const struct timespec *ts) +{ +#if WINPTHREADS_TIME_BITS == 32 + return pthread_rwlock_timedrdlock32 (l, (const struct _timespec32 *) ts); +#else + return pthread_rwlock_timedrdlock64 (l, (const struct _timespec64 *) ts); +#endif +} WINPTHREAD_API int pthread_rwlock_unlock(pthread_rwlock_t *l); WINPTHREAD_API int pthread_rwlock_tryrdlock(pthread_rwlock_t *l); WINPTHREAD_API int pthread_rwlock_trywrlock(pthread_rwlock_t *l); @@ -285,11 +311,38 @@ WINPTHREAD_API int pthread_cond_destroy(pthread_cond_t *cv); WINPTHREAD_API int pthread_cond_signal (pthread_cond_t *cv); WINPTHREAD_API int pthread_cond_broadcast (pthread_cond_t *cv); WINPTHREAD_API int pthread_cond_wait (pthread_cond_t *cv, pthread_mutex_t *external_mutex); -WINPTHREAD_API int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *external_mutex, const struct timespec *t); -WINPTHREAD_API int pthread_cond_timedwait_relative_np(pthread_cond_t *cv, pthread_mutex_t *external_mutex, const struct timespec *t); +WINPTHREAD_API int pthread_cond_timedwait32(pthread_cond_t *cv, pthread_mutex_t *external_mutex, const struct _timespec32 *t); +WINPTHREAD_API int pthread_cond_timedwait64(pthread_cond_t *cv, pthread_mutex_t *external_mutex, const struct _timespec64 *t); +WINPTHREAD_COND_DECL int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *external_mutex, const struct timespec *t) +{ +#if WINPTHREADS_TIME_BITS == 32 + return pthread_cond_timedwait32 (cv, external_mutex, (const struct _timespec32 *) t); +#else + return pthread_cond_timedwait64 (cv, external_mutex, (const struct _timespec64 *) t); +#endif +} +WINPTHREAD_API int pthread_cond_timedwait32_relative_np(pthread_cond_t *cv, pthread_mutex_t *external_mutex, const struct _timespec32 *t); +WINPTHREAD_API int pthread_cond_timedwait64_relative_np(pthread_cond_t *cv, pthread_mutex_t *external_mutex, const struct _timespec64 *t); +WINPTHREAD_COND_DECL int pthread_cond_timedwait_relative_np(pthread_cond_t *cv, pthread_mutex_t *external_mutex, const struct timespec *t) +{ +#if WINPTHREADS_TIME_BITS == 32 + return pthread_cond_timedwait32_relative_np (cv, external_mutex, (const struct _timespec32 *) t); +#else + return pthread_cond_timedwait64_relative_np (cv, external_mutex, (const struct _timespec64 *) t); +#endif +} WINPTHREAD_API int pthread_mutex_lock(pthread_mutex_t *m); -WINPTHREAD_API int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *ts); +WINPTHREAD_API int pthread_mutex_timedlock32(pthread_mutex_t *m, const struct _timespec32 *ts); +WINPTHREAD_API int pthread_mutex_timedlock64(pthread_mutex_t *m, const struct _timespec64 *ts); +WINPTHREAD_MUTEX_DECL int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *ts) +{ +#if WINPTHREADS_TIME_BITS == 32 + return pthread_mutex_timedlock32 (m, (const struct _timespec32 *) ts); +#else + return pthread_mutex_timedlock64 (m, (const struct _timespec64 *) ts); +#endif +} WINPTHREAD_API int pthread_mutex_unlock(pthread_mutex_t *m); WINPTHREAD_API int pthread_mutex_trylock(pthread_mutex_t *m); WINPTHREAD_API int pthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *a); @@ -343,7 +396,6 @@ 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, clockid_t clock_id); -WINPTHREAD_API int __pthread_clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp); WINPTHREAD_API int pthread_barrierattr_init(void **attr); WINPTHREAD_API int pthread_barrierattr_destroy(void **attr); diff --git a/mingw-w64-libraries/winpthreads/include/pthread_compat.h b/mingw-w64-libraries/winpthreads/include/pthread_compat.h index 96118722d..3a8552882 100644 --- a/mingw-w64-libraries/winpthreads/include/pthread_compat.h +++ b/mingw-w64-libraries/winpthreads/include/pthread_compat.h @@ -60,6 +60,12 @@ #ifndef WIN_PTHREADS_PTHREAD_COMPAT_H #define WIN_PTHREADS_PTHREAD_COMPAT_H +#if defined(_USE_32BIT_TIME_T) || (defined(_TIME_BITS) && _TIME_BITS == 32) +#define WINPTHREADS_TIME_BITS 32 +#else +#define WINPTHREADS_TIME_BITS 64 +#endif + #if defined(IN_WINPTHREAD) # if defined(DLL_EXPORT) # define WINPTHREAD_API __declspec(dllexport) /* building the DLL */ @@ -97,7 +103,8 @@ typedef unsigned short mode_t; #ifdef __GNUC__ -#define WINPTHREADS_INLINE inline +#define WINPTHREADS_INLINE __inline__ +#define WINPTHREADS_ALWAYS_INLINE __inline__ __attribute__((__always_inline__)) #define WINPTHREADS_ATTRIBUTE(X) __attribute__(X) #define WINPTHREADS_SECTION(X) __section__(X) @@ -110,9 +117,32 @@ typedef int pid_t; #endif #define WINPTHREADS_INLINE __inline +#define WINPTHREADS_ALWAYS_INLINE __inline __forceinline #define WINPTHREADS_ATTRIBUTE(X) __declspec X #define WINPTHREADS_SECTION(X) allocate(X) #endif +#ifndef WINPTHREAD_CLOCK_DECL +#define WINPTHREAD_CLOCK_DECL static WINPTHREADS_ALWAYS_INLINE +#endif +#ifndef WINPTHREAD_COND_DECL +#define WINPTHREAD_COND_DECL static WINPTHREADS_ALWAYS_INLINE +#endif +#ifndef WINPTHREAD_MUTEX_DECL +#define WINPTHREAD_MUTEX_DECL static WINPTHREADS_ALWAYS_INLINE +#endif +#ifndef WINPTHREAD_NANOSLEEP_DECL +#define WINPTHREAD_NANOSLEEP_DECL static WINPTHREADS_ALWAYS_INLINE +#endif +#ifndef WINPTHREAD_RWLOCK_DECL +#define WINPTHREAD_RWLOCK_DECL static WINPTHREADS_ALWAYS_INLINE +#endif +#ifndef WINPTHREAD_SEM_DECL +#define WINPTHREAD_SEM_DECL static WINPTHREADS_ALWAYS_INLINE +#endif +#ifndef WINPTHREAD_THREAD_DECL +#define WINPTHREAD_THREAD_DECL static WINPTHREADS_ALWAYS_INLINE +#endif + #endif diff --git a/mingw-w64-libraries/winpthreads/include/pthread_time.h b/mingw-w64-libraries/winpthreads/include/pthread_time.h index 363154d67..ac014aefc 100644 --- a/mingw-w64-libraries/winpthreads/include/pthread_time.h +++ b/mingw-w64-libraries/winpthreads/include/pthread_time.h @@ -73,12 +73,60 @@ extern "C" { #endif -WINPTHREAD_API int __cdecl nanosleep(const struct timespec *request, struct timespec *remain); +WINPTHREAD_API int __cdecl nanosleep32(const struct _timespec32 *request, struct _timespec32 *remain); +WINPTHREAD_API int __cdecl nanosleep64(const struct _timespec64 *request, struct _timespec64 *remain); +WINPTHREAD_NANOSLEEP_DECL int __cdecl nanosleep(const struct timespec *request, struct timespec *remain) +{ +#if WINPTHREADS_TIME_BITS == 32 + return nanosleep32 ((struct _timespec32 *)request, (struct _timespec32 *)remain); +#else + return nanosleep64 ((struct _timespec64 *)request, (struct _timespec64 *)remain); +#endif +} -WINPTHREAD_API int __cdecl clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *request, struct timespec *remain); -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); +WINPTHREAD_API int __cdecl clock_nanosleep32(clockid_t clock_id, int flags, const struct _timespec32 *request, struct _timespec32 *remain); +WINPTHREAD_API int __cdecl clock_nanosleep64(clockid_t clock_id, int flags, const struct _timespec64 *request, struct _timespec64 *remain); +WINPTHREAD_CLOCK_DECL int __cdecl clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *request, struct timespec *remain) +{ +#if WINPTHREADS_TIME_BITS == 32 + return clock_nanosleep32 (clock_id, flags, (struct _timespec32 *)request, (struct _timespec32 *)remain); +#else + return clock_nanosleep64 (clock_id, flags, (struct _timespec64 *)request, (struct _timespec64 *)remain); +#endif +} + +WINPTHREAD_API int __cdecl clock_getres32(clockid_t clock_id, struct _timespec32 *res); +WINPTHREAD_API int __cdecl clock_getres64(clockid_t clock_id, struct _timespec64 *res); +WINPTHREAD_CLOCK_DECL int __cdecl clock_getres(clockid_t clock_id, struct timespec *res) +{ +#if WINPTHREADS_TIME_BITS == 32 + return clock_getres32 (clock_id, (struct _timespec32 *)res); +#else + return clock_getres64 (clock_id, (struct _timespec64 *)res); +#endif +} + +WINPTHREAD_API int __cdecl clock_gettime32(clockid_t clock_id, struct _timespec32 *tp); +WINPTHREAD_API int __cdecl clock_gettime64(clockid_t clock_id, struct _timespec64 *tp); +WINPTHREAD_CLOCK_DECL int __cdecl clock_gettime(clockid_t clock_id, struct timespec *tp) +{ +#if WINPTHREADS_TIME_BITS == 32 + return clock_gettime32 (clock_id, (struct _timespec32 *)tp); +#else + return clock_gettime64 (clock_id, (struct _timespec64 *)tp); +#endif +} + +WINPTHREAD_API int __cdecl clock_settime32(clockid_t clock_id, const struct _timespec32 *tp); +WINPTHREAD_API int __cdecl clock_settime64(clockid_t clock_id, const struct _timespec64 *tp); +WINPTHREAD_CLOCK_DECL int __cdecl clock_settime(clockid_t clock_id, const struct timespec *tp) +{ +#if WINPTHREADS_TIME_BITS == 32 + return clock_settime32 (clock_id, (struct _timespec32 *)tp); +#else + return clock_settime64 (clock_id, (struct _timespec64 *)tp); +#endif +} #ifdef __cplusplus } diff --git a/mingw-w64-libraries/winpthreads/include/semaphore.h b/mingw-w64-libraries/winpthreads/include/semaphore.h index b6cd13f16..649583ffc 100644 --- a/mingw-w64-libraries/winpthreads/include/semaphore.h +++ b/mingw-w64-libraries/winpthreads/include/semaphore.h @@ -43,7 +43,16 @@ WINPTHREAD_API int sem_trywait(sem_t *sem); WINPTHREAD_API int sem_wait(sem_t *sem); -WINPTHREAD_API int sem_timedwait(sem_t * sem, const struct timespec *t); +WINPTHREAD_API int sem_timedwait32(sem_t * sem, const struct _timespec32 *t); +WINPTHREAD_API int sem_timedwait64(sem_t * sem, const struct _timespec64 *t); +WINPTHREAD_SEM_DECL int sem_timedwait(sem_t * sem, const struct timespec *t) +{ +#if WINPTHREADS_TIME_BITS == 32 + return sem_timedwait32 (sem, (const struct _timespec32 *) t); +#else + return sem_timedwait64 (sem, (const struct _timespec64 *) t); +#endif +} WINPTHREAD_API int sem_post(sem_t *sem); diff --git a/mingw-w64-libraries/winpthreads/src/clock.c b/mingw-w64-libraries/winpthreads/src/clock.c index 17aa3dae6..922c5de5d 100644 --- a/mingw-w64-libraries/winpthreads/src/clock.c +++ b/mingw-w64-libraries/winpthreads/src/clock.c @@ -8,6 +8,7 @@ #include "config.h" #endif +#include <assert.h> #include <errno.h> #include <stdint.h> #include <time.h> @@ -15,6 +16,8 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> +#define WINPTHREAD_CLOCK_DECL WINPTHREAD_API + /* public header files */ #include "pthread_time.h" /* internal header files */ @@ -56,7 +59,7 @@ static WINPTHREADS_INLINE int lc_set_errno(int result) * If the function fails, the return value is -1, * with errno set to indicate the error. */ -int clock_getres(clockid_t clock_id, struct timespec *res) +static int __clock_getres(clockid_t clock_id, struct _timespec64 *res) { clockid_t id = clock_id; @@ -118,7 +121,7 @@ int clock_getres(clockid_t clock_id, struct timespec *res) * If the function fails, the return value is -1, * with errno set to indicate the error. */ -int clock_gettime(clockid_t clock_id, struct timespec *tp) +static int __clock_gettime(clockid_t clock_id, struct _timespec64 *tp) { unsigned __int64 t; LARGE_INTEGER pf, pc; @@ -206,20 +209,20 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) * If the function fails, the return value is -1, * with errno set to indicate the error. */ -int clock_nanosleep(clockid_t clock_id, int flags, - const struct timespec *request, - struct timespec *remain) +static int __clock_nanosleep(clockid_t clock_id, int flags, + const struct _timespec64 *request, + struct _timespec64 *remain) { - struct timespec tp; + struct _timespec64 tp; if (clock_id != CLOCK_REALTIME) return lc_set_errno(EINVAL); if (flags == 0) - return nanosleep(request, remain); + return nanosleep64(request, remain); /* TIMER_ABSTIME = 1 */ - clock_gettime(CLOCK_REALTIME, &tp); + __clock_gettime(CLOCK_REALTIME, &tp); tp.tv_sec = request->tv_sec - tp.tv_sec; tp.tv_nsec = request->tv_nsec - tp.tv_nsec; @@ -228,7 +231,7 @@ int clock_nanosleep(clockid_t clock_id, int flags, tp.tv_sec --; } - return nanosleep(&tp, remain); + return nanosleep64(&tp, remain); } /** @@ -239,7 +242,7 @@ int clock_nanosleep(clockid_t clock_id, int flags, * If the function fails, the return value is -1, * with errno set to indicate the error. */ -int clock_settime(clockid_t clock_id, const struct timespec *tp) +static int __clock_settime(clockid_t clock_id, const struct _timespec64 *tp) { SYSTEMTIME st; @@ -260,3 +263,92 @@ int clock_settime(clockid_t clock_id, const struct timespec *tp) return 0; } + +/** + * Versions to use with 64-bit time_t (struct _timespec64) + */ + +int clock_getres64 (clockid_t clock_id, struct _timespec64 *tp) +{ + return __clock_getres (clock_id, tp); +} + +int clock_gettime64 (clockid_t clock_id, struct _timespec64 *tp) +{ + return __clock_gettime (clock_id, tp); +} + +int clock_settime64 (clockid_t clock_id, const struct _timespec64 *tp) +{ + return __clock_settime (clock_id, tp); +} + +int clock_nanosleep64 (clockid_t clock_id, int flags, + const struct _timespec64 *request, struct _timespec64 *remain) +{ + return __clock_nanosleep (clock_id, flags, request, remain); +} + +/** + * Versions to use with 32-bit time_t (struct _timespec32) + */ + +int clock_getres32 (clockid_t clock_id, struct _timespec32 *tp) +{ + struct _timespec64 tp64 = {0}; + + if (__clock_getres (clock_id, &tp64) == -1) + return -1; + + tp->tv_sec = (__time32_t) tp64.tv_sec; + tp->tv_nsec = tp64.tv_nsec; + + return 0; +} + +int clock_gettime32 (clockid_t clock_id, struct _timespec32 *tp) +{ + struct _timespec64 tp64 = {0}; + + if (__clock_gettime (clock_id, &tp64) == -1) + return -1; + + if (tp64.tv_sec > INT_MAX) + { + _set_errno (EOVERFLOW); + return -1; + } + + tp->tv_sec = (__time32_t) tp64.tv_sec; + tp->tv_nsec = tp64.tv_nsec; + + return 0; +} + +int clock_settime32 (clockid_t clock_id, const struct _timespec32 *tp) +{ + struct _timespec64 tp64 = {.tv_sec = tp->tv_sec, .tv_nsec = tp->tv_nsec}; + return __clock_settime (clock_id, &tp64); +} + +int clock_nanosleep32 (clockid_t clock_id, int flags, + const struct _timespec32 *request, struct _timespec32 *remain) +{ + struct _timespec64 request64 = { + .tv_sec = request->tv_sec, + .tv_nsec = request->tv_nsec + }; + struct _timespec64 remain64 = {0}; + + if (__clock_nanosleep (clock_id, flags, &request64, &remain64) == -1) + return -1; + + assert (remain64.tv_sec <= INT_MAX); + + if (remain != NULL) { + remain->tv_sec = (__time32_t)remain64.tv_sec; + remain->tv_nsec = remain64.tv_nsec; + } + + return 0; +} diff --git a/mingw-w64-libraries/winpthreads/src/cond.c b/mingw-w64-libraries/winpthreads/src/cond.c index afede3000..a77cd3ef0 100644 --- a/mingw-w64-libraries/winpthreads/src/cond.c +++ b/mingw-w64-libraries/winpthreads/src/cond.c @@ -36,6 +36,8 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> +#define WINPTHREAD_COND_DECL WINPTHREAD_API + /* public header files */ #include "pthread.h" #include "pthread_time.h" @@ -123,40 +125,6 @@ pthread_condattr_setclock(pthread_condattr_t *a, clockid_t clock_id) return 0; } -int -__pthread_clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *rqtp, - struct timespec *rmtp) -{ - unsigned long long tick, tick2; - unsigned long long delay; - DWORD dw; - - if (clock_id != CLOCK_REALTIME - && clock_id != CLOCK_MONOTONIC - && clock_id != CLOCK_PROCESS_CPUTIME_ID) - return EINVAL; - if ((flags & TIMER_ABSTIME) != 0) - delay = _pthread_rel_time_in_ms (rqtp); - else - delay = _pthread_time_in_ms_from_timespec (rqtp); - do - { - dw = (DWORD) (delay >= 99999ULL ? 99999ULL : delay); - tick = _pthread_time_in_ms (); - _pthread_delay_np_ms (dw); - tick2 = _pthread_time_in_ms (); - tick2 -= tick; - if (tick2 >= delay) - delay = 0; - else - delay -= tick2; - } - while (delay != 0ULL); - if (rmtp) - memset (rmtp, 0, sizeof (*rmtp)); - return 0; -} - int pthread_condattr_setpshared (pthread_condattr_t *a, int s) { @@ -445,7 +413,7 @@ tryagain: } static int -pthread_cond_timedwait_impl (pthread_cond_t *c, pthread_mutex_t *external_mutex, const struct timespec *t, int rel) +pthread_cond_timedwait_impl (pthread_cond_t *c, pthread_mutex_t *external_mutex, const struct _timespec64 *t, int rel) { sCondWaitHelper ch; DWORD dwr; @@ -511,17 +479,31 @@ tryagain: } int -pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m, const struct timespec *t) +pthread_cond_timedwait64(pthread_cond_t *c, pthread_mutex_t *m, const struct _timespec64 *t) { return pthread_cond_timedwait_impl(c, m, t, 0); } int -pthread_cond_timedwait_relative_np(pthread_cond_t *c, pthread_mutex_t *m, const struct timespec *t) +pthread_cond_timedwait32(pthread_cond_t *c, pthread_mutex_t *m, const struct _timespec32 *t) +{ + struct _timespec64 t64 = {.tv_sec = t->tv_sec, .tv_nsec = t->tv_nsec}; + return pthread_cond_timedwait_impl(c, m, &t64, 0); +} + +int +pthread_cond_timedwait64_relative_np(pthread_cond_t *c, pthread_mutex_t *m, const struct _timespec64 *t) { return pthread_cond_timedwait_impl(c, m, t, 1); } +int +pthread_cond_timedwait32_relative_np(pthread_cond_t *c, pthread_mutex_t *m, const struct _timespec32 *t) +{ + struct _timespec64 t64 = {.tv_sec = t->tv_sec, .tv_nsec = t->tv_nsec}; + return pthread_cond_timedwait_impl(c, m, &t64, 1); +} + static void cleanup_wait (void *arg) { diff --git a/mingw-w64-libraries/winpthreads/src/misc.c b/mingw-w64-libraries/winpthreads/src/misc.c index 1e0d6124a..d9c55041e 100644 --- a/mingw-w64-libraries/winpthreads/src/misc.c +++ b/mingw-w64-libraries/winpthreads/src/misc.c @@ -95,7 +95,7 @@ unsigned long long _pthread_time_in_ms(void) - 0x19DB1DED53E8000ULL) / 10000ULL; } -unsigned long long _pthread_time_in_ms_from_timespec(const struct timespec *ts) +unsigned long long _pthread_time_in_ms_from_timespec(const struct _timespec64 *ts) { unsigned long long t = (unsigned long long) ts->tv_sec * 1000LL; /* The +999999 is here to ensure that the division always rounds up */ @@ -104,7 +104,7 @@ unsigned long long _pthread_time_in_ms_from_timespec(const struct timespec *ts) return t; } -unsigned long long _pthread_rel_time_in_ms(const struct timespec *ts) +unsigned long long _pthread_rel_time_in_ms(const struct _timespec64 *ts) { unsigned long long t1 = _pthread_time_in_ms_from_timespec(ts); unsigned long long t2 = _pthread_time_in_ms(); diff --git a/mingw-w64-libraries/winpthreads/src/misc.h b/mingw-w64-libraries/winpthreads/src/misc.h index 75818b473..f954ad451 100644 --- a/mingw-w64-libraries/winpthreads/src/misc.h +++ b/mingw-w64-libraries/winpthreads/src/misc.h @@ -75,8 +75,8 @@ static WINPTHREADS_INLINE unsigned long dwMilliSecs(unsigned long long ms) } unsigned long long _pthread_time_in_ms(void); -unsigned long long _pthread_time_in_ms_from_timespec(const struct timespec *ts); -unsigned long long _pthread_rel_time_in_ms(const struct timespec *ts); +unsigned long long _pthread_time_in_ms_from_timespec(const struct _timespec64 *ts); +unsigned long long _pthread_rel_time_in_ms(const struct _timespec64 *ts); unsigned long _pthread_wait_for_single_object (void *handle, unsigned long timeout); unsigned long _pthread_wait_for_multiple_objects (unsigned long count, void **handles, unsigned int all, unsigned long timeout); diff --git a/mingw-w64-libraries/winpthreads/src/mutex.c b/mingw-w64-libraries/winpthreads/src/mutex.c index 20d881513..b90120976 100644 --- a/mingw-w64-libraries/winpthreads/src/mutex.c +++ b/mingw-w64-libraries/winpthreads/src/mutex.c @@ -32,6 +32,8 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> +#define WINPTHREAD_MUTEX_DECL WINPTHREAD_API + /* public header files */ #include "pthread.h" /* internal header files */ @@ -193,7 +195,8 @@ pthread_mutex_lock (pthread_mutex_t *m) return pthread_mutex_lock_intern (m, INFINITE); } -int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *ts) +/* Internal version which always uses `struct _timespec64`. */ +static int __pthread_mutex_timedlock(pthread_mutex_t *m, const struct _timespec64 *ts) { unsigned long long patience; if (ts != NULL) { @@ -208,6 +211,17 @@ int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *ts) return pthread_mutex_lock_intern(m, patience); } +int pthread_mutex_timedlock64(pthread_mutex_t *m, const struct _timespec64 *ts) +{ + return __pthread_mutex_timedlock (m, ts); +} + +int pthread_mutex_timedlock32(pthread_mutex_t *m, const struct _timespec32 *ts) +{ + struct _timespec64 ts64 = {.tv_sec = ts->tv_sec, .tv_nsec = ts->tv_nsec}; + return __pthread_mutex_timedlock (m, &ts64); +} + int pthread_mutex_unlock(pthread_mutex_t *m) { /* Here m might an initialiser of an error-checking or recursive mutex, in diff --git a/mingw-w64-libraries/winpthreads/src/nanosleep.c b/mingw-w64-libraries/winpthreads/src/nanosleep.c index d1c139088..a81bf2c89 100644 --- a/mingw-w64-libraries/winpthreads/src/nanosleep.c +++ b/mingw-w64-libraries/winpthreads/src/nanosleep.c @@ -8,12 +8,15 @@ #include "config.h" #endif +#include <assert.h> #include <errno.h> #include <time.h> #define WIN32_LEAN_AND_MEAN #include <windows.h> +#define WINPTHREAD_NANOSLEEP_DECL WINPTHREAD_API + /* public header files */ #include "pthread.h" #include "pthread_time.h" @@ -34,7 +37,7 @@ * If the function fails, the return value is -1, * with errno set to indicate the error. */ -int nanosleep(const struct timespec *request, struct timespec *remain) +static int __nanosleep(const struct _timespec64 *request, struct _timespec64 *remain) { unsigned long ms, rc = 0; unsigned __int64 u64, want, real; @@ -78,3 +81,29 @@ int nanosleep(const struct timespec *request, struct timespec *remain) return 0; } + +int nanosleep64(const struct _timespec64 *request, struct _timespec64 *remain) +{ + return __nanosleep (request, remain); +} + +int nanosleep32(const struct _timespec32 *request, struct _timespec32 *remain) +{ + struct _timespec64 request64 = { + .tv_sec = request->tv_sec, + .tv_nsec = request->tv_nsec + }; + struct _timespec64 remain64 = {0}; + + if (__nanosleep (&request64, &remain64) == -1) + return -1; + + assert (remain64.tv_sec <= INT_MAX); + + if (remain != NULL) { + remain->tv_sec = (__time32_t)remain64.tv_sec; + remain->tv_nsec = remain64.tv_nsec; + } + + return 0; +} diff --git a/mingw-w64-libraries/winpthreads/src/rwlock.c b/mingw-w64-libraries/winpthreads/src/rwlock.c index 8aa62ec8a..68ef2a733 100644 --- a/mingw-w64-libraries/winpthreads/src/rwlock.c +++ b/mingw-w64-libraries/winpthreads/src/rwlock.c @@ -31,6 +31,8 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> +#define WINPTHREAD_RWLOCK_DECL WINPTHREAD_API + /* public header files */ #include "pthread.h" /* internal header files */ @@ -262,7 +264,8 @@ int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock_) return rwl_unref(rwlock_, ret); } -int pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock_, const struct timespec *ts) +/* Internal version which always uses `struct _timespec64`. */ +static int __pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock_, const struct _timespec64 *ts) { rwlock_t *rwlock; int ret; @@ -273,12 +276,12 @@ int pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock_, const struct timespec if(ret != 0) return ret; rwlock = (rwlock_t *)*rwlock_; - if ((ret = pthread_mutex_timedlock (&rwlock->mex, ts)) != 0) + if ((ret = pthread_mutex_timedlock64 (&rwlock->mex, ts)) != 0) return rwl_unref(rwlock_, ret); InterlockedIncrement(&rwlock->nsh_count); if (rwlock->nsh_count == INT_MAX) { - ret = pthread_mutex_timedlock(&rwlock->mcomplete, ts); + ret = pthread_mutex_timedlock64(&rwlock->mcomplete, ts); if (ret != 0) { if (ret == ETIMEDOUT) @@ -295,6 +298,17 @@ int pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock_, const struct timespec return rwl_unref(rwlock_, ret); } +int pthread_rwlock_timedrdlock64(pthread_rwlock_t *l, const struct _timespec64 *ts) +{ + return __pthread_rwlock_timedrdlock (l, ts); +} + +int pthread_rwlock_timedrdlock32(pthread_rwlock_t *l, const struct _timespec32 *ts) +{ + struct _timespec64 ts64 = {.tv_sec = ts->tv_sec, .tv_nsec = ts->tv_nsec}; + return __pthread_rwlock_timedrdlock (l, &ts64); +} + int pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock_) { rwlock_t *rwlock; @@ -442,7 +456,8 @@ int pthread_rwlock_wrlock (pthread_rwlock_t *rwlock_) return rwl_unref(rwlock_,ret); } -int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, const struct timespec *ts) +/* Internal version which always uses `struct _timespec64`. */ +static int __pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, const struct _timespec64 *ts) { int ret; rwlock_t *rwlock; @@ -454,10 +469,10 @@ int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, const struct timespec return ret; rwlock = (rwlock_t *)*rwlock_; - ret = pthread_mutex_timedlock(&rwlock->mex, ts); + ret = pthread_mutex_timedlock64(&rwlock->mex, ts); if (ret != 0) return rwl_unref(rwlock_,ret); - ret = pthread_mutex_timedlock (&rwlock->mcomplete, ts); + ret = pthread_mutex_timedlock64(&rwlock->mcomplete, ts); if (ret != 0) { pthread_mutex_unlock(&rwlock->mex); @@ -475,7 +490,7 @@ int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, const struct timespec rwlock->ncomplete = -rwlock->nsh_count; pthread_cleanup_push(st_cancelwrite, (void *) rwlock); do { - ret = pthread_cond_timedwait(&rwlock->ccomplete, &rwlock->mcomplete, ts); + ret = pthread_cond_timedwait64(&rwlock->ccomplete, &rwlock->mcomplete, ts); } while (rwlock->ncomplete < 0 && !ret); pthread_cleanup_pop(!ret ? 0 : 1); @@ -488,6 +503,17 @@ int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, const struct timespec return rwl_unref(rwlock_,ret); } +int pthread_rwlock_timedwrlock64(pthread_rwlock_t *rwlock, const struct _timespec64 *ts) +{ + return __pthread_rwlock_timedwrlock (rwlock, ts); +} + +int pthread_rwlock_timedwrlock32(pthread_rwlock_t *rwlock, const struct _timespec32 *ts) +{ + struct _timespec64 ts64 = {.tv_sec = ts->tv_sec, .tv_nsec = ts->tv_nsec}; + return __pthread_rwlock_timedwrlock (rwlock, &ts64); +} + int pthread_rwlockattr_destroy(pthread_rwlockattr_t *a) { if (!a) diff --git a/mingw-w64-libraries/winpthreads/src/sem.c b/mingw-w64-libraries/winpthreads/src/sem.c index 1226bb829..37abf2e11 100644 --- a/mingw-w64-libraries/winpthreads/src/sem.c +++ b/mingw-w64-libraries/winpthreads/src/sem.c @@ -220,8 +220,9 @@ sem_wait (sem_t *sem) return sem_result (ret); } -int -sem_timedwait (sem_t *sem, const struct timespec *t) +/* Internal version which always uses `struct _timespec64`. */ +static int +__sem_timedwait (sem_t *sem, const struct _timespec64 *t) { int cur_v, ret = 0; DWORD dwr; @@ -259,6 +260,17 @@ sem_timedwait (sem_t *sem, const struct timespec *t) return sem_result (ret); } +int sem_timedwait64(sem_t *sem, const struct _timespec64 *t) +{ + return __sem_timedwait (sem, t); +} + +int sem_timedwait32(sem_t *sem, const struct _timespec32 *t) +{ + struct _timespec64 t64 = {.tv_sec = t->tv_sec, .tv_nsec = t->tv_nsec}; + return __sem_timedwait (sem, &t64); +} + int sem_post (sem_t *sem) { diff --git a/mingw-w64-libraries/winpthreads/src/thread.c b/mingw-w64-libraries/winpthreads/src/thread.c index e13704bb6..155d96ebe 100644 --- a/mingw-w64-libraries/winpthreads/src/thread.c +++ b/mingw-w64-libraries/winpthreads/src/thread.c @@ -34,6 +34,8 @@ #include <windows.h> #include <strsafe.h> +#define WINPTHREAD_THREAD_DECL WINPTHREAD_API + /* public header files */ #include "pthread.h" /* internal header files */ @@ -658,8 +660,8 @@ pthread_timechange_handler_np(void *dummy) /* Compatibility routine for pthread-win32. It waits for ellapse of interval and additionally checks for possible thread-cancelation. */ -int -pthread_delay_np (const struct timespec *interval) +static int +__pthread_delay_np (const struct _timespec64 *interval) { DWORD to = (!interval ? 0 : dwMilliSecs (_pthread_time_in_ms_from_timespec (interval))); struct _pthread_v *s = __pthread_self_lite (); @@ -680,6 +682,19 @@ pthread_delay_np (const struct timespec *interval) return 0; } +int +pthread_delay64_np (const struct _timespec64 *interval) +{ + return __pthread_delay_np(interval); +} + +int +pthread_delay32_np (const struct _timespec32 *interval) +{ + struct _timespec64 interval64 = {.tv_sec = interval->tv_sec, .tv_nsec = interval->tv_nsec}; + return __pthread_delay_np(&interval64); +} + int _pthread_delay_np_ms (DWORD to) { -- 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