Skip to content

Commit 9d44a7e

Browse files
authored
Merge branch 'GerHobbelt:master' into master
2 parents dcd2936 + 3309f4d commit 9d44a7e

31 files changed

+3745
-25
lines changed

ChangeLog.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ pre-merge-with-mingw-patches / Wed, 30 Mar 2016
467467
* [b9afb8d2] Move recently incorrectly placed comment. (`Ross Johnson`)
468468
* [9f8c38b1] Version 2.9.0 last changes. (`Ross Johnson`)
469469
* [7452bc46] callbacks defined as cdecl (`Ross Johnson`)
470-
* [473862a0] Fix MSC_VER related to item 2 in BUGS (`rpj`)
470+
* [473862a0] Fix _MSC_VER related to item 2 in BUGS (`rpj`)
471471
* [b83397a7] Remove compile warning; fix bug (`rpj`)
472472
* [07078828] *** empty log message *** (`rpj`)
473473
* [d0616e87] Reorganisation of #defines (`rpj`)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# pthread-win32 for Windows
2+
# pthread-win32 for Windows (a.k.a. pthreads4W)
33

44
Combined `pthread-win32` fork of RedFox20 + Oktonion + WinBuild
55

create.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pthread_create (pthread_t * tid,
9393
pthread_t thread = { 0 }; // init to shut up MSVC2013: warning C4701 : potentially uninitialized local variable 'thread' used
9494
ptw32_thread_t * tp;
9595
ptw32_thread_t * sp;
96-
register pthread_attr_t a;
96+
pthread_attr_t a;
9797
HANDLE threadH = 0;
9898
int result = EAGAIN;
9999
int run = PTW32_TRUE;

docs/ChangeLog.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2399,7 +2399,7 @@ General Note:
23992399
2011-07-06 Ross Johnson <ross dot johnson at homemail dot com dot au>
24002400

24012401
* pthread_cond_wait.c (pragma inline_depth): this is almost redundant
2402-
now nevertheless fixed thei controlling MSC_VER from "< 800" to
2402+
now nevertheless fixed thei controlling _MSC_VER from "< 800" to
24032403
"< 1400" (i.e. any prior to VC++ 8.0).
24042404
* pthread_once.ci (pragma inline_depth): Likewise.
24052405
* pthread_rwlock_timedwrlock.ci (pragma inline_depth): Likewise.
@@ -5034,7 +5034,7 @@ General Note:
50345034
2000-08-12 Ross Johnson <rpj at special.ise.canberra.edu.au>
50355035

50365036
* pthread.h: Add compile-time message when using
5037-
MSC_VER compiler and C++ EH to warn application
5037+
_MSC_VER compiler and C++ EH to warn application
50385038
programmers to use __PtW32Catch instead of catch(...)
50395039
if they want cancellation and pthread_exit to work.
50405040

implement.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ struct ptw32_thread_t_
251251
int sched_priority; /* As set, not as currently is */
252252
int cancelState;
253253
int cancelType;
254-
int implicit:1;
254+
unsigned int implicit:1;
255255
DWORD thread; /* Windows thread ID */
256256
#if defined(HAVE_CPU_AFFINITY)
257257
size_t cpuset; /* Thread CPU affinity set */
@@ -788,7 +788,11 @@ char *ptw32_strdup (const char *s);
788788
#endif
789789
void ptw32_throw (DWORD exception)
790790
#if defined(__cplusplus)
791+
#if __cplusplus <= 201402L
791792
throw(ptw32_exception_cancel,ptw32_exception_exit)
793+
#else
794+
noexcept(false)
795+
#endif
792796
#endif
793797
;
794798

pthread.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@
103103
#undef PTW32_LEVEL_MAX
104104
#define PTW32_LEVEL_MAX 3
105105

106-
#if _POSIX_C_SOURCE >= 200112L /* POSIX.1-2001 and later */
106+
#if defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 200112L /* POSIX.1-2001 and later */
107107
# define PTW32_LEVEL PTW32_LEVEL_MAX /* include everything */
108108

109109
#elif defined INCLUDE_NP /* earlier than POSIX.1-2001, but... */
110110
# define PTW32_LEVEL 2 /* include non-portable extensions */
111111

112-
#elif _POSIX_C_SOURCE >= 199309L /* POSIX.1-1993 */
112+
#elif defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 199309L /* POSIX.1-1993 */
113113
# define PTW32_LEVEL 1 /* include 1b, 1c, and 1d */
114114

115115
#elif defined _POSIX_SOURCE /* early POSIX */
@@ -654,6 +654,8 @@ struct ptw32_cleanup_t
654654

655655
#if defined(PTW32_CLEANUP_CXX)
656656

657+
#if defined(__cplusplus)
658+
657659
/*
658660
* C++ version of cancel cleanup.
659661
* - John E. Bossom.
@@ -728,6 +730,8 @@ struct ptw32_cleanup_t
728730
cleanup.execute( _execute ); \
729731
}
730732

733+
#endif // __cplusplus
734+
731735
#else
732736

733737
#error ERROR [__FILE__, line __LINE__]: Cleanup type undefined.

pthread_getspecific.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ pthread_getspecific (pthread_key_t key)
7878
}
7979
else
8080
{
81-
int lasterror = GetLastError ();
81+
DWORD lasterror = GetLastError ();
8282
#if defined(RETAIN_WSALASTERROR)
83-
int lastWSAerror = WSAGetLastError ();
83+
DWORD lastWSAerror = WSAGetLastError ();
8484
#endif
8585
ptr = TlsGetValue (key->key);
8686

pthread_spin_destroy.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
int
4949
pthread_spin_destroy (pthread_spinlock_t * lock)
5050
{
51-
register pthread_spinlock_t s;
51+
pthread_spinlock_t s;
5252
int result = 0;
5353

5454
if (lock == NULL || *lock == NULL)

pthread_spin_lock.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
int
4949
pthread_spin_lock (pthread_spinlock_t * lock)
5050
{
51-
register pthread_spinlock_t s;
51+
pthread_spinlock_t s;
5252

5353
if (NULL == lock || NULL == *lock)
5454
{

pthread_spin_trylock.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
int
4949
pthread_spin_trylock (pthread_spinlock_t * lock)
5050
{
51-
register pthread_spinlock_t s;
51+
pthread_spinlock_t s;
5252

5353
if (NULL == lock || NULL == *lock)
5454
{

pthread_spin_unlock.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
int
4949
pthread_spin_unlock (pthread_spinlock_t * lock)
5050
{
51-
register pthread_spinlock_t s;
51+
pthread_spinlock_t s;
5252

5353
if (NULL == lock || NULL == *lock)
5454
{

ptw32_mutex_check_need_init.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ static pthread_mutexattr_t ptw32_errorcheck_mutexattr = &ptw32_errorcheck_mutexa
5555
INLINE int
5656
ptw32_mutex_check_need_init (pthread_mutex_t * mutex)
5757
{
58-
register int result = 0;
59-
register pthread_mutex_t mtx;
58+
int result = 0;
59+
pthread_mutex_t mtx;
6060
ptw32_mcs_local_node_t node;
6161

6262
ptw32_mcs_lock_acquire(&ptw32_mutex_test_init_lock, &node);

sched.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656
*/
5757
#if ! defined __MINGW32__ || ! defined __have_typedef_pid_t
5858

59-
# if defined __MINGW64__
59+
# if defined __MINGW64__ || defined WIN64 || defined _WIN64
6060
typedef __int64 pid_t;
6161
# else
6262
typedef int pid_t;
6363
#endif
6464

65-
#if __GNUC__ < 4
65+
#if ! defined __GNUC__ || __GNUC__ < 4
6666
/* GCC v4.0 and later, (as used by MinGW), allows us to repeat a
6767
* typedef, provided every duplicate is consistent; only set this
6868
* multiple definition guard when we cannot be certain that it is

sem_getvalue.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ sem_getvalue (sem_t * sem, int *sval)
8787
int result = 0;
8888

8989
ptw32_mcs_local_node_t node;
90-
register sem_t s = *sem;
90+
sem_t s = *sem;
9191

9292
ptw32_mcs_lock_acquire(&s->lock, &node);
9393
*sval = s->value;

tests/benchlib.c

+7
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ old_mutex_init(old_mutex_t *mutex, const old_mutexattr_t *attr)
109109
{
110110
CRITICAL_SECTION cs;
111111

112+
#if (_WIN32_WINNT >= 0x0400)
113+
ptw32_try_enter_critical_section = &TryEnterCriticalSection;
114+
#else
112115
/*
113116
* Load KERNEL32 and try to get address of TryEnterCriticalSection
114117
*/
@@ -121,6 +124,7 @@ old_mutex_init(old_mutex_t *mutex, const old_mutexattr_t *attr)
121124
#else
122125
GetProcAddress(ptw32_h_kernel32,
123126
(LPCSTR) "TryEnterCriticalSection");
127+
#endif
124128
#endif
125129

126130
if (ptw32_try_enter_critical_section != NULL)
@@ -140,11 +144,14 @@ old_mutex_init(old_mutex_t *mutex, const old_mutexattr_t *attr)
140144
DeleteCriticalSection(&cs);
141145
}
142146

