From 414f4bd7e70d94025576d9264c86da63c506f6ca Mon Sep 17 00:00:00 2001 From: rpj Date: Wed, 13 Aug 2003 15:10:53 +0000 Subject: Bug fixes plus adaptation to current MinGW/MsysDTK environment. Changes to tests/benchmarks. --- ChangeLog | 15 +++++++++++++++ GNUmakefile | 41 ++++++++++++++++++++--------------------- pthread_spin_lock.c | 8 +++++--- pthread_spin_trylock.c | 14 +++++++++----- pthread_spin_unlock.c | 12 ++++++++---- ptw32_callUserDestroyRoutines.c | 5 +++++ ptw32_threadStart.c | 38 ++++++++++++-------------------------- sem_destroy.c | 2 +- sem_init.c | 2 +- tests/ChangeLog | 14 ++++++++++++++ tests/GNUmakefile | 40 +++++++++++++++++++--------------------- tests/benchtest1.c | 22 +++++++++++----------- tests/benchtest2.c | 22 +++++++++++----------- tests/benchtest3.c | 20 ++++++++++---------- tests/benchtest4.c | 20 ++++++++++---------- tests/benchtest5.c | 10 +++++----- tests/exception2.c | 2 +- tests/exception3.c | 9 +++++++-- tests/eyal1.c | 14 ++++++++++---- tests/semaphore1.c | 4 ++-- 20 files changed, 176 insertions(+), 138 deletions(-) diff --git a/ChangeLog b/ChangeLog index 65e1df4..c114280 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,21 @@ parameter was returning an incorrect error value. * pthread_setschedparam.c (pthread_setschedparam): Likewise. +2003-07-19 Ross Johnson + + * GNUmakefile: modified to work under MsysDTK environment. + * pthread_spin_lock.c (pthread_spin_lock): Check for NULL arg. + * pthread_spin_unlock.c (pthread_spin_unlock): Likewise. + * pthread_spin_trylock.c (pthread_spin_trylock): Likewise; + fix incorrect pointer value if lock is dynamically initialised by + this function. + * sem_init.c (sem_init): Initialise sem_t value to quell compiler warning. + * sem_destroy.c (sem_destroy): Likewise. + * ptw32_threadStart.c (non-MSVC code sections): Include rather + than old-style ; fix all std:: namespace entities such as + std::terminate_handler instances and associated methods. + * ptw32_callUserDestroyRoutines.c (non-MSVC code sections): Likewise. + 2003-06-24 Piet van Bruggen * pthread_spin_destroy.c (pthread_spin_destroy): Was not freeing the diff --git a/GNUmakefile b/GNUmakefile index 44fc4d7..4655d91 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -34,16 +34,15 @@ DEVROOT = C:\PTHREADS DLLDEST = $(DEVROOT)\DLL LIBDEST = $(DEVROOT)\DLL -#RM = rm -#MV = mv -#CP = cp +# If Running MsysDTK +RM = rm -f +MV = mv -f +CP = cp -f -RM = erase -MV = rename -CP = copy - -CC = gcc -CXX = g++ +# If not. +#RM = erase +#MV = rename +#CP = copy AR = ar @@ -54,7 +53,7 @@ OPT = -O3 -finline-functions LFLAGS = -lwsock32 GC_CFLAGS = -D__CLEANUP_C -GCE_CFLAGS = -D__CLEANUP_CXX -x c++ -mthreads +GCE_CFLAGS = -D__CLEANUP_CXX -mthreads ## Mingw32 MAKE = make @@ -395,27 +394,27 @@ GC_INLINED_STAMP = pthreadGC.stamp PTHREAD_DEF = pthread.def help: - @ echo Run one of the following command lines: - @ echo make clean GCE (to build the GNU C dll with C++ exception handling) - @ echo make clean GC (to build the GNU C dll with C cleanup code) - @ echo make clean GCE-inlined (to build the GNU C inlined dll with C++ exception handling) - @ echo make clean GC-inlined (to build the GNU C inlined dll with C cleanup code) + @ echo "Run one of the following command lines:" + @ echo "make clean GCE (to build the GNU C dll with C++ exception handling)" + @ echo "make clean GC (to build the GNU C dll with C cleanup code)" + @ echo "make clean GCE-inlined (to build the GNU C inlined dll with C++ exception handling)" + @ echo "make clean GC-inlined (to build the GNU C inlined dll with C cleanup code)" all: @ $(MAKE) clean GCE @ $(MAKE) clean GC GC: - $(MAKE) CLEANUP_FLAGS="$(GC_CFLAGS)" OBJ="$(DLL_OBJS)" $(GC_DLL) + $(MAKE) CC=gcc CLEANUP_FLAGS="$(GC_CFLAGS)" OBJ="$(DLL_OBJS)" $(GC_DLL) GCE: - $(MAKE) CLEANUP_FLAGS="$(GCE_CFLAGS)" OBJ="$(DLL_OBJS)" $(GCE_DLL) + $(MAKE) CC=g++ CLEANUP_FLAGS="$(GCE_CFLAGS)" OBJ="$(DLL_OBJS)" $(GCE_DLL) GC-inlined: - $(MAKE) CLEANUP_FLAGS="$(GC_CFLAGS)" OBJ="$(DLL_INLINED_OBJS)" $(GC_INLINED_STAMP) + $(MAKE) CC=gcc CLEANUP_FLAGS="$(GC_CFLAGS)" OBJ="$(DLL_INLINED_OBJS)" $(GC_INLINED_STAMP) GCE-inlined: - $(MAKE) CLEANUP_FLAGS="$(GCE_CFLAGS)" OBJ="$(DLL_INLINED_OBJS)" $(GCE_INLINED_STAMP) + $(MAKE) CC=g++ CLEANUP_FLAGS="$(GCE_CFLAGS)" OBJ="$(DLL_INLINED_OBJS)" $(GCE_INLINED_STAMP) tests: @ cd tests @@ -438,7 +437,7 @@ $(GC_DLL): $(DLL_OBJS) dlltool -k --dllname $@ --output-lib $(GC_LIB) --def $(PTHREAD_DEF) $(GCE_DLL): $(DLL_OBJS) - $(CXX) $(OPT) -mthreads -shared -o $(GCE_DLL) $(DLL_OBJS) $(LFLAGS) + $(CC) $(OPT) -mthreads -shared -o $(GCE_DLL) $(DLL_OBJS) $(LFLAGS) dlltool -z pthread.def $(DLL_OBJS) dlltool -k --dllname $@ --output-lib $(GCE_LIB) --def $(PTHREAD_DEF) @@ -449,7 +448,7 @@ $(GC_INLINED_STAMP): $(DLL_INLINED_OBJS) echo touched > $(GC_INLINED_STAMP) $(GCE_INLINED_STAMP): $(DLL_INLINED_OBJS) - $(CXX) $(OPT) -mthreads -shared -o $(GCE_DLL) $(DLL_INLINED_OBJS) $(LFLAGS) + $(CC) $(OPT) -mthreads -shared -o $(GCE_DLL) $(DLL_INLINED_OBJS) $(LFLAGS) dlltool -z pthread.def $(DLL_INLINED_OBJS) dlltool -k --dllname $(GCE_DLL) --output-lib $(GCE_LIB) --def $(PTHREAD_DEF) echo touched > $(GCE_INLINED_STAMP) diff --git a/pthread_spin_lock.c b/pthread_spin_lock.c index d3355d1..f9210f1 100644 --- a/pthread_spin_lock.c +++ b/pthread_spin_lock.c @@ -38,14 +38,16 @@ #include "implement.h" -/* - * NOTE: For speed, these routines don't check if "lock" is valid. - */ int pthread_spin_lock(pthread_spinlock_t *lock) { register pthread_spinlock_t s; + if (NULL == lock || NULL == *lock) + { + return(EINVAL); + } + if (*lock == PTHREAD_SPINLOCK_INITIALIZER) { int result; diff --git a/pthread_spin_trylock.c b/pthread_spin_trylock.c index 39b7fd3..02cfd40 100644 --- a/pthread_spin_trylock.c +++ b/pthread_spin_trylock.c @@ -38,15 +38,17 @@ #include "implement.h" -/* - * NOTE: For speed, these routines don't check if "lock" is valid. - */ int pthread_spin_trylock(pthread_spinlock_t *lock) { - pthread_spinlock_t s = *lock; + register pthread_spinlock_t s; + + if (NULL == lock || NULL == *lock) + { + return(EINVAL); + } - if (s == PTHREAD_SPINLOCK_INITIALIZER) + if (*lock == PTHREAD_SPINLOCK_INITIALIZER) { int result; @@ -56,6 +58,8 @@ pthread_spin_trylock(pthread_spinlock_t *lock) } } + s = *lock; + switch ((long) ptw32_interlocked_compare_exchange((PTW32_INTERLOCKED_LPLONG) &(s->interlock), (PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED, (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED )) diff --git a/pthread_spin_unlock.c b/pthread_spin_unlock.c index 30c11d4..7b77395 100644 --- a/pthread_spin_unlock.c +++ b/pthread_spin_unlock.c @@ -38,13 +38,17 @@ #include "implement.h" -/* - * NOTE: For speed, these routines don't check if "lock" is valid. - */ int pthread_spin_unlock(pthread_spinlock_t *lock) { - register pthread_spinlock_t s = *lock; + register pthread_spinlock_t s; + + if (NULL == lock || NULL == *lock) + { + return(EINVAL); + } + + s = *lock; if (s == PTHREAD_SPINLOCK_INITIALIZER) { diff --git a/ptw32_callUserDestroyRoutines.c b/ptw32_callUserDestroyRoutines.c index cef88cf..f580223 100644 --- a/ptw32_callUserDestroyRoutines.c +++ b/ptw32_callUserDestroyRoutines.c @@ -38,6 +38,11 @@ #include "pthread.h" #include "implement.h" +#ifdef __cplusplus +# if ! defined (_MSC_VER) && ! (defined(__GNUC__) && __GNUC__ < 3) + using std::terminate; +# endif +#endif void ptw32_callUserDestroyRoutines (pthread_t thread) diff --git a/ptw32_threadStart.c b/ptw32_threadStart.c index 96cadf9..79b793b 100644 --- a/ptw32_threadStart.c +++ b/ptw32_threadStart.c @@ -82,37 +82,32 @@ ExceptionFilter (EXCEPTION_POINTERS * ep, DWORD * ei) #elif defined(__CLEANUP_CXX) #if defined(_MSC_VER) -#include -static terminate_function ptw32_oldTerminate; +# include #else -#include -static terminate_handler ptw32_oldTerminate; +# if defined(__GNUC__) && __GNUC__ < 3 +# include +# else +# include + using std::terminate_handler; + using std::terminate; + using std::set_terminate; +# endif + typedef terminate_handler terminate_function; #endif -#if 0 -#include -static pthread_mutex_t termLock = PTHREAD_MUTEX_INITIALIZER; -#endif +static terminate_function ptw32_oldTerminate; void ptw32_terminate () { pthread_t self = pthread_self(); -#if 0 - FILE * fp; - pthread_mutex_lock(&termLock); - fp = fopen("pthread.log", "a"); - fprintf(fp, "Terminate\n"); - fclose(fp); - pthread_mutex_unlock(&termLock); -#endif set_terminate(ptw32_oldTerminate); (void) pthread_mutex_destroy(&self->cancelLock); ptw32_callUserDestroyRoutines(self); terminate(); } -#endif /* _MSC_VER */ +#endif #if ! defined (__MINGW32__) || defined (__MSVCRT__) unsigned __stdcall @@ -263,12 +258,7 @@ ptw32_threadStart (void * vthreadParms) * supplied function. */ -#if defined(_MSC_VER) terminate_function term_func = set_terminate(0); -#else - terminate_handler term_func = set_terminate(0); -#endif - set_terminate(term_func); if (term_func != 0) { @@ -323,7 +313,6 @@ ptw32_threadStart (void * vthreadParms) #endif /* __CLEANUP_C */ #endif /* __CLEANUP_SEH */ -#if 1 if (self->detachState == PTHREAD_CREATE_DETACHED) { /* @@ -345,9 +334,6 @@ ptw32_threadStart (void * vthreadParms) { ptw32_callUserDestroyRoutines (self); } -#else - ptw32_callUserDestroyRoutines (self); -#endif #if ! defined (__MINGW32__) || defined (__MSVCRT__) _endthreadex ((unsigned) status); diff --git a/sem_destroy.c b/sem_destroy.c index 80358f8..041d9d9 100644 --- a/sem_destroy.c +++ b/sem_destroy.c @@ -73,7 +73,7 @@ sem_destroy (sem_t * sem) */ { int result = 0; - sem_t s; + sem_t s = NULL; if (sem == NULL || *sem == NULL) { diff --git a/sem_init.c b/sem_init.c index f980729..0382b62 100644 --- a/sem_init.c +++ b/sem_init.c @@ -85,7 +85,7 @@ sem_init (sem_t * sem, int pshared, unsigned int value) */ { int result = 0; - sem_t s; + sem_t s = NULL; if (pshared != 0) { diff --git a/tests/ChangeLog b/tests/ChangeLog index b3916d2..fb52cef 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,17 @@ +2003-07-19 Ross Johnson + + * eyal1.c (waste_time): Make threads do more work to ensure that + all threads get to do some work. + * semaphore1.c: Make it clear that certain errors are expected. + * exception2.c (non_MSVC code sections): Change to include + C++ standard include file, i.e. change to . + * exception3.c (non_MSVC code sections): Likewise; qualify std:: + namespace entities where necessary. + * GNUmakefile: modified to work in the MsysDTK (newer MinGW) + environment; define CC as gcc or g++ as appropriate because + using gcc -x c++ doesn't link with required c++ libs by default, + but g++ does. + 2002-12-11 Ross Johnson * mutex7e.c: Assert EBUSY return instead of EDEADLK. diff --git a/tests/GNUmakefile b/tests/GNUmakefile index 15b77b6..132f84b 100644 --- a/tests/GNUmakefile +++ b/tests/GNUmakefile @@ -32,12 +32,12 @@ # -#CP = cp -#MV = mv -#RM = rm -CP = copy -MV = rename -RM = erase +CP = cp -f +MV = mv -f +RM = rm -f +#CP = copy +#MV = rename +#RM = erase MKDIR = mkdir TOUCH = echo Passed > ECHO = @echo @@ -46,8 +46,6 @@ MAKE = make # # Mingw32 # -GLANG = c++ -CC = gcc XXCFLAGS = CFLAGS = -O3 -UNDEBUG -Wall $(XXCFLAGS) #CFLAGS = -g -O0 -UNDEBUG -Wall $(XXCFLAGS) @@ -92,12 +90,12 @@ PASSES = $(TESTS:%=%.pass) BENCHRESULTS = $(BENCHTESTS:%=%.bench) help: - @ $(ECHO) Run one of the following command lines: - @ $(ECHO) nmake clean GC (to test using GC dll with C (no EH) applications) - @ $(ECHO) nmake clean GCX (to test using GC dll with C++ (EH) applications) - @ $(ECHO) nmake clean GCE (to test using GCE dll with C++ (EH) applications) - @ $(ECHO) nmake clean GC-bench (to benchtest using GNU C dll with C cleanup code) - @ $(ECHO) nmake clean GCE-bench (to benchtest using GNU C dll with C++ exception handling) + @ $(ECHO) "Run one of the following command lines:" + @ $(ECHO) "make clean GC (to test using GC dll with C (no EH) applications)" + @ $(ECHO) "make clean GCX (to test using GC dll with C++ (EH) applications)" + @ $(ECHO) "make clean GCE (to test using GCE dll with C++ (EH) applications)" + @ $(ECHO) "make clean GC-bench (to benchtest using GNU C dll with C cleanup code)" + @ $(ECHO) "make clean GCE-bench (to benchtest using GNU C dll with C++ exception handling)" all: @ $(MAKE) clean GC @@ -105,19 +103,19 @@ all: @ $(MAKE) clean GCE GC: - $(MAKE) GCX=GC XXCFLAGS="-x c -D__CLEANUP_C" all-pass + $(MAKE) GCX=GC CC=gcc XXCFLAGS="-D__CLEANUP_C" all-pass GCE: - $(MAKE) GCX=GCE XXCFLAGS="-mthreads -x c++ -D__CLEANUP_CXX" all-pass + $(MAKE) GCX=GCE CC=g++ XXCFLAGS="-mthreads -D__CLEANUP_CXX" all-pass GCX: - $(MAKE) GCX=GC XXCFLAGS="-mthreads -x c++ -D__CLEANUP_C" all-pass + $(MAKE) GCX=GC CC=g++ XXCFLAGS="-mthreads -D__CLEANUP_C" all-pass GC-bench: - $(MAKE) GCX=GC XXCFLAGS="-x c -D__CLEANUP_C" all-bench + $(MAKE) GCX=GC CC=gcc XXCFLAGS="-D__CLEANUP_C" all-bench GCE-bench: - $(MAKE) GCX=GCE XXCFLAGS="-mthreads -x c++ -D__CLEANUP_CXX" all-bench + $(MAKE) GCX=GCE CC=g++ XXCFLAGS="-mthreads -D__CLEANUP_CXX" all-bench all-pass: $(PASSES) @ $(ECHO) ALL TESTS PASSED! Congratulations! @@ -244,7 +242,7 @@ tsd1.pass: join1.pass %.exe: %.c @ $(ECHO) Compiling $@ @ $(ECHO) $(CC) $(CFLAGS) -o $@ $^ $(INCLUDES) -L. -lpthread$(GCX) - @ $(CC) $(CFLAGS) -o $@ $^ $(INCLUDES) -L. -lpthread$(GCX) + @ $(CC) $(CFLAGS) -o $@ $^ $(INCLUDES) -L. -lpthread$(GCX) -lsupc++ %.pre: %.c @ $(CC) -E $(CFLAGS) -o $@ $^ $(INCLUDES) @@ -254,7 +252,7 @@ tsd1.pass: join1.pass $(COPYFILES): @ $(ECHO) Copying $@ - @ $(CP) $(BUILD_DIR)\$@ . + @ $(CP) $(BUILD_DIR)/$@ . pthread.dll: @ $(CP) $(DLL) $@ diff --git a/tests/benchtest1.c b/tests/benchtest1.c index b4dbdae..e9ecbb0 100644 --- a/tests/benchtest1.c +++ b/tests/benchtest1.c @@ -91,7 +91,7 @@ runTest (char * testNameString, int mType) durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", + printf( "%-45s %15ld %15.3f\n", testNameString, durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); @@ -106,14 +106,14 @@ main (int argc, char *argv[]) pthread_mutexattr_init(&ma); - printf( "========================================================================\n"); + printf( "=============================================================================\n"); printf( "\nLock plus unlock on an unlocked mutex.\n%ld iterations\n\n", ITERATIONS); - printf( "%-40s %15s %15s\n", + printf( "%-45s %15s %15s\n", "Test", "Total(msec)", "average(usec)"); - printf( "------------------------------------------------------------------------\n"); + printf( "-----------------------------------------------------------------------------\n"); /* * Time the loop overhead so we can subtract it from the actual test times. @@ -139,7 +139,7 @@ main (int argc, char *argv[]) durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", + printf( "%-45s %15ld %15.3f\n", "Simple Critical Section", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); @@ -157,8 +157,8 @@ main (int argc, char *argv[]) durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", - "PT Mutex using a Critical Section (WNT)", + printf( "%-45s %15ld %15.3f\n", + "Old PT Mutex using a Critical Section (WNT)", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); @@ -175,12 +175,12 @@ main (int argc, char *argv[]) durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", - "PT Mutex using a Win32 Mutex (W9x)", + printf( "%-45s %15ld %15.3f\n", + "Old PT Mutex using a Win32 Mutex (W9x)", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); - printf( "........................................................................\n"); + printf( ".............................................................................\n"); /* * Now we can start the actual tests @@ -197,7 +197,7 @@ main (int argc, char *argv[]) runTest("Non-blocking lock", 0); #endif - printf( "========================================================================\n"); + printf( "=============================================================================\n"); /* * End of tests. diff --git a/tests/benchtest2.c b/tests/benchtest2.c index e1362d1..9c614b5 100644 --- a/tests/benchtest2.c +++ b/tests/benchtest2.c @@ -168,7 +168,7 @@ runTest (char * testNameString, int mType) assert(pthread_mutex_destroy(&gate2) == 0); assert(pthread_mutex_destroy(&gate1) == 0); durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", + printf( "%-45s %15ld %15.3f\n", testNameString, durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS / 4 /* Four locks/unlocks per iteration */); @@ -180,15 +180,15 @@ main (int argc, char *argv[]) { assert(pthread_mutexattr_init(&ma) == 0); - printf( "========================================================================\n"); + printf( "=============================================================================\n"); printf( "\nLock plus unlock on an unlocked mutex.\n"); printf("%ld iterations, four locks/unlocks per iteration.\n\n", ITERATIONS); - printf( "%-40s %15s %15s\n", + printf( "%-45s %15s %15s\n", "Test", "Total(msec)", "average(usec)"); - printf( "------------------------------------------------------------------------\n"); + printf( "-----------------------------------------------------------------------------\n"); /* * Time the loop overhead so we can subtract it from the actual test times. @@ -226,7 +226,7 @@ main (int argc, char *argv[]) DeleteCriticalSection(&cs2); DeleteCriticalSection(&cs1); durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", + printf( "%-45s %15ld %15.3f\n", "Simple Critical Section", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS / 4 ); @@ -253,8 +253,8 @@ main (int argc, char *argv[]) assert(old_mutex_destroy(&ox2) == 0); assert(old_mutex_destroy(&ox1) == 0); durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", - "PT Mutex using a Critical Section (WNT)", + printf( "%-45s %15ld %15.3f\n", + "Old PT Mutex using a Critical Section (WNT)", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS / 4); @@ -280,12 +280,12 @@ main (int argc, char *argv[]) assert(old_mutex_destroy(&ox2) == 0); assert(old_mutex_destroy(&ox1) == 0); durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", - "PT Mutex using a Win32 Mutex (W9x)", + printf( "%-45s %15ld %15.3f\n", + "Old PT Mutex using a Win32 Mutex (W9x)", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS / 4); - printf( "........................................................................\n"); + printf( ".............................................................................\n"); /* * Now we can start the actual tests @@ -302,7 +302,7 @@ main (int argc, char *argv[]) runTest("Blocking locks", 0); #endif - printf( "========================================================================\n"); + printf( "=============================================================================\n"); /* * End of tests. */ diff --git a/tests/benchtest3.c b/tests/benchtest3.c index 4de6488..5e86957 100644 --- a/tests/benchtest3.c +++ b/tests/benchtest3.c @@ -114,7 +114,7 @@ runTest (char * testNameString, int mType) durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", + printf( "%-45s %15ld %15.3f\n", testNameString, durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); @@ -128,14 +128,14 @@ main (int argc, char *argv[]) assert(pthread_mutexattr_init(&ma) == 0); - printf( "========================================================================\n"); + printf( "=============================================================================\n"); printf( "\nTrylock on a locked mutex.\n"); printf( "%ld iterations.\n\n", ITERATIONS); - printf( "%-40s %15s %15s\n", + printf( "%-45s %15s %15s\n", "Test", "Total(msec)", "average(usec)"); - printf( "------------------------------------------------------------------------\n"); + printf( "-----------------------------------------------------------------------------\n"); /* * Time the loop overhead so we can subtract it from the actual test times. @@ -156,8 +156,8 @@ main (int argc, char *argv[]) assert(old_mutex_unlock(&ox) == 0); assert(old_mutex_destroy(&ox) == 0); durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", - "PT Mutex using a Critical Section (WNT)", + printf( "%-45s %15ld %15.3f\n", + "Old PT Mutex using a Critical Section (WNT)", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); @@ -169,12 +169,12 @@ main (int argc, char *argv[]) assert(old_mutex_unlock(&ox) == 0); assert(old_mutex_destroy(&ox) == 0); durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", - "PT Mutex using a Win32 Mutex (W9x)", + printf( "%-45s %15ld %15.3f\n", + "Old PT Mutex using a Win32 Mutex (W9x)", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); - printf( "........................................................................\n"); + printf( ".............................................................................\n"); /* * Now we can start the actual tests @@ -191,7 +191,7 @@ main (int argc, char *argv[]) runTest("Non-blocking lock", 0); #endif - printf( "========================================================================\n"); + printf( "=============================================================================\n"); /* * End of tests. diff --git a/tests/benchtest4.c b/tests/benchtest4.c index 653b0ed..f769afe 100644 --- a/tests/benchtest4.c +++ b/tests/benchtest4.c @@ -98,7 +98,7 @@ runTest (char * testNameString, int mType) durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", + printf( "%-45s %15ld %15.3f\n", testNameString, durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); @@ -110,14 +110,14 @@ main (int argc, char *argv[]) { pthread_mutexattr_init(&ma); - printf( "========================================================================\n"); + printf( "=============================================================================\n"); printf( "Trylock plus unlock on an unlocked mutex.\n"); printf( "%ld iterations.\n\n", ITERATIONS); - printf( "%-40s %15s %15s\n", + printf( "%-45s %15s %15s\n", "Test", "Total(msec)", "average(usec)"); - printf( "------------------------------------------------------------------------\n"); + printf( "-----------------------------------------------------------------------------\n"); /* * Time the loop overhead so we can subtract it from the actual test times. @@ -137,8 +137,8 @@ main (int argc, char *argv[]) TESTSTOP assert(old_mutex_destroy(&ox) == 0); durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", - "PT Mutex using a Critical Section (WNT)", + printf( "%-45s %15ld %15.3f\n", + "Old PT Mutex using a Critical Section (WNT)", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); @@ -150,12 +150,12 @@ main (int argc, char *argv[]) TESTSTOP assert(old_mutex_destroy(&ox) == 0); durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", - "PT Mutex using a Win32 Mutex (W9x)", + printf( "%-45s %15ld %15.3f\n", + "Old PT Mutex using a Win32 Mutex (W9x)", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); - printf( "........................................................................\n"); + printf( ".............................................................................\n"); /* * Now we can start the actual tests @@ -172,7 +172,7 @@ main (int argc, char *argv[]) runTest("Non-blocking lock", 0); #endif - printf( "========================================================================\n"); + printf( "=============================================================================\n"); /* * End of tests. diff --git a/tests/benchtest5.c b/tests/benchtest5.c index b7d3225..0b48d9f 100644 --- a/tests/benchtest5.c +++ b/tests/benchtest5.c @@ -78,7 +78,7 @@ reportTest (char * testNameString) { durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; - printf( "%-40s %15ld %15.3f\n", + printf( "%-45s %15ld %15.3f\n", testNameString, durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); @@ -88,14 +88,14 @@ reportTest (char * testNameString) int main (int argc, char *argv[]) { - printf( "========================================================================\n"); + printf( "=============================================================================\n"); printf( "\nOperations on a semaphore.\n%ld iterations\n\n", ITERATIONS); - printf( "%-40s %15s %15s\n", + printf( "%-45s %15s %15s\n", "Test", "Total(msec)", "average(usec)"); - printf( "------------------------------------------------------------------------\n"); + printf( "-----------------------------------------------------------------------------\n"); /* * Time the loop overhead so we can subtract it from the actual test times. @@ -165,7 +165,7 @@ main (int argc, char *argv[]) reportTest("Wait then Post without blocking"); - printf( "========================================================================\n"); + printf( "=============================================================================\n"); /* * End of tests. diff --git a/tests/exception2.c b/tests/exception2.c index 9c99dd3..36edd9c 100644 --- a/tests/exception2.c +++ b/tests/exception2.c @@ -79,7 +79,7 @@ #if defined(_MSC_VER) && defined(__cplusplus) #include #else -#include +#include #endif #ifdef __GNUC__ diff --git a/tests/exception3.c b/tests/exception3.c index d3eb364..915a0e9 100644 --- a/tests/exception3.c +++ b/tests/exception3.c @@ -78,9 +78,14 @@ #if defined(__cplusplus) #if defined(_MSC_VER) -#include +# include #else -#include +# if defined(__GNUC__) && __GNUC__ < 3 +# include +# else +# include + using std::set_terminate; +# endif #endif /* diff --git a/tests/eyal1.c b/tests/eyal1.c index 72a127f..2890207 100644 --- a/tests/eyal1.c +++ b/tests/eyal1.c @@ -124,15 +124,21 @@ static double waste_time (int n) { int i; - double f; + double f, g, h, s; - f = rand (); + s = 0; + /* + * Useless work. + */ for (i = n*100; i > 0; --i) { - f = 2 * f * f / (f * f); + f = rand (); + g = rand (); + h = rand (); + s += 2 * f * g / (h != 0 ? (h * h) : 1); } - return f; + return s; } static int diff --git a/tests/semaphore1.c b/tests/semaphore1.c index c5911f9..1fc60d5 100644 --- a/tests/semaphore1.c +++ b/tests/semaphore1.c @@ -87,7 +87,7 @@ thr(void * arg) if ( result == -1 ) { - perror("thread: sem_trywait 1"); // No error + perror("thread: sem_trywait 1: expected error"); // No error assert(errno == EAGAIN); } else @@ -131,7 +131,7 @@ main() if ( result == -1 ) { - perror("main: sem_trywait 1"); // No error + perror("main: sem_trywait 1: expected error"); // No error assert(errno == EAGAIN); } else -- cgit v1.2.3