summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTORS6
-rw-r--r--ChangeLog7
-rw-r--r--Makefile34
-rw-r--r--NEWS4
-rw-r--r--implement.h30
-rw-r--r--ptw32_MCS_lock.c24
-rw-r--r--tests/ChangeLog6
-rw-r--r--tests/Makefile6
-rw-r--r--tests/benchtest1.c9
-rw-r--r--tests/benchtest2.c9
-rw-r--r--tests/benchtest3.c9
-rw-r--r--tests/benchtest4.c9
-rw-r--r--tests/benchtest5.c9
-rw-r--r--tests/condvar2.c6
-rw-r--r--tests/condvar2_1.c6
-rw-r--r--tests/condvar3.c6
-rw-r--r--tests/condvar3_1.c6
-rw-r--r--tests/condvar3_2.c6
-rw-r--r--tests/condvar3_3.c6
-rw-r--r--tests/condvar4.c6
-rw-r--r--tests/condvar5.c6
-rw-r--r--tests/condvar6.c6
-rw-r--r--tests/condvar7.c8
-rw-r--r--tests/condvar8.c6
-rw-r--r--tests/condvar9.c6
-rw-r--r--tests/mutex8.c6
-rw-r--r--tests/mutex8e.c6
-rw-r--r--tests/mutex8n.c6
-rw-r--r--tests/mutex8r.c6
-rwxr-xr-xtests/openmp1.c40
-rw-r--r--tests/rwlock2_t.c6
-rw-r--r--tests/rwlock3_t.c6
-rw-r--r--tests/rwlock4_t.c6
-rw-r--r--tests/rwlock5_t.c6
-rw-r--r--tests/rwlock6_t.c6
-rw-r--r--tests/rwlock6_t2.c6
-rw-r--r--tests/rwlock7.c9
-rw-r--r--tests/rwlock8.c9
-rw-r--r--tests/semaphore1.c32
-rw-r--r--tests/spin4.c9
-rw-r--r--tests/stress1.c6
-rw-r--r--tests/test.h14
42 files changed, 155 insertions, 260 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 905f38e..da31ff2 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -131,6 +131,10 @@ Vladimir Kliatchko vladimir at kliatchko dot com
Ramiro Polla ramiro.polla at gmail dot com
static library auto init/cleanup on application
start/exit via RT hooks (MSC and GCC compilers only).
+Daniel Richard G. skunk at iSKUNK dot org
+ Patches and cleanups for x86 and x64, particularly
+ across a range of MS build environments.
John Kamp john dot kamp at globalgraphics dot com
- Patches to fix various problems on x64.
+ Patches to fix various problems on x64; brutal testing
+ particularly using high memory run environments.
diff --git a/ChangeLog b/ChangeLog
index d439553..ee35762 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-07-02 Daniel Richard G. <skunk at iskunk dot org>
+
+ * Makefile: Cleanups and implovements.
+ * ptw32_MCS_locks.c: Casting fixes.
+ * implement.h: Interlocked call and argument casting macro fixes
+ to support older and newer build environments.
+
2011-07-01 Ross Johnson <ross dot johnson at homemail dot com dot au>
* *.[ch] (PTW32_INTERLOCKED_*): Redo 23 and 64 bit versions of these
diff --git a/Makefile b/Makefile
index 5bc5f29..97a65ec 100644
--- a/Makefile
+++ b/Makefile
@@ -13,9 +13,9 @@ DLL_VERD= $(DLL_VER)d
DEVROOT = C:\pthreads
-DLLDEST = $(DEVROOT)\DLL
-LIBDEST = $(DEVROOT)\LIB
-HDRDEST = $(DEVROOT)\INCLUDE
+DLLDEST = $(DEVROOT)\dll
+LIBDEST = $(DEVROOT)\lib
+HDRDEST = $(DEVROOT)\include
DLLS = pthreadVCE$(DLL_VER).dll pthreadVSE$(DLL_VER).dll pthreadVC$(DLL_VER).dll \
pthreadVCE$(DLL_VERD).dll pthreadVSE$(DLL_VERD).dll pthreadVC$(DLL_VERD).dll
@@ -28,24 +28,28 @@ OPTIM = /O2 /Ob2
OPTIMD =
CC = cl
-CFLAGS = /W3 /MD /nologo /I. /D_WIN32_WINNT=0x400 /DHAVE_PTW32_CONFIG_H
+#CFLAGS = /W3 /MD /nologo /I. /D_WIN32_WINNT=0x400 /DHAVE_PTW32_CONFIG_H
+CPPFLAGS = /I. /D_WIN32_WINNT=0x400 /DHAVE_PTW32_CONFIG_H
+CFLAGS = /W3 /MD /nologo
CFLAGSD = /Z7 $(CFLAGS)
# Uncomment this if config.h defines RETAIN_WSALASTERROR
#XLIBS = wsock32.lib
+CRTLIBS = /nodefaultlib:libcmt msvcrt.lib
+
# Default cleanup style
CLEANUP = __CLEANUP_C
# C++ Exceptions
-VCEFLAGS = /EHsc /TP $(CFLAGS)
-VCEFLAGSD = /EHsc /TP $(CFLAGSD)
+VCEFLAGS = /EHsc /TP $(CPPFLAGS) $(CFLAGS)
+VCEFLAGSD = /EHsc /TP $(CPPFLAGS) $(CFLAGSD)
#Structured Exceptions
-VSEFLAGS = $(CFLAGS)
-VSEFLAGSD = $(CFLAGSD)
+VSEFLAGS = $(CPPFLAGS) $(CFLAGS)
+VSEFLAGSD = $(CPPFLAGS) $(CFLAGSD)
#C cleanup code
-VCFLAGS = $(CFLAGS)
-VCFLAGSD= $(CFLAGSD)
+VCFLAGS = $(CPPFLAGS) $(CFLAGS)
+VCFLAGSD = $(CPPFLAGS) $(CFLAGSD)
DLL_INLINED_OBJS = \
pthread.obj \
@@ -468,7 +472,7 @@ clean:
if exist *.res del *.res
-install: $(DLLS)
+install:
copy pthread*.dll $(DLLDEST)
copy pthread*.lib $(LIBDEST)
copy pthread.h $(HDRDEST)
@@ -476,14 +480,10 @@ install: $(DLLS)
copy semaphore.h $(HDRDEST)
$(DLLS): $(DLL_OBJS)
- $(CC) /LDd /Zi /nologo $(DLL_OBJS) \
- /link /nodefaultlib:libcmt /implib:$*.lib \
- msvcrt.lib $(XLIBS) /out:$@
+ $(CC) /LDd /Zi /nologo $(DLL_OBJS) /link /implib:$*.lib $(CRTLIBS) $(XLIBS) /out:$@
$(INLINED_STAMPS): $(DLL_INLINED_OBJS)
- $(CC) /LDd /Zi /nologo $(DLL_INLINED_OBJS) \
- /link /nodefaultlib:libcmt /implib:$*.lib \
- msvcrt.lib $(XLIBS) /out:$*.dll
+ $(CC) /LDd /Zi /nologo $(DLL_INLINED_OBJS) /link /implib:$*.lib $(CRTLIBS) $(XLIBS) /out:$*.dll
$(STATIC_STAMPS): $(DLL_INLINED_OBJS)
if exist $*.lib del $*.lib
diff --git a/NEWS b/NEWS
index ebc3e4a..f39c587 100644
--- a/NEWS
+++ b/NEWS
@@ -101,6 +101,10 @@ and SEH builds only). Uncaught exceptions now cause the thread to exit with
the return code PTHREAD_CANCELED.
- Ross Johnson
+Lots of casting fixes particularly for x64, Interlocked fixes and reworking
+for x64.
+- Daniel Richard G., John Kamp
+
Other changes
-------------
Dependence on the winsock library is now discretionary via
diff --git a/implement.h b/implement.h
index bae4bff..5344505 100644
--- a/implement.h
+++ b/implement.h
@@ -85,13 +85,21 @@ typedef VOID (APIENTRY *PAPCFUNC)(DWORD dwParam);
#else
#define INLINE
#endif
+#if defined(_MSC_VER) && _MSC_VER < 1300
+/*
+ * MSVC 6 does not use the "volatile" qualifier
+ */
+#define VOLATILE
+#else
+#define VOLATILE volatile
+#endif
#define PTW32_INTERLOCKED_LONG long
#define PTW32_INTERLOCKED_SIZE size_t
-#define PTW32_INTERLOCKED_LONGPTR volatile long*
-#define PTW32_INTERLOCKED_SIZEPTR volatile size_t*
#define PTW32_INTERLOCKED_PVOID PVOID
-#define PTW32_INTERLOCKED_PVOID_PTR volatile PVOID*
+#define PTW32_INTERLOCKED_LONGPTR VOLATILE long*
+#define PTW32_INTERLOCKED_SIZEPTR VOLATILE size_t*
+#define PTW32_INTERLOCKED_PVOID_PTR VOLATILE PVOID*
#if defined(__MINGW64__) || defined(__MINGW32__)
# include <stdint.h>
@@ -139,7 +147,7 @@ struct ptw32_thread_t_
HANDLE threadH; /* Win32 thread handle - POSIX thread is invalid if threadH == 0 */
pthread_t ptHandle; /* This thread's permanent pthread_t handle */
ptw32_thread_t * prevReuse; /* Links threads on reuse stack */
- volatile PThreadState state;
+ VOLATILE PThreadState state;
ptw32_mcs_lock_t threadLock; /* Used for serialised access to public thread state */
ptw32_mcs_lock_t stateLock; /* Used for async-cancel safety */
HANDLE cancelEvent;
@@ -875,16 +883,20 @@ extern "C"
# define PTW32_INTERLOCKED_INCREMENT_64 InterlockedIncrement64
# define PTW32_INTERLOCKED_DECREMENT_64 InterlockedDecrement64
# endif
-# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG InterlockedCompareExchange
+# if defined(_MSC_VER) && _MSC_VER < 1300 && !defined(_WIN64) /* MSVC 6 */
+# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG(location, value, comparand) \
+ ((LONG)InterlockedCompareExchange((PVOID *)(location), (PVOID)(value), (PVOID)(comparand)))
+# else
+# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG InterlockedCompareExchange
+# endif
# define PTW32_INTERLOCKED_EXCHANGE_LONG InterlockedExchange
# define PTW32_INTERLOCKED_EXCHANGE_ADD_LONG InterlockedExchangeAdd
# define PTW32_INTERLOCKED_INCREMENT_LONG InterlockedIncrement
# define PTW32_INTERLOCKED_DECREMENT_LONG InterlockedDecrement
-# if defined(_MSC_VER) && _MSC_VER < 1300
-# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR(location, value, comparand) \
- InterlockedCompareExchange((LONG*)location, (LONG)value, (LONG)comparand)
+# if defined(_MSC_VER) && _MSC_VER < 1300 && !defined(_WIN64) /* MSVC 6 */
+# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR InterlockedCompareExchange
# define PTW32_INTERLOCKED_EXCHANGE_PTR(location, value) \
- InterlockedExchange((LONG*)location, (LONG)value)
+ ((PVOID)InterlockedExchange((LPLONG)(location), (LONG)(value)))
# else
# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR InterlockedCompareExchangePointer
# define PTW32_INTERLOCKED_EXCHANGE_PTR InterlockedExchangePointer
diff --git a/ptw32_MCS_lock.c b/ptw32_MCS_lock.c
index 3a85c1b..d69cf80 100644
--- a/ptw32_MCS_lock.c
+++ b/ptw32_MCS_lock.c
@@ -165,8 +165,8 @@ ptw32_mcs_lock_acquire (ptw32_mcs_lock_t * lock, ptw32_mcs_local_node_t * node)
node->next = 0; /* initially, no successor */
/* queue for the lock */
- pred = (ptw32_mcs_local_node_t *)PTW32_INTERLOCKED_EXCHANGE_PTR((PVOID volatile *)lock,
- (PVOID) node);
+ pred = (ptw32_mcs_local_node_t *)PTW32_INTERLOCKED_EXCHANGE_PTR((PTW32_INTERLOCKED_PVOID_PTR)lock,
+ (PTW32_INTERLOCKED_PVOID)node);
if (0 != pred)
{
@@ -201,9 +201,9 @@ ptw32_mcs_lock_release (ptw32_mcs_local_node_t * node)
/* no known successor */
if (node == (ptw32_mcs_local_node_t *)
- PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR((PVOID volatile *)lock,
- (PVOID)0,
- (PVOID)node))
+ PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR((PTW32_INTERLOCKED_PVOID_PTR)lock,
+ (PTW32_INTERLOCKED_PVOID)0,
+ (PTW32_INTERLOCKED_PVOID)node))
{
/* no successor, lock is free now */
return;
@@ -233,10 +233,10 @@ ptw32_mcs_lock_try_acquire (ptw32_mcs_lock_t * lock, ptw32_mcs_local_node_t * no
node->readyFlag = 0;
node->next = 0; /* initially, no successor */
- return ((PVOID)PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR((PVOID volatile *)lock,
- (PVOID)node,
- (PVOID)0)
- == (PVOID)0) ? 0 : EBUSY;
+ return ((PTW32_INTERLOCKED_PVOID)PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR((PTW32_INTERLOCKED_PVOID_PTR)lock,
+ (PTW32_INTERLOCKED_PVOID)node,
+ (PTW32_INTERLOCKED_PVOID)0)
+ == (PTW32_INTERLOCKED_PVOID)0) ? 0 : EBUSY;
}
/*
@@ -261,9 +261,9 @@ ptw32_mcs_node_transfer (ptw32_mcs_local_node_t * new_node, ptw32_mcs_local_node
new_node->readyFlag = 0; /* Not needed - we were waiting on this */
new_node->next = 0;
- if ((ptw32_mcs_local_node_t *)PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR((PVOID volatile *)new_node->lock,
- (PVOID)new_node,
- (PVOID)old_node)
+ if ((ptw32_mcs_local_node_t *)PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR((PTW32_INTERLOCKED_PVOID_PTR)new_node->lock,
+ (PTW32_INTERLOCKED_PVOID)new_node,
+ (PTW32_INTERLOCKED_PVOID)old_node)
!= old_node)
{
/*
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 342c0c8..803b4dc 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,9 @@
+2011-07-02 Daniel Richard G. <skunk at iskunk dot org>
+
+ * *.[ch]: Cleanups around timeb struct, mainly centralising
+ macro definitions in test.h.
+ * Makefile: Fix annoying nmake warning.
+
2011-06-30 Ross Johnson <ross.johnson at homemail.com.au>
* sequence1.c: Fix loop overrun.
diff --git a/tests/Makefile b/tests/Makefile
index 4164e1e..cb4cacb 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -81,7 +81,9 @@ EHFLAGS =
# If a test case returns a non-zero exit code to the shell, make will
# stop.
-PASSES= sizes.pass loadfree.pass \
+PASSES = sizes.pass $(REGULAR_PASSES)
+
+REGULAR_PASSES = loadfree.pass \
self1.pass mutex5.pass \
mutex1.pass mutex1n.pass mutex1e.pass mutex1r.pass \
semaphore1.pass semaphore2.pass semaphore3.pass \
@@ -213,7 +215,7 @@ sizes.pass: sizes.exe
@ $(ECHO) ...... Passed
@ $(TOUCH) $*.pass
-$(PASSES): $*.exe
+$(REGULAR_PASSES): $*.exe
@ $(ECHO) ... Running $(TEST) test: $*.exe
@ .\$*.exe
@ $(ECHO) ...... Passed
diff --git a/tests/benchtest1.c b/tests/benchtest1.c
index 4184719..191f986 100644
--- a/tests/benchtest1.c
+++ b/tests/benchtest1.c
@@ -53,13 +53,8 @@
pthread_mutex_t mx;
pthread_mutexattr_t ma;
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTimeStart;
- struct __timeb64 currSysTimeStop;
-#else
- struct _timeb currSysTimeStart;
- struct _timeb currSysTimeStop;
-#endif
+PTW32_STRUCT_TIMEB currSysTimeStart;
+PTW32_STRUCT_TIMEB currSysTimeStop;
long durationMilliSecs;
long overHeadMilliSecs = 0;
int two = 2;
diff --git a/tests/benchtest2.c b/tests/benchtest2.c
index 28e1cfe..10f3d0e 100644
--- a/tests/benchtest2.c
+++ b/tests/benchtest2.c
@@ -60,13 +60,8 @@ CRITICAL_SECTION cs1, cs2;
pthread_mutexattr_t ma;
long durationMilliSecs;
long overHeadMilliSecs = 0;
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTimeStart;
- struct __timeb64 currSysTimeStop;
-#else
- struct _timeb currSysTimeStart;
- struct _timeb currSysTimeStop;
-#endif
+PTW32_STRUCT_TIMEB currSysTimeStart;
+PTW32_STRUCT_TIMEB currSysTimeStop;
pthread_t worker;
int running = 0;
diff --git a/tests/benchtest3.c b/tests/benchtest3.c
index 1b6e823..7d03ed8 100644
--- a/tests/benchtest3.c
+++ b/tests/benchtest3.c
@@ -54,13 +54,8 @@
pthread_mutex_t mx;
old_mutex_t ox;
pthread_mutexattr_t ma;
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTimeStart;
- struct __timeb64 currSysTimeStop;
-#else
- struct _timeb currSysTimeStart;
- struct _timeb currSysTimeStop;
-#endif
+PTW32_STRUCT_TIMEB currSysTimeStart;
+PTW32_STRUCT_TIMEB currSysTimeStop;
long durationMilliSecs;
long overHeadMilliSecs = 0;
diff --git a/tests/benchtest4.c b/tests/benchtest4.c
index d64cd4a..d7cf47c 100644
--- a/tests/benchtest4.c
+++ b/tests/benchtest4.c
@@ -54,13 +54,8 @@
pthread_mutex_t mx;
old_mutex_t ox;
pthread_mutexattr_t ma;
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTimeStart;
- struct __timeb64 currSysTimeStop;
-#else
- struct _timeb currSysTimeStart;
- struct _timeb currSysTimeStop;
-#endif
+PTW32_STRUCT_TIMEB currSysTimeStart;
+PTW32_STRUCT_TIMEB currSysTimeStop;
long durationMilliSecs;
long overHeadMilliSecs = 0;
diff --git a/tests/benchtest5.c b/tests/benchtest5.c
index 83d59c1..d262baf 100644
--- a/tests/benchtest5.c
+++ b/tests/benchtest5.c
@@ -53,13 +53,8 @@
sem_t sema;
HANDLE w32sema;
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTimeStart;
- struct __timeb64 currSysTimeStop;
-#else
- struct _timeb currSysTimeStart;
- struct _timeb currSysTimeStop;
-#endif
+PTW32_STRUCT_TIMEB currSysTimeStart;
+PTW32_STRUCT_TIMEB currSysTimeStop;
long durationMilliSecs;
long overHeadMilliSecs = 0;
int one = 1;
diff --git a/tests/condvar2.c b/tests/condvar2.c
index dd9851b..6e2fa52 100644
--- a/tests/condvar2.c
+++ b/tests/condvar2.c
@@ -87,11 +87,7 @@ int
main()
{
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
assert(pthread_cond_init(&cv, NULL) == 0);
diff --git a/tests/condvar2_1.c b/tests/condvar2_1.c
index 7607abd..3486d21 100644
--- a/tests/condvar2_1.c
+++ b/tests/condvar2_1.c
@@ -106,11 +106,7 @@ main()
int i;
pthread_t t[NUMTHREADS + 1];
void* result = (void*)0;
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
assert(pthread_cond_init(&cv, NULL) == 0);
diff --git a/tests/condvar3.c b/tests/condvar3.c
index 0a6c152..056334b 100644
--- a/tests/condvar3.c
+++ b/tests/condvar3.c
@@ -112,11 +112,7 @@ main()
{
pthread_t t[NUMTHREADS];
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
assert((t[0] = pthread_self()).p != NULL);
diff --git a/tests/condvar3_1.c b/tests/condvar3_1.c
index bc539d5..33baeb1 100644
--- a/tests/condvar3_1.c
+++ b/tests/condvar3_1.c
@@ -127,11 +127,7 @@ main()
int i;
pthread_t t[NUMTHREADS + 1];
void* result = (void*)0;
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
assert(pthread_cond_init(&cv, NULL) == 0);
diff --git a/tests/condvar3_2.c b/tests/condvar3_2.c
index 192b842..4c35801 100644
--- a/tests/condvar3_2.c
+++ b/tests/condvar3_2.c
@@ -128,11 +128,7 @@ main()
int i;
pthread_t t[NUMTHREADS + 1];
void* result = (void*)0;
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
assert(pthread_cond_init(&cv, NULL) == 0);
diff --git a/tests/condvar3_3.c b/tests/condvar3_3.c
index ae1ed70..f842440 100644
--- a/tests/condvar3_3.c
+++ b/tests/condvar3_3.c
@@ -87,11 +87,7 @@ int main()
int rc;
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
assert(pthread_cond_init(&cnd, 0) == 0);
diff --git a/tests/condvar4.c b/tests/condvar4.c
index 8d9fbe9..3f6879b 100644
--- a/tests/condvar4.c
+++ b/tests/condvar4.c
@@ -112,11 +112,7 @@ main()
{
pthread_t t[NUMTHREADS];
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
cvthing.shared = 0;
diff --git a/tests/condvar5.c b/tests/condvar5.c
index acbc65a..73083a5 100644
--- a/tests/condvar5.c
+++ b/tests/condvar5.c
@@ -111,11 +111,7 @@ main()
{
pthread_t t[NUMTHREADS];
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
cvthing.shared = 0;
diff --git a/tests/condvar6.c b/tests/condvar6.c
index ed16e5d..9d0b75d 100644
--- a/tests/condvar6.c
+++ b/tests/condvar6.c
@@ -144,11 +144,7 @@ main()
int i;
pthread_t t[NUMTHREADS + 1];
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
cvthing.shared = 0;
diff --git a/tests/condvar7.c b/tests/condvar7.c
index 3975e2c..0647e7d 100644
--- a/tests/condvar7.c
+++ b/tests/condvar7.c
@@ -154,11 +154,7 @@ main()
int i;
pthread_t t[NUMTHREADS + 1];
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
cvthing.shared = 0;
@@ -173,7 +169,7 @@ main()
PTW32_FTIME(&currSysTime);
- abstime.tv_sec = currSysTime.time;
+ abstime.tv_sec = (time_t)currSysTime.time;
abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
abstime.tv_sec += 10;
diff --git a/tests/condvar8.c b/tests/condvar8.c
index 96978f2..7c2579d 100644
--- a/tests/condvar8.c
+++ b/tests/condvar8.c
@@ -155,11 +155,7 @@ main()
int first, last;
pthread_t t[NUMTHREADS + 1];
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
assert((t[0] = pthread_self()).p != NULL);
diff --git a/tests/condvar9.c b/tests/condvar9.c
index dfcd158..62d044b 100644
--- a/tests/condvar9.c
+++ b/tests/condvar9.c
@@ -163,11 +163,7 @@ main()
int canceledThreads = 0;
pthread_t t[NUMTHREADS + 1];
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
assert((t[0] = pthread_self()).p != NULL);
diff --git a/tests/mutex8.c b/tests/mutex8.c
index 9798f5a..f263678 100644
--- a/tests/mutex8.c
+++ b/tests/mutex8.c
@@ -44,11 +44,7 @@ static pthread_mutex_t mutex;
void * locker(void * arg)
{
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
PTW32_FTIME(&currSysTime);
diff --git a/tests/mutex8e.c b/tests/mutex8e.c
index 58d7d1e..a360566 100644
--- a/tests/mutex8e.c
+++ b/tests/mutex8e.c
@@ -52,11 +52,7 @@ static pthread_mutexattr_t mxAttr;
void * locker(void * arg)
{
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
PTW32_FTIME(&currSysTime);
diff --git a/tests/mutex8n.c b/tests/mutex8n.c
index deb9215..0c6d97d 100644
--- a/tests/mutex8n.c
+++ b/tests/mutex8n.c
@@ -52,11 +52,7 @@ static pthread_mutexattr_t mxAttr;
void * locker(void * arg)
{
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
PTW32_FTIME(&currSysTime);
diff --git a/tests/mutex8r.c b/tests/mutex8r.c
index fe686c5..434b9af 100644
--- a/tests/mutex8r.c
+++ b/tests/mutex8r.c
@@ -52,11 +52,7 @@ static pthread_mutexattr_t mxAttr;
void * locker(void * arg)
{
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
PTW32_FTIME(&currSysTime);
diff --git a/tests/openmp1.c b/tests/openmp1.c
index 4c23d79..ee36e75 100755
--- a/tests/openmp1.c
+++ b/tests/openmp1.c
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef _OPENMP
- #include <omp.h>
+# include <omp.h>
#endif
#include <pthread.h>
@@ -20,17 +20,17 @@ void *_thread(void* Id) {
int i;
int x[Size];
- #ifdef _OPENMP
- #pragma omp parallel for
- #endif
+#ifdef _OPENMP
+# pragma omp parallel for
+#endif
for ( i = 0; i < Size; i++ ) {
- #ifdef _OPENMP
+#ifdef _OPENMP
if (Verbose && i%1000==0) {
int tid = omp_get_thread_num();
- #pragma omp critical
+# pragma omp critical
printf("thread %d : tid %d handles %d\n",(int)Id,tid,i);
}
- #endif
+#endif
x[i] = i;
}
@@ -40,9 +40,9 @@ void *_thread(void* Id) {
Sum += x[i];
}
if (Verbose) {
- #ifdef _OPENMP
- #pragma omp critical
- #endif
+#ifdef _OPENMP
+# pragma omp critical
+#endif
printf("Id %d : %s : %d(should be %d)\n",(int)Id, __FUNCTION__, Sum,ShouldSum);
}
if (Sum == ShouldSum) ThreadOK[(int)Id] = 1;
@@ -53,16 +53,16 @@ void *_thread(void* Id) {
void MainThread() {
int i;
- #ifdef _OPENMP
- #pragma omp parallel for
- #endif
+#ifdef _OPENMP
+# pragma omp parallel for
+#endif
for ( i = 0; i < 4; i++ ) {
- #ifdef _OPENMP
+#ifdef _OPENMP
int tid = omp_get_thread_num();
- #pragma omp critical
+# pragma omp critical
printf("Main : tid %d\n",tid);
_thread((void *)tid);
- #endif
+#endif
}
return;
}
@@ -117,11 +117,11 @@ int main(int argc, char *argv[]) {
}
printf("Joined thread2\n");
}
-#endif
+#endif // SPAWN_THREADS
short OK = 0;
// Check that we have OpenMP before declaring things OK formally.
- #ifdef _OPENMP
+#ifdef _OPENMP
OK = 1;
{
short i;
@@ -129,9 +129,9 @@ int main(int argc, char *argv[]) {
}
if (OK) printf("OMP : All looks good\n");
else printf("OMP : Error\n");
- #else
+#else
printf("OpenMP seems not enabled ...\n");
- #endif
+#endif
return OK?0:1;
}
diff --git a/tests/rwlock2_t.c b/tests/rwlock2_t.c
index af7ef05..4267ddb 100644
--- a/tests/rwlock2_t.c
+++ b/tests/rwlock2_t.c
@@ -50,11 +50,7 @@ int
main()
{
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
PTW32_FTIME(&currSysTime);
diff --git a/tests/rwlock3_t.c b/tests/rwlock3_t.c
index 60798dd..6419de1 100644
--- a/tests/rwlock3_t.c
+++ b/tests/rwlock3_t.c
@@ -63,11 +63,7 @@ main()
{
pthread_t t;
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
PTW32_FTIME(&currSysTime);
diff --git a/tests/rwlock4_t.c b/tests/rwlock4_t.c
index cccfd27..58b3602 100644
--- a/tests/rwlock4_t.c
+++ b/tests/rwlock4_t.c
@@ -63,11 +63,7 @@ main()
{
pthread_t t;
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
PTW32_FTIME(&currSysTime);
diff --git a/tests/rwlock5_t.c b/tests/rwlock5_t.c
index 96b4348..4a94658 100644
--- a/tests/rwlock5_t.c
+++ b/tests/rwlock5_t.c
@@ -65,11 +65,7 @@ main()
{
pthread_t t;
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
PTW32_FTIME(&currSysTime);
diff --git a/tests/rwlock6_t.c b/tests/rwlock6_t.c
index 6c45b0a..71cbe22 100644
--- a/tests/rwlock6_t.c
+++ b/tests/rwlock6_t.c
@@ -62,11 +62,7 @@ void * rdfunc(void * arg)
{
int ba = -1;
struct timespec abstime = { 0, 0 };
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
PTW32_FTIME(&currSysTime);
diff --git a/tests/rwlock6_t2.c b/tests/rwlock6_t2.c
index 28de466..b8b0df9 100644
--- a/tests/rwlock6_t2.c
+++ b/tests/rwlock6_t2.c
@@ -89,11 +89,7 @@ main()
void* wr1Result = (void*)0;
void* wr2Result = (void*)0;
void* rdResult = (void*)0;
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
PTW32_FTIME(&currSysTime);
diff --git a/tests/rwlock7.c b/tests/rwlock7.c
index 33e87e2..69d1a73 100644
--- a/tests/rwlock7.c
+++ b/tests/rwlock7.c
@@ -108,13 +108,8 @@ main (int argc, char *argv[])
int data_updates = 0;
int seed = 1;
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime1;
- struct __timeb64 currSysTime2;
-#else
- struct _timeb currSysTime1;
- struct _timeb currSysTime2;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime1;
+ PTW32_STRUCT_TIMEB currSysTime2;
/*
* Initialize the shared data.
diff --git a/tests/rwlock8.c b/tests/rwlock8.c
index 28552ba..99c357a 100644
--- a/tests/rwlock8.c
+++ b/tests/rwlock8.c
@@ -114,13 +114,8 @@ main (int argc, char *argv[])
int data_updates = 0;
int seed = 1;
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime1;
- struct __timeb64 currSysTime2;
-#else
- struct _timeb currSysTime1;
- struct _timeb currSysTime2;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime1;
+ PTW32_STRUCT_TIMEB currSysTime2;
/*
* Initialize the shared data.
diff --git a/tests/semaphore1.c b/tests/semaphore1.c
index 0f2eb77..8fc91ee 100644
--- a/tests/semaphore1.c
+++ b/tests/semaphore1.c
@@ -86,8 +86,11 @@ thr(void * arg)
if ( result == -1 )
{
int err = errno;
- printf("thread: sem_trywait 1: expecting error %s: got %s\n",
- error_string[EAGAIN], error_string[err]); fflush(stdout);
+ if (err != EAGAIN)
+ {
+ printf("thread: sem_trywait 1: expecting error %s: got %s\n",
+ error_string[EAGAIN], error_string[err]); fflush(stdout);
+ }
assert(err == EAGAIN);
}
else
@@ -99,15 +102,6 @@ thr(void * arg)
assert((result = sem_trywait(&s)) == 0);
- if ( result == -1 )
- {
- perror("thread: sem_trywait 2");
- }
- else
- {
- printf("thread: ok 2\n");
- }
-
assert(sem_post(&s) == 0);
return NULL;
@@ -133,8 +127,11 @@ main()
if (result2 == -1)
{
int err = errno;
- printf("main: sem_trywait 1: expecting error %s: got %s\n",
- error_string[EAGAIN], error_string[err]); fflush(stdout);
+ if (err != EAGAIN)
+ {
+ printf("main: sem_trywait 1: expecting error %s: got %s\n",
+ error_string[EAGAIN], error_string[err]); fflush(stdout);
+ }
assert(err == EAGAIN);
}
else
@@ -146,15 +143,6 @@ main()
assert((result2 = sem_trywait(&s)) == 0);
- if ( result2 == -1 )
- {
- perror("main: sem_trywait 2");
- }
- else
- {
- printf("main: ok 2\n");
- }
-
assert(sem_post(&s) == 0);
return 0;
diff --git a/tests/spin4.c b/tests/spin4.c
index 44527fe..bf1227d 100644
--- a/tests/spin4.c
+++ b/tests/spin4.c
@@ -41,13 +41,8 @@
#include <sys/timeb.h>
pthread_spinlock_t lock = PTHREAD_SPINLOCK_INITIALIZER;
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTimeStart;
- struct __timeb64 currSysTimeStop;
-#else
- struct _timeb currSysTimeStart;
- struct _timeb currSysTimeStop;
-#endif
+PTW32_STRUCT_TIMEB currSysTimeStart;
+PTW32_STRUCT_TIMEB currSysTimeStop;
#define GetDurationMilliSecs(_TStart, _TStop) ((_TStop.time*1000+_TStop.millitm) \
- (_TStart.time*1000+_TStart.millitm))
diff --git a/tests/stress1.c b/tests/stress1.c
index e4dbbd2..7c787dc 100644
--- a/tests/stress1.c
+++ b/tests/stress1.c
@@ -111,11 +111,7 @@ enum {
struct timespec *
millisecondsFromNow (struct timespec * time, int millisecs)
{
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
- struct __timeb64 currSysTime;
-#else
- struct _timeb currSysTime;
-#endif
+ PTW32_STRUCT_TIMEB currSysTime;
int64_t nanosecs, secs;
const int64_t NANOSEC_PER_MILLISEC = 1000000;
const int64_t NANOSEC_PER_SEC = 1000000000;
diff --git a/tests/test.h b/tests/test.h
index 639ee55..042e87b 100644
--- a/tests/test.h
+++ b/tests/test.h
@@ -61,12 +61,16 @@
#define int64_t _int64
#endif
-#ifdef _MSC_VER
- #define PTW32_FTIME(x) _ftime64_s(x);
-#elif defined(__MINGW32__) && __MSVCRT_VERSION__ >= 0x0601
- #define PTW32_FTIME(x) _ftime64(x);
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+# define PTW32_FTIME(x) _ftime64_s(x)
+# define PTW32_STRUCT_TIMEB struct __timeb64
+#elif ( defined(_MSC_VER) && _MSC_VER >= 1300 ) || \
+ ( defined(__MINGW32__) && __MSVCRT_VERSION__ >= 0x0601 )
+# define PTW32_FTIME(x) _ftime64(x)
+# define PTW32_STRUCT_TIMEB struct __timeb64
#else
- #define PTW32_FTIME(x) _ftime(x);
+# define PTW32_FTIME(x) _ftime(x)
+# define PTW32_STRUCT_TIMEB struct _timeb
#endif