147+
#if (_WIN32_WINNT >= 0x0400)
148+
#else
143149
if (ptw32_try_enter_critical_section == NULL)
144150
{
145151
(void) FreeLibrary(ptw32_h_kernel32);
146152
ptw32_h_kernel32 = 0;
147153
}
154+
#endif
148155

149156
if (old_mutex_use == OLD_WIN32CS)
150157
{

tests/context2.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ static void * func(void * arg)
100100
{
101101
washere = 1;
102102

103-
return (void *) tree(64);
103+
void *rv = (void *) tree(64);
104+
fprintf(stderr, "func: done\n");
105+
return rv;
104106
}
105107

106108
static void
@@ -110,6 +112,7 @@ anotherEnding ()
110112
* Switched context
111113
*/
112114
washere++;
115+
fprintf(stderr, "another ending!\n");
113116
pthread_exit(0);
114117
}
115118

@@ -144,6 +147,8 @@ test_context2(void)
144147
*/
145148
CONTEXT context;
146149

150+
fprintf(stderr, "wait: done\n");
151+
147152
context.ContextFlags = CONTEXT_CONTROL;
148153

149154
GetThreadContext(hThread, &context);
@@ -160,6 +165,7 @@ test_context2(void)
160165
Sleep(1000);
161166

162167
assert(washere == 2);
168+
fprintf(stderr, "assertion check: done\n");
163169

164170
return 0;
165171
}

tests/create3.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ static void * func(void * arg)
8888

8989
#ifndef MONOLITHIC_PTHREAD_TESTS
9090
int
91-
main(int argc, char **argv)
91+
main(void)
9292
#else
9393
int
94-
test_create3(int argc, char **argv)
94+
test_create3(void)
9595
#endif
9696
{
9797
pthread_t t;

tests/test.h

+6
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,13 @@ static const char * error_string[] = {
162162
(fprintf(stderr, "Assertion failed: (%s), file %s, line %d\n", \
163163
#e, __FILE__, (int) __LINE__), exit(1), 0))
164164

165+
#if defined(PTW32_CLEANUP_CXX) && defined(__PTHREAD_JUMBO_BUILD__) && defined(MONOLITHIC_PTHREAD_TESTS)
166+
// fix/hack the error about duplicate definitions of the assertion code in (forced) C++ mode (for pthread-EH.cpp); this does NOT affect the other build modes; the default build mode remains as-is.
167+
extern int assertE;
168+
#else
165169
int assertE;
170+
#endif
171+
166172
# define assert_e(e, o, r) \
167173
(((assertE = e) o (r)) ? ((ASSERT_TRACE) ? fprintf(stderr, \
168174
"Assertion succeeded: (%s), file %s, line %d\n", \

tests/tryentercs.c

+7
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ test_tryentercs(void)
8080

8181
printf("Last Error [main enter] %ld\n", (long) GetLastError());
8282

83+
#if (_WIN32_WINNT >= 0x0400)
84+
_try_enter_critical_section = &TryEnterCriticalSection;
85+
#else
8386
/*
8487
* Load KERNEL32 and try to get address of TryEnterCriticalSection
8588
*/
@@ -88,6 +91,7 @@ test_tryentercs(void)
8891
(TryEnterCriticalSection_f *)
8992
GetProcAddress(_h_kernel32,
9093
(LPCSTR) "TryEnterCriticalSection");
94+
#endif
9195

9296
if (_try_enter_critical_section != NULL)
9397
{
@@ -108,7 +112,10 @@ test_tryentercs(void)
108112
DeleteCriticalSection(&cs);
109113
}
110114

115+
#if (_WIN32_WINNT >= 0x0400)
116+
#else
111117
(void) FreeLibrary(_h_kernel32);
118+
#endif
112119

113120
printf("This system %s TryEnterCriticalSection.\n",
114121
(_try_enter_critical_section == NULL) ? "DOES NOT SUPPORT" : "SUPPORTS");

tests/tryentercs2.c

+7
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ test_tryentercs2(void)
8080

8181
printf("Last Error [main enter] %ld\n", (long) GetLastError());
8282

83+
#if (_WIN32_WINNT >= 0x0400)
84+
_try_enter_critical_section = &TryEnterCriticalSection;
85+
#else
8386
/*
8487
* Load KERNEL32 and try to get address of TryEnterCriticalSection
8588
*/
@@ -88,6 +91,7 @@ test_tryentercs2(void)
8891
(TryEnterCriticalSection_f *)
8992
GetProcAddress(_h_kernel32,
9093
(LPCSTR) "TryEnterCriticalSection");
94+
#endif
9195

9296
if (_try_enter_critical_section != NULL)
9397
{
@@ -121,7 +125,10 @@ test_tryentercs2(void)
121125
printf("Last Error [try enter] %ld\n", (long) GetLastError());
122126
}
123127

128+
#if (_WIN32_WINNT >= 0x0400)
129+
#else
124130
(void) FreeLibrary(_h_kernel32);
131+
#endif
125132

126133
printf("This system %s TryEnterCriticalSection.\n",
127134
(_try_enter_critical_section == NULL) ? "DOES NOT SUPPORT" : "SUPPORTS");

tests/wrapper4tests_1.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
#include <windows.h>
1212

1313

14+
#if defined(BUILD_MONOLITHIC)
15+
#define main pthw32_all_tests_main
16+
#endif
17+
18+
1419
#ifndef MONOLITHIC_PTHREAD_TESTS
1520

1621
int main(int argc, char **argv)
@@ -20,6 +25,11 @@ int main(int argc, char **argv)
2025

2126
#else
2227

28+
// fix/hack the error about duplicate definitions of the assertion code in (forced) C++ mode (for pthread-EH.cpp); this does NOT affect the other build modes; the default build mode remains as-is.
29+
#if defined(PTW32_CLEANUP_CXX) && defined(__PTHREAD_JUMBO_BUILD__)
30+
int assertE;
31+
#endif
32+
2333
int test_affinity1(void);
2434
int test_affinity2(void);
2535
int test_affinity3(void);
@@ -276,7 +286,6 @@ int main(int argc, char **argv)
276286
TEST_WRAPPER(test_condvar7);
277287
TEST_WRAPPER(test_condvar9);
278288
TEST_WRAPPER(test_exception1);
279-
TEST_WRAPPER(test_sequence1);
280289

281290
TEST_WRAPPER(test_affinity1);
282291
TEST_WRAPPER(test_affinity2);
@@ -321,7 +330,7 @@ int main(int argc, char **argv)
321330
TEST_WRAPPER(test_condvar8);
322331
// TEST_WRAPPER(test_condvar9);
323332
TEST_WRAPPER(test_context1);
324-
TEST_WRAPPER(test_context2);
333+
// TEST_WRAPPER(test_context2); // fails in MSVC2022; probably stack corruption at process_exit() as this example hard-swaps PC (program counter) register while resuming...
325334
TEST_WRAPPER(test_count1);
326335
TEST_WRAPPER(test_create1);
327336
TEST_WRAPPER(test_create2);
@@ -421,6 +430,7 @@ int main(int argc, char **argv)
421430
TEST_WRAPPER(test_semaphore4t);
422431
TEST_WRAPPER(test_semaphore5);
423432
// TEST_WRAPPER(test_sequence1);
433+
// TEST_WRAPPER(test_sequence2);
424434
TEST_WRAPPER(test_sizes);
425435
TEST_WRAPPER(test_spin1);
426436
TEST_WRAPPER(test_spin2);

0 commit comments

Comments
 (0)