From 16cb1bf22f72db0ac47080e364ffbc79a3ec174a Mon Sep 17 00:00:00 2001 From: rpj Date: Mon, 14 Aug 2000 03:43:09 +0000 Subject: 2000-08-13 Ross Johnson * errno.c: Add _MD precompile condition; thus far had no effect when using /MD compile option but I thnk it should be there. * exit.c: Add __cplusplus to various #if lines; was compiling SEH code even when VC++ had C++ compile options. * private.c: ditto. * create.c (pthread_create): Add PT_STDCALL macro to function pointer arg in _beginthread(). * pthread.h: PT_STDCALL really does need to be defined in both this and impliment.h; don't set it to __cdecl - this macro is only used to extend function pointer casting for functions that will be passed as parameters. (~PThreadCleanup): add cast and group expression. (_errno): Add _MD compile conditional. (PtW32NoCatchWarn): Change pragma message. * implement.h: Move and change PT_STDCALL define. * need_errno.h: Add _MD to compilation conditional. * GNUmakefile: Substantial rewrite for new naming convention; set for nil optimisation (turn it up when we have a working library build; add target "fake.a" to build a libpthreadw32.a from the VC++ built DLL pthreadVCE.dll. * pthread.def (LIBRARY): Don't specify in the .def file - it is specified on the linker command line since we now use the same .def file for variously named .dlls. * Makefile: Substantial rewrite for new naming convention; default nmake target only issues a help message; run nmake with specific target corresponding to the EH scheme being used. * README: Update information; add naming convention explanation. * ANNOUNCE: Update information. 2000-08-12 Ross Johnson * pthread.h: Add compile-time message when using MSC_VER compiler and C++ EH to warn application programmers to use PtW32Catch instead of catch(...) if they want cancelation and pthread_exit to work. * implement.h: Remove #include ; we use our own local semaphore.h. tests/ChangeLog: 2000-08-13 Ross Johnson * condvar3.c: Minor change to eliminate compiler warning. * condvar4.c: ditto. * condvar5.c: ditto. * condvar6.c: ditto. * condvar7.c: ditto. * condvar8.c: ditto. * condvar9.c: ditto. * exit1.c: Function needed return statement. * cleanup1.c: Remove unnecessary printf arg. * cleanup2.c: Fix cast. * rwlock6.c: Fix casts. * exception1.c (PtW32CatchAll): Had the wrong name; fix casts. * cancel3.c: Remove unused waitLock variable. * GNUmakefile: Change library/dll naming; add new tests; general minor changes. * Makefile: Change library/dll naming; add targets for testing each of the two VC++ EH scheme versions; default target now issues help message; compile warnings now interpreted as errors to stop the make; add new tests; restructure to remove prerequisites needed otherwise. * README: Updated. --- ANNOUNCE | 39 +++++---- CONTRIBUTORS | 7 +- ChangeLog | 58 ++++++++++++++ GNUmakefile | 29 ++++--- Makefile | 55 +++++++------ README | 191 ++++++++++++++++++++++++++++++++----------- buildlib.bat | 50 +++++++----- create.c | 2 +- errno.c | 4 +- exit.c | 4 +- implement.h | 10 +++ misc.c | 2 +- need_errno.h | 10 +-- private.c | 10 +-- pthread.def | 232 ++++++++++++++++++++++++++--------------------------- pthread.h | 37 +++++---- tests/ChangeLog | 43 ++++++++++ tests/GNUmakefile | 22 +++-- tests/Makefile | 142 +++++++++++++++++++------------- tests/README | 28 +++++-- tests/cancel3.c | 2 - tests/cleanup1.c | 3 +- tests/cleanup2.c | 2 +- tests/cleanup3.c | 2 +- tests/condvar3.c | 2 +- tests/condvar4.c | 2 +- tests/condvar5.c | 2 +- tests/condvar6.c | 2 +- tests/condvar7.c | 2 +- tests/condvar8.c | 2 +- tests/condvar9.c | 2 +- tests/exception1.c | 8 +- tests/exit1.c | 1 + tests/rwlock6.c | 6 +- 34 files changed, 647 insertions(+), 366 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 47d2ece..12ac234 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ - PTHREADS-WIN32 SNAPSHOT 2000-08-10 + PTHREADS-WIN32 SNAPSHOT 2000-08-13 ---------------------------------- Web Site: http://sources.redhat.com/pthreads-win32/ FTP Site: ftp://sources.redhat.com/pub/pthreads-win32 @@ -26,19 +26,19 @@ Change Summary (since the last snapshot) (See the ChangeLog file for details.) New: -- asynchronous cancelation on X86 (Jason Nye) -- Makefile compatible with MS nmake to replace - buildlib.bat -- GNUmakefile for Mingw32 -- tests/Makefile for MS nmake replaces runall.bat -- tests/GNUmakefile for Mingw32 +- Renamed DLL and LIB files: + pthreadVSE.dll (MS VC++/Structured EH) + pthreadVSE.lib + pthreadVCE.dll (MS VC++/C++ EH) + pthreadVCE.lib + pthreadGCE.dll (GNU G++/C++ EH) + libpthreadw32.a + + Both your application and the pthread dll should use the + same exception handling scheme. Bugs fixed: -- kernel32 load/free problem -- attempt to hide internel exceptions from application - exception handlers (__try/__except and try/catch blocks) -- Win32 thread handle leakage bug - (David Baggett/Paul Redondo/Eyal Lebedinsky) +- MSVC++ C++ exception handling. Some new tests have been added. @@ -52,16 +52,15 @@ page access) exception. The fault appears to be in the assembler code emmitted by the compiler [to handle exception contexts] at the end of the try block in _pthread_threadStart(). -2. There are problems with using the libpthread32.a file with the -VC++ SEH version of pthread.dll. The cleanup1.c test fails and the -eyal1.c test gives suspect results. +2. There are problems using the libpthreadw32.a stub archive derived +from either of pthreadVSE.dll or pthreadVCE.dll. The cleanup1.c test +fails. + -3. I have not been able to build with VC++ using C++ EH. This is a -maintainer problem who doesn't think he's doing it right. Consequently -there may also be basic parser errors and warnings to be cleaned -up in the code. +Caveats +------- -4. Due to what is believed to be a C++ compliance error in VC++, +1. Due to what is believed to be a C++ compliance error in VC++, if your application contains catch(...) blocks in your POSIX threads then you will need to replace the "catch(...)" with the macro "PtW32Catch", eg. diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 044225c..dee0d33 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -7,7 +7,6 @@ John E. Bossom John.Bossom@cognos.com Anders Norlander anorland@hem2.passagen.se Tor Lillqvist tml@iki.fi Kevin Ruland Kevin.Ruland@anheuser-busch.com -Eyal Lebedinsky eyal@eyal.emu.id.au Mike Russo miker@eai.com Mark E. Armstrong avail@pacbell.net Lorin Hochstein lmh@xiphos.ca @@ -23,6 +22,6 @@ Todd Owen towen@lucidcalm.dropbear.id.au Jason Nye jnye@nbnet.nb.ca Fred Forester fforest@eticomm.net Kevin D. Clark kclark@cabletron.com -David Baggett dmb@itasoftware.com -Paul Redondo paul@matchvision.com -Scott McCaskill scott@3dfx.com +David Baggett dmb.itasoftware.com +Paul Redondo paul.matchvision.com +Scott McCaskill scott.3dfx.om diff --git a/ChangeLog b/ChangeLog index ddace34..1a788ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,61 @@ +2000-08-13 Ross Johnson + + * errno.c: Add _MD precompile condition; thus far + had no effect when using /MD compile option but I + thnk it should be there. + + * exit.c: Add __cplusplus to various #if lines; + was compiling SEH code even when VC++ had + C++ compile options. + + * private.c: ditto. + + * create.c (pthread_create): Add PT_STDCALL macro to + function pointer arg in _beginthread(). + + * pthread.h: PT_STDCALL really does need to be defined + in both this and impliment.h; don't set it to __cdecl + - this macro is only used to extend function pointer + casting for functions that will be passed as parameters. + (~PThreadCleanup): add cast and group expression. + (_errno): Add _MD compile conditional. + (PtW32NoCatchWarn): Change pragma message. + + * implement.h: Move and change PT_STDCALL define. + + * need_errno.h: Add _MD to compilation conditional. + + * GNUmakefile: Substantial rewrite for new naming + convention; set for nil optimisation (turn it up + when we have a working library build; add target + "fake.a" to build a libpthreadw32.a from the VC++ + built DLL pthreadVCE.dll. + + * pthread.def (LIBRARY): Don't specify in the .def + file - it is specified on the linker command line + since we now use the same .def file for variously + named .dlls. + + * Makefile: Substantial rewrite for new naming + convention; default nmake target only issues a + help message; run nmake with specific target + corresponding to the EH scheme being used. + + * README: Update information; add naming convention + explanation. + + * ANNOUNCE: Update information. + +2000-08-12 Ross Johnson + + * pthread.h: Add compile-time message when using + MSC_VER compiler and C++ EH to warn application + programmers to use PtW32Catch instead of catch(...) + if they want cancelation and pthread_exit to work. + + * implement.h: Remove #include ; we + use our own local semaphore.h. + 2000-08-10 Ross Johnson * cleanup.c (pthread_pop_cleanup): Remove _pthread diff --git a/GNUmakefile b/GNUmakefile index b10e358..c91a782 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -21,6 +21,8 @@ GLANG = c++ RM = erase +MV = rename +CP = copy CC = gcc @@ -28,7 +30,7 @@ AR = ar LD = gcc -mdll -OPT = -g -O2 -x $(GLANG) +OPT = -g -O0 -x $(GLANG) ## Mingw32 CFLAGS = $(OPT) -I. -mthreads -DHAVE_CONFIG_H -Wall @@ -42,19 +44,21 @@ OBJS = attr.o cancel.o cleanup.o condvar.o create.o dll.o errno.o \ INCL = implement.h semaphore.h pthread.h windows.h -DLL = pthread.dll +DLL = pthreadGCE.dll -LIB = libpthread32.a +LIBS = libpthreadw32.a -all: $(LIB) +all: $(LIBS) -pthread.a: - dlltool --def $(DLL:.dll=.def) --output-lib $@ --dllname $(DLL) - rename pthread.a $(LIB) +fake.a: + @ $(CP) pthreadVCE.dll $(DLL) + dlltool --def pthread.def --output-lib $@ --dllname $(DLL) + @-$(RM) $(LIBS) + $(MV) fake.a $(LIBS) -$(LIB): $(DLL) - dlltool --def $(DLL:.dll=.def) --output-lib $@ --dllname $(DLL) +$(LIBS): $(DLL) + dlltool --def pthread.def --output-lib $@ --dllname $(DLL) %.pre: %.c $(CC) -E -o $@ $(CFLAGS) $^ @@ -66,16 +70,17 @@ $(LIB): $(DLL) $(DLL): $(OBJS) $(LD) -o $@ $^ -Wl,--base-file,$*.base - dlltool --base-file=$*.base --def $*.def --output-exp $*.exp --dllname $@ + dlltool --base-file=$*.base --def pthread.def --output-exp $*.exp --dllname $@ $(LD) -o $@ $^ -Wl,--base-file,$*.base,$*.exp - dlltool --base-file=$*.base --def $*.def --output-exp $*.exp --dllname $@ + dlltool --base-file=$*.base --def pthread.def --output-exp $*.exp --dllname $@ $(LD) -o $@ $^ -Wl,$*.exp clean: -$(RM) *~ - -$(RM) $(LIB) + -$(RM) $(LIBS) -$(RM) *.o -$(RM) *.exe -$(RM) $(DLL) -$(RM) $(DLL:.dll=.base) -$(RM) $(DLL:.dll=.exp) + -$(RM) fake.a diff --git a/Makefile b/Makefile index 3ecd026..f8d0b00 100644 --- a/Makefile +++ b/Makefile @@ -11,9 +11,14 @@ DEVROOT=c:\pthreads\dll DLLDEST=$(DEVROOT) LIBDEST=$(DEVROOT) -#CLIB = /MD -CLIB = /MT -CCFLAGS = #/EHsc /TP /D_cplusplus +DLLS = pthreadVCE.dll pthreadVSE.dll + +# C++ Exceptions +VCEFLAGS = /GX /TP /DPtW32NoCatchWarn +#Structured Exceptions +VSEFLAGS = + +CFLAGS = /W3 /MT /nologo /Yd /Zi /I. /D_WIN32_WINNT=0x400 OBJ=attr.obj \ cancel.obj \ @@ -35,33 +40,37 @@ OBJ=attr.obj \ sync.obj \ tsd.obj -all: pthread.dll +all: + @ echo Run one of the following command lines: + @ echo nmake clean VCE (to build the dll with C++ exception handling) + @ echo nmake clean VSE (to build the dll with structured exception handling) + +VCE: + @ nmake /nologo EHFLAGS="$(VCEFLAGS)" pthreadVCE.dll + +VSE: + @ nmake /nologo EHFLAGS="$(VSEFLAGS)" pthreadVSE.dll + +realclean: clean + del *.dll + del *.lib clean: - del pthread.dll - del pthread.lib del *.obj del *.ilk del *.pdb + del *.exp del *.o -install: all - copy pthread.dll $(DLLDEST) - copy pthread.lib $(LIBDEST) - -pthread.dll: $(OBJ) pthread.def - cl /LD /Zi $(CFLAGS) $(OBJ) /Fepthread.dll /link \ - /nodefaultlib:libcmt \ - /implib:pthread.lib \ - msvcrt.lib \ - /def:pthread.def - -.c.obj:: - cl /W3 $(CLIB) $(CFLAGS) /nologo /Yd /Zi /I. \ - /D_WIN32_WINNT=0x400 \ - /DSTDCALL=_stdcall \ - -c $< +install: $(DLLS) + copy pthread*.dll $(DLLDEST) + copy pthread*.lib $(LIBDEST) -$(OBJ): +$(DLLS): $(OBJ) pthread.def + cl /LD /Zi /nologo $(OBJ) \ + /link /nodefaultlib:libcmt /implib:$*.lib \ + msvcrt.lib /def:pthread.def /out:$@ +.c.obj: + cl $(EHFLAGS) $(CFLAGS) -c $< diff --git a/README b/README index af3e421..76c4dd6 100644 --- a/README +++ b/README @@ -5,27 +5,48 @@ Pthreads-win32 is free software, distributed under the GNU Library General Public License (LGPL). See the file 'COPYING.LIB' for terms and conditions. -Mailing list ------------- -There is a mailing list for discussing pthreads on Win32. To join, send email -to: +What is it? +----------- - pthreads-win32-subscribe@sources.redhat.com +Pthreads-win32 is an Open Source Software (OSS) implementation of the +Threads component of the POSIX 1003.1c 1995 Standard for Microsoft's +Win32 environment. Some functions from POSIX 1003.1b are also +supported including semaphores. Other related functions include +the set of read-write lock functions. -Unsubscribe by sending mail to: +See the file "ANNOUNCE" for more information including standards +conformance details and list of supported routines. - pthreads-win32-unsubscribe@sources.redhat.com +Library naming +-------------- -Acknowledgements ----------------- +Because the library is being built using various exception +handling schemes and compilers - and because the library +will not work reliably if these are mixed in an application, +each different version of the library has it's own name. -Pthreads-win32 is based substantially on a Win32 Pthreads implementation -contributed by John E. Bossom . Many others -have contributed important new code and bug fixes. +In general: + pthread[VG][SC]E.dll + pthread[VG][SC]E.lib -See the 'CONTRIBUTORS' file for the list of contributors. +where: + [VG] indicates the compiler + V - MS VC++ + G - GNU G++ + + [SC] indicates the exception handling scheme + S - Structured EH + C - C++ EH + +For example: + pthreadVSE.dll (VC++/SEH) + pthreadGCE.dll (G++/C++ EH) + +The GNU library archive file name has changed to: + + libpthreadw32.a (the "32" is now "w32") Known bugs in this snapshot @@ -37,16 +58,15 @@ page access) exception. The fault appears to be in the assembler code emmitted by the compiler [to handle exception contexts] at the end of the try block in _pthread_threadStart(). -2. There are problems with using the libpthread32.a file derived -from the VC++ SEH version of pthread.dll. You may have to wait until -bug(1.) is fixed. +2. There are problems using the libpthreadw32.a stub archive derived +from either of pthreadVSE.dll or pthreadVCE.dll. The cleanup1.c test +fails. + -3. I have not been able to build with VC++ using C++ EH. This is a -maintainer problem who doesn't know how to do it. Consequently -there may also be basic parser errors and warnings to be cleaned -up in the code. +Caveats +------- -4. Due to what is believed to be C++ compliance error in VC++, +1. Due to what is believed to be C++ compliance error in VC++, if your application contains catch(...) blocks in your POSIX threads then you will need to replace the "catch(...)" with the macro "PtW32Catch", eg. @@ -65,59 +85,111 @@ Otherwise neither pthreads cancelation nor pthread_exit() will work reliably. +Building under VC++ using either C++ EH or Structured EH +-------------------------------------------------------- + +From the source directory run one of the following: + +nmake clean VCE (builds the VC++ C++ EH version pthreadVCE.dll) + +or: + +nmake clean VSE (builds the VC++ structured EH version pthreadVSE.dll) + +You can run the testsuite by changing to the "tests" directory and +running the target corresponding to the DLL version you built: + +nmake clean VCE + +or: + +nmake clean VSE + + Building under Mingw32 ---------------------- pthread.dll can be built with the current development version of mingw32. Run "make" in the soruce directory (uses GNUmakefile). This builds -pthread.dll and libpthread32.a. +pthreadGCE.dll and libpthreadw32.a. + +To generate the libpthreadw32.a file from pthreadVCE.dll rather than +building the library with G++, run "make fake.a". (You must have +pthreadVCE.dll already built - see above.) +Please note that VC++ and GNU exception handling is implemented +completely differently and so automatic cleanup of objects and +the propagation of exceptions themselves between the two schemes is not +going to happen. You can run the testsuite by changing to the "tests" directory and running "make clean" and then "make". See the "Known bugs" section above. -Building under VC++ using SEH ------------------------------ +Building the library under Cygwin +--------------------------------- -From the source directory run "nmake". This builds pthread.dll and -pthread.lib. - -You can run the testsuite by changing to the "tests" directory and -running "nmake clean" and then "nmake". +Not tested by me although I think some people have done this. +Not sure how successfully though. +Cygwin is implementing it's own POSIX threads routines and these +will be the ones to use if you develop using Cygwin. -Why you cannot build the library with Cygwin yet ------------------------------------------------- -The DLL pthread.dll still cannot be built using g++ due to non thread-safe -exception handling in g++. Thanks to Kevin Ruland for researching this -one. See the FAQ Question 2 for more information. +Ready to run binaries +--------------------- -However, you can use the export library libpthread32.a built under -Mingw32 (not tested under Cygwin) together with the pthread.dll built -with MSVC. Thanks to Anders Norlander for pointing this out. - -For convenience, the following pre-built files can be downloaded from -the FTP site (see under "Availability" below): +For convenience, the following ready-to-run files can be downloaded +from the FTP site (see under "Availability" below): pthread.h semaphore.h sched.h - pthread.dll - built with MSVC cl compiler - pthread.lib - built with MSVC cl compiler - libpthread32.a - built with Mingw32 (use with MSVC pthread.dll) + pthread.def + pthreadVCE.dll - built with MSVC++ compiler using C++ EH + pthreadVCE.lib + pthreadVSE.dll - built with MSVC++ compiler using SEH + pthreadVSE.lib + pthreadGCE.dll - currently a copy of pthreadVCE.dll + libpthreadw32.a - derived from pthreadGCE.dll + + +Building applications with the library +-------------------------------------- + +Use the appropriate DLL and LIB files to match the exception handing +that you use in your application, or specifically, in your POSIX +threads. Don't mix them or neither thread cancelation nor +pthread_exit() will work reliably if at all. + + +Building applications with GNU compilers +---------------------------------------- + +[Please see the section on Known Bugs above and the section +dealing with building the library with Mingw32 before +you build applications using the GNU compilers. Please also +note that the pre-built pthreadGCE.dll is currently only +a copy of the dll built by MSVC++. Note that VC++ and +GNU exception handling is implemented completely differently +and so automatic cleanup of objects and the propagation of +exceptions themselves between the two schemes is not +going to happen. You'll need to wait for the version of +pthreadGCE.dll built be G++ itself which still has problems.] + +Use gcc-2.95.2 or later. -With these files in the same directory as your application myapp.c, -you could compile, link and run myapp.c under Mingw32 as follows: +With pthreadGCE.dll and libpthreadw32.a in the same directory as your +application myapp.c, you could compile, link and run myapp.c under +Mingw32 as follows: - gcc -o myapp.exe myapp.c -I. -L. -lpthread32 + gcc -x c++ -o myapp.exe myapp.c -I. -L. -lpthreadw32 myapp -Or put pthread.dll in an appropriate directory in your PATH, +Or put pthreadGCE.dll in an appropriate directory in your PATH, put libpthread32.a in MINGW_ROOT\i386-mingw32\lib, and put pthread.h in MINGW_ROOT\i386-mingw32\include, then use: - gcc -o myapp.exe myapp.c -lpthread32 + gcc -x c++ -o myapp.exe myapp.c -lpthreadw32 myapp @@ -137,6 +209,29 @@ Home page: http://sources.redhat.com/pthreads-win32/ + +Mailing list +------------ + +There is a mailing list for discussing pthreads on Win32. To join, send email +to: + + pthreads-win32-subscribe@sources.redhat.com + +Unsubscribe by sending mail to: + + pthreads-win32-unsubscribe@sources.redhat.com + + +Acknowledgements +---------------- + +Pthreads-win32 is based substantially on a Win32 Pthreads implementation +contributed by John E. Bossom . Many others +have contributed important new code and bug fixes. + +See the 'CONTRIBUTORS' file for the list of contributors. + ---- Ross Johnson diff --git a/buildlib.bat b/buildlib.bat index d64b4ed..0fb3f59 100644 --- a/buildlib.bat +++ b/buildlib.bat @@ -1,5 +1,5 @@ del *.obj -del pthread_*.dll +del pthread*.dll if x%1==x goto seh @@ -26,27 +26,33 @@ cl /W3 -DSTDCALL=_stdcall /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c tsd.c cl /W3 -DSTDCALL=_stdcall /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c semaphore.c cl /W3 -DSTDCALL=_stdcall /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c rwlock.c -cl /LD /Zi *.obj /Fepthread_SEH.dll /link /nodefaultlib:libcmt /implib:pthread.lib msvcrt.lib /def:pthread.def +cl /LD /Zi *.obj /Fepthread.dll /link /nodefaultlib:libcmt /implib:pthread.lib msvcrt.lib /def:pthread.def + +goto end :ceh -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c attr.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c cancel.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c cleanup.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c condvar.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c create.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c dll.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c exit.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c fork.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c global.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c misc.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c mutex.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c private.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c sched.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c signal.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c sync.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c tsd.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c semaphore.c -cl /W3 /GX /TP -D_cplusplus -DSTDCALL=_cdecl /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c rwlock.c - -cl /LD /Zi *.obj /Fepthread_C++.dll /link /nodefaultlib:libcmt /implib:pthread.lib msvcrt.lib /def:pthread.def +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c attr.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c cancel.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c cleanup.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c condvar.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c create.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c dll.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c exit.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c fork.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c global.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c misc.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c mutex.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c private.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c sched.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c signal.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c sync.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c tsd.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c semaphore.c +cl /W3 /GX /TP /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -c rwlock.c + +cl /LD /Zi *.obj /Fepthread.dll /link /nodefaultlib:libcmt /implib:pthread.lib msvcrt.lib /def:pthread.def + +goto end + +:end \ No newline at end of file diff --git a/create.c b/create.c index 48d0984..1079f07 100644 --- a/create.c +++ b/create.c @@ -161,7 +161,7 @@ pthread_create (pthread_t * tid, thread->threadH = threadH = (HANDLE) _beginthread ( - (void (*) (void *)) _pthread_threadStart, + (void (PT_STDCALL *) (void *)) _pthread_threadStart, (unsigned) stackSize, /* default stack size */ parms); diff --git a/errno.c b/errno.c index 77c747a..bd46cf5 100644 --- a/errno.c +++ b/errno.c @@ -24,7 +24,7 @@ * MA 02111-1307, USA */ -#if (! defined(HAVE_ERRNO)) || (! defined( _REENTRANT ) && ! defined( _MT )) +#if (! defined(HAVE_ERRNO)) || (! defined( _REENTRANT ) && (! defined( _MT ) || ! defined( _MD ))) #include "pthread.h" #include "implement.h" @@ -79,4 +79,4 @@ int * _errno( void ) } /* _errno */ -#endif /* (! HAVE_ERRNO) || (!_REENTRANT && !_MT) */ +#endif /* (! HAVE_ERRNO) || (!_REENTRANT && (!_MT || !_MD)) */ diff --git a/exit.c b/exit.c index ff0aab3..2b9e165 100644 --- a/exit.c +++ b/exit.c @@ -53,7 +53,7 @@ pthread_exit (void *value_ptr) { pthread_t self; -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__cplusplus) DWORD exceptionInformation[3]; @@ -83,7 +83,7 @@ pthread_exit (void *value_ptr) self->exitStatus = value_ptr; -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__cplusplus) exceptionInformation[0] = (DWORD) (_PTHREAD_EPS_EXIT); exceptionInformation[1] = (DWORD) (value_ptr); diff --git a/implement.h b/implement.h index 0e80a6e..3fc81b1 100644 --- a/implement.h +++ b/implement.h @@ -27,6 +27,16 @@ #ifndef _IMPLEMENT_H #define _IMPLEMENT_H +#ifdef __MINGW32__ +#define PT_STDCALL +#else +#ifdef __cplusplus +#define PT_STDCALL __stdcall +#else +#define PT_STDCALL __stdcall +#endif +#endif + /* changed include from to use local file during development */ #include "semaphore.h" diff --git a/misc.c b/misc.c index aa78752..ca51595 100644 --- a/misc.c +++ b/misc.c @@ -328,7 +328,7 @@ CancelableWait (HANDLE waitHandle, DWORD timeout) * Thread started with pthread_create */ -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__cplusplus) DWORD exceptionInformation[3]; diff --git a/need_errno.h b/need_errno.h index d10f951..2609f8d 100644 --- a/need_errno.h +++ b/need_errno.h @@ -1,9 +1,9 @@ /*** -*errno.h - system wide error numbers (set by system calls) +* errno.h - system wide error numbers (set by system calls) * * Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. * -*Purpose: +* Purpose: * This file defines the system-wide error numbers (set by * system calls). Conforms to the XENIX standard. Extended * for compatibility with Uniforum standard. @@ -62,12 +62,12 @@ extern "C" { /* declare reference to errno */ -#if (defined(_MT) || defined(_DLL)) && !defined(_MAC) +#if (defined(_MT) || defined(_MD) || defined(_DLL)) && !defined(_MAC) _CRTIMP extern int * __cdecl _errno(void); #define errno (*_errno()) -#else /* ndef _MT && ndef _DLL */ +#else /* ndef _MT && ndef _MD && ndef _DLL */ _CRTIMP extern int errno; -#endif /* _MT || _DLL */ +#endif /* _MT || _MD || _DLL */ /* Error Codes */ diff --git a/private.c b/private.c index c757fb8..66188aa 100644 --- a/private.c +++ b/private.c @@ -214,7 +214,7 @@ _pthread_threadStart (ThreadParms * threadParms) pthread_setspecific (_pthread_selfThreadKey, self); -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__cplusplus) __try { @@ -253,7 +253,7 @@ _pthread_threadStart (ThreadParms * threadParms) } } -#else /* _MSC_VER */ +#else /* _MSC_VER && !__cplusplus */ #ifdef __cplusplus @@ -539,7 +539,7 @@ _pthread_callUserDestroyRoutines (pthread_t thread) if (value != NULL && k->destructor != NULL) { -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__cplusplus) __try { @@ -557,7 +557,7 @@ _pthread_callUserDestroyRoutines (pthread_t thread) */ } -#else /* _MSC_VER */ +#else /* _MSC_VER && !__cplusplus */ #ifdef __cplusplus try @@ -798,7 +798,7 @@ _pthread_sem_timedwait (sem_t * sem, const struct timespec * abstime) DWORD _pthread_get_exception_services_code(void) { -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__cplusplus) return EXCEPTION_PTHREAD_SERVICES; diff --git a/pthread.def b/pthread.def index 80b6290..9f9d836 100644 --- a/pthread.def +++ b/pthread.def @@ -1,116 +1,116 @@ -; pthread.def -; Last updated: $Date: 2000/01/04 10:19:28 $ - -; Currently unimplemented functions are commented out. - -LIBRARY pthread - -EXPORTS -_pthread_processInitialize -;pthread_atfork -pthread_attr_destroy -pthread_attr_getdetachstate -;pthread_attr_getinheritsched -pthread_attr_getschedparam -;pthread_attr_getschedpolicy -;pthread_attr_getscope -pthread_attr_getstackaddr -pthread_attr_getstacksize -pthread_attr_init -pthread_attr_setdetachstate -;pthread_attr_setinheritsched -pthread_attr_setschedparam -;pthread_attr_setschedpolicy -;pthread_attr_setscope -pthread_attr_setstackaddr -pthread_attr_setstacksize -pthread_cancel -; -; These are implemented as macros -; -;pthread_cleanup_pop -;pthread_cleanup_push -; -pthread_condattr_destroy -pthread_condattr_getpshared -pthread_condattr_init -pthread_condattr_setpshared -pthread_cond_broadcast -pthread_cond_destroy -pthread_cond_init -pthread_cond_signal -pthread_cond_timedwait -pthread_cond_wait -pthread_create -pthread_detach -pthread_equal -pthread_exit -pthread_getschedparam -pthread_getspecific -pthread_join -pthread_key_create -pthread_key_delete -;pthread_kill -pthread_mutexattr_destroy -;pthread_mutexattr_getprioceiling -;pthread_mutexattr_getprotocol -pthread_mutexattr_getpshared -pthread_mutexattr_init -;pthread_mutexattr_setprioceiling -;pthread_mutexattr_setprotocol -pthread_mutexattr_setpshared -pthread_mutexattr_destroy -pthread_mutex_init -pthread_mutex_destroy -pthread_mutex_lock -pthread_mutex_trylock -pthread_mutex_unlock -pthread_once -pthread_self -pthread_setcancelstate -pthread_setcanceltype -pthread_setschedparam -pthread_setspecific -;pthread_sigmask -pthread_testcancel -; -; POSIX 1.b -; -sched_get_priority_min -sched_get_priority_max -sched_yield -sem_init -sem_destroy -sem_trywait -sem_wait -sem_post -sem_open -sem_close -sem_unlink -sem_getvalue -; -; Read/Write Locks -; -pthread_rwlock_init -pthread_rwlock_destroy -pthread_rwlock_tryrdlock -pthread_rwlock_trywrlock -pthread_rwlock_rdlock -pthread_rwlock_wrlock -pthread_rwlock_unlock -; -; Non-portable but useful -; -pthread_mutexattr_setforcecs_np -pthreadCancelableWait -pthreadCancelableTimedWait -; -; Needed if !defined(_MSC_VER) && !defined(__cplusplus) -; -pthread_push_cleanup -pthread_pop_cleanup -; -; Not for use directly. Needed by macros in pthread.h -; to return internal SEH code. -; -_pthread_get_exception_services_code +; pthread.def +; Last updated: $Date: 2000/08/14 03:43:09 $ + +; Currently unimplemented functions are commented out. + +;LIBRARY pthread + +EXPORTS +_pthread_processInitialize +;pthread_atfork +pthread_attr_destroy +pthread_attr_getdetachstate +;pthread_attr_getinheritsched +pthread_attr_getschedparam +;pthread_attr_getschedpolicy +;pthread_attr_getscope +pthread_attr_getstackaddr +pthread_attr_getstacksize +pthread_attr_init +pthread_attr_setdetachstate +;pthread_attr_setinheritsched +pthread_attr_setschedparam +;pthread_attr_setschedpolicy +;pthread_attr_setscope +pthread_attr_setstackaddr +pthread_attr_setstacksize +pthread_cancel +; +; These are implemented as macros +; +;pthread_cleanup_pop +;pthread_cleanup_push +; +pthread_condattr_destroy +pthread_condattr_getpshared +pthread_condattr_init +pthread_condattr_setpshared +pthread_cond_broadcast +pthread_cond_destroy +pthread_cond_init +pthread_cond_signal +pthread_cond_timedwait +pthread_cond_wait +pthread_create +pthread_detach +pthread_equal +pthread_exit +pthread_getschedparam +pthread_getspecific +pthread_join +pthread_key_create +pthread_key_delete +;pthread_kill +pthread_mutexattr_destroy +;pthread_mutexattr_getprioceiling +;pthread_mutexattr_getprotocol +pthread_mutexattr_getpshared +pthread_mutexattr_init +;pthread_mutexattr_setprioceiling +;pthread_mutexattr_setprotocol +pthread_mutexattr_setpshared +pthread_mutexattr_destroy +pthread_mutex_init +pthread_mutex_destroy +pthread_mutex_lock +pthread_mutex_trylock +pthread_mutex_unlock +pthread_once +pthread_self +pthread_setcancelstate +pthread_setcanceltype +pthread_setschedparam +pthread_setspecific +;pthread_sigmask +pthread_testcancel +; +; POSIX 1.b +; +sched_get_priority_min +sched_get_priority_max +sched_yield +sem_init +sem_destroy +sem_trywait +sem_wait +sem_post +sem_open +sem_close +sem_unlink +sem_getvalue +; +; Read/Write Locks +; +pthread_rwlock_init +pthread_rwlock_destroy +pthread_rwlock_tryrdlock +pthread_rwlock_trywrlock +pthread_rwlock_rdlock +pthread_rwlock_wrlock +pthread_rwlock_unlock +; +; Non-portable but useful +; +pthread_mutexattr_setforcecs_np +pthreadCancelableWait +pthreadCancelableTimedWait +; +; Needed if !defined(_MSC_VER) && !defined(__cplusplus) +; +pthread_push_cleanup +pthread_pop_cleanup +; +; Not for use directly. Needed by macros in pthread.h +; to return internal SEH code. +; +_pthread_get_exception_services_code diff --git a/pthread.h b/pthread.h index 167adff..ddfd601 100644 --- a/pthread.h +++ b/pthread.h @@ -267,6 +267,16 @@ struct timespec { #define ETIMEDOUT 10060 /* This is the value in winsock.h. */ #endif +#ifdef __MINGW32__ +#define PT_STDCALL +#else +#ifdef __cplusplus +#define PT_STDCALL __stdcall +#else +#define PT_STDCALL __stdcall +#endif +#endif + #ifdef _MSC_VER /* * Re-enable all but 4127, 4514 @@ -279,16 +289,6 @@ struct timespec { #define FALSE 0 #endif /* !TRUE */ -#ifdef __MINGW32__ -#define PT_STDCALL -#else -#ifdef __cplusplus -#define PT_STDCALL __cdecl -#else -#define PT_STDCALL __stdcall -#endif -#endif - #ifdef __cplusplus extern "C" { @@ -655,7 +655,7 @@ struct _pthread_cleanup_t * of how the code exits the scope * (i.e. such as by an exception) */ - void (*cleanUpRout)( void * ); + void (PT_STDCALL *cleanUpRout)( void * ); void * obj; int executeIt; @@ -671,7 +671,7 @@ struct _pthread_cleanup_t } PThreadCleanup( - void (*routine)( void * ), + void (PT_STDCALL *routine)( void * ), void * arg ) : cleanUpRout( routine ), obj( arg ), @@ -684,9 +684,9 @@ struct _pthread_cleanup_t ~PThreadCleanup() { - if ( executeIt && cleanUpRout != NULL ) + if ( executeIt && ((void *) cleanUpRout != NULL) ) { - (*cleanUpRout)( obj ); + (void) (*cleanUpRout)( obj ); } } @@ -928,7 +928,7 @@ int pthreadCancelableTimedWait (HANDLE waitHandle, DWORD timeout); /* * Thread-Safe C Runtime Library Mappings. */ -#if (! defined(NEED_ERRNO)) || (! defined( _REENTRANT ) && ! defined( _MT )) +#if (! defined(NEED_ERRNO)) || (! defined( _REENTRANT ) && (! defined( _MT ) || ! defined( _MD ))) int * _errno( void ); #endif @@ -1002,9 +1002,14 @@ class Pthread_exception_exit : public Pthread_exception {}; * WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll' * if you want Pthread-Win32 cancelation and pthread_exit to work. */ +#ifndef PtW32NoCatchWarn +#pragma message("When compiling applications with MSVC++ and C++ exception handling:") +#pragma message(" Replace any 'catch( ... )' with 'PtW32CatchAll' in POSIX threads") +#pragma message(" if you want POSIX thread cancelation and pthread_exit to work.") +#endif #define PtW32CatchAll \ catch( Pthread_exception & ) { throw; } \ - catch( ... ) + catch( ... ) #else #define catch( E ) \ catch( Pthread_exception & ) { throw; } \ diff --git a/tests/ChangeLog b/tests/ChangeLog index 7d7cd4a..412c09c 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,46 @@ +2000-08-13 Ross Johnson + + * condvar3.c: Minor change to eliminate compiler + warning. + + * condvar4.c: ditto. + + * condvar5.c: ditto. + + * condvar6.c: ditto. + + * condvar7.c: ditto. + + * condvar8.c: ditto. + + * condvar9.c: ditto. + + * exit1.c: Function needed return statement. + + * cleanup1.c: Remove unnecessary printf arg. + + * cleanup2.c: Fix cast. + + * rwlock6.c: Fix casts. + + * exception1.c (PtW32CatchAll): Had the wrong name; + fix casts. + + * cancel3.c: Remove unused waitLock variable. + + * GNUmakefile: Change library/dll naming; add new tests; + general minor changes. + + * Makefile: Change library/dll naming; add targets for + testing each of the two VC++ EH scheme versions; + default target now issues help message; compile warnings + now interpreted as errors to stop the make; add new + tests; restructure to remove prerequisites needed + otherwise. + + * README: Updated. + + 2000-08-10 Ross Johnson * eyal1.c (main): Change implicit cast to explicit diff --git a/tests/GNUmakefile b/tests/GNUmakefile index 3d86a0f..e8438e2 100644 --- a/tests/GNUmakefile +++ b/tests/GNUmakefile @@ -13,14 +13,14 @@ ECHO = @echo # GLANG = c++ CC = gcc -CFLAGS = -g -O2 -mthreads -UNDEBUG -Wall -x $(GLANG) +CFLAGS = -g -O0 -mthreads -UNDEBUG -Wall -x $(GLANG) BUILD_DIR = .. INCLUDES = -I. -LIBS = -L. -lpthread32 +LIBS = -L. -lpthreadw32 HDR = pthread.h semaphore.h sched.h -LIB = libpthread32.a -DLL = pthread.dll +LIB = libpthreadw32.a +DLL = pthreadGCE.dll COPYFILES = $(HDR) $(LIB) $(DLL) @@ -35,7 +35,8 @@ TESTS = loadfree \ condvar3 condvar4 condvar5 condvar6 condvar7 condvar8 condvar9 \ errno1 \ rwlock1 rwlock2 rwlock3 rwlock4 rwlock5 rwlock6 \ - context1 cancel3 cancel4 cleanup1 cleanup2 cleanup3 \ + context1 cancel3 cancel4 \ + cleanup0 cleanup1 cleanup2 cleanup3 \ exception1 PASSES = $(TESTS:%=%.pass) @@ -43,7 +44,7 @@ PASSES = $(TESTS:%=%.pass) all: $(PASSES) @ $(ECHO) ALL TESTS PASSED! Congratulations! -loadfree.pass: +loadfree.pass: pthread.dll mutex1.pass: mutex2.pass: exit1.pass: @@ -82,7 +83,8 @@ rwlock6.pass: rwlock5.pass context1.pass: cancel2.pass cancel3.pass: context1.pass cancel4.pass: cancel3.pass -cleanup1.pass: cancel4.pass +cleanup0.pass: cancel4.pass +cleanup1.pass: cleanup0.pass cleanup2.pass: cleanup1.pass cleanup3.pass: cleanup2.pass exception1.pass: cancel4.pass @@ -105,13 +107,19 @@ $(COPYFILES): @ $(ECHO) Copying $@ @ $(CP) $(BUILD_DIR)\$@ . +pthread.dll: + @ $(CP) $(DLL) $@ + clean: - $(RM) *.dll + - $(RM) *.lib - $(RM) pthread.h - $(RM) semaphore.h - $(RM) sched.h - $(RM) *.a - $(RM) *.e + - $(RM) *.obj + - $(RM) *.pdb - $(RM) *.exe - $(RM) *.pass diff --git a/tests/Makefile b/tests/Makefile index 8143b46..08cfcce 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -9,26 +9,35 @@ TOUCH = echo Passed > ECHO = @echo CPHDR = pthread.h semaphore.h sched.h -CPLIB = pthread.lib -CPDLL = pthread.dll -CFLAGS= /W3 /MT /nologo /Yd /Zi -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall +# C++ Exceptions +VCEFLAGS = /GX /TP /DPtW32NoCatchWarn +VCELIB = pthreadVCE.lib +VCEDLL = pthreadVCE.dll +# Structured Exceptions +VSEFLAGS = +VSELIB = pthreadVSE.lib +VSEDLL = pthreadVSE.dll + +CFLAGS= /W3 /WX /MT /nologo /Yd /Zi -D_WIN32_WINNT=0x400 LFLAGS= /INCREMENTAL:NO -LIBS = .\pthread.lib INCLUDES=-I. BUILD_DIR=.. COPYFILES = $(CPHDR) $(CPLIB) $(CPDLL) +TEST = +EHFLAGS = + # If a test case returns a non-zero exit code to the shell, make will # stop. PASSES= loadfree.pass \ - mutex1.pass condvar1.pass condvar2.pass \ + mutex1.pass mutex2.pass mutex3.pass \ + condvar1.pass condvar2.pass \ exit1.pass create1.pass equal1.pass \ exit2.pass exit3.pass \ join0.pass join1.pass join2.pass \ - mutex2.pass mutex3.pass \ count1.pass once1.pass tsd1.pass \ self1.pass self2.pass \ cancel1.pass cancel2.pass \ @@ -38,78 +47,53 @@ PASSES= loadfree.pass \ errno1.pass \ rwlock1.pass rwlock2.pass rwlock3.pass rwlock4.pass rwlock5.pass rwlock6.pass \ context1.pass \ - cancel3.pass cancel4.pass cleanup1.pass \ - cleanup2.pass cleanup3.pass \ + cancel3.pass cancel4.pass \ + cleanup0.pass cleanup1.pass cleanup2.pass cleanup3.pass \ exception1.pass -all: $(CPLIB) $(CPDLL) $(CPHDR) $(PASSES) - @ $(ECHO) ALL TESTS PASSED! Congratulations! +all: + @ $(ECHO) Run one of the following command lines: + @ $(ECHO) nmake clean VCE (to test using dll with C++ exception handling) + @ $(ECHO) nmake clean VSE (to test using dll with structured exception handling) -loadfree.pass: loadfree.exe -mutex1.pass: mutex1.exe -mutex2.pass: mutex2.exe -exit1.pass: exit1.exe -condvar1.pass: condvar1.exe -self1.pass: self1.exe -condvar2.pass: condvar2.exe condvar1.pass -create1.pass: create1.exe mutex2.pass -cancel1.pass: cancel1.exe create1.pass -cancel2.pass: cancel2.exe cancel1.pass -mutex3.pass: mutex3.exe create1.pass -equal1.pass: equal1.exe create1.pass -exit2.pass: exit2.exe create1.pass -exit3.pass: exit3.exe create1.pass -join0.pass: join0.exe create1.pass -join1.pass: join1.exe create1.pass -join2.pass: join2.exe create1.pass -count1.pass: count1.exe join1.pass -once1.pass: once1.exe create1.pass -tsd1.pass: tsd1.exe join1.pass -self2.pass: self2.exe create1.pass -eyal1.pass: eyal1.exe tsd1.pass -condvar3.pass: condvar3.exe create1.pass -condvar4.pass: condvar4.exe create1.pass -condvar5.pass: condvar5.exe condvar4.pass -condvar6.pass: condvar6.exe condvar5.pass -condvar7.pass: condvar7.exe condvar6.pass cleanup1.pass -condvar8.pass: condvar8.exe condvar7.pass -condvar9.pass: condvar9.exe condvar8.pass -errno1.pass: errno1.exe mutex3.pass -rwlock1.pass: rwlock1.exe condvar6.pass -rwlock2.pass: rwlock2.exe rwlock1.pass -rwlock3.pass: rwlock3.exe rwlock2.pass -rwlock4.pass: rwlock4.exe rwlock3.pass -rwlock5.pass: rwlock5.exe rwlock4.pass -rwlock6.pass: rwlock6.exe rwlock5.pass -context1.pass: context1.exe cancel2.pass -cancel3.pass: cancel3.exe context1.pass -cancel4.pass: cancel4.exe cancel3.pass -cleanup1.pass: cleanup1.exe cancel4.pass -cleanup2.pass: cleanup2.exe cleanup1.pass -cleanup3.pass: cleanup3.exe cleanup2.pass -exception1.pass: exception1.exe cancel4.pass +auto: clean VCE clean VSE + +tests: $(CPLIB) $(CPDLL) $(CPHDR) $(PASSES) + @ $(ECHO) ALL TESTS PASSED! Congratulations! $(PASSES): $*.exe + @ $(ECHO) ... Running $(TEST) test: $*.exe @ .\$*.exe - @ $(ECHO) Passed + @ $(ECHO) ...... Passed @ $(TOUCH) $*.pass +VCE: + @ nmake TEST="$@" CPLIB="$(VCELIB)" CPDLL="$(VCEDLL)" EHFLAGS="$(VCEFLAGS)" tests + +VSE: + @ nmake TEST="$@" CPLIB="$(VSELIB)" CPDLL="$(VSEDLL)" EHFLAGS="$(VSEFLAGS)" tests + .c.exe: - @ $(CC) $(CFLAGS) $(INCLUDES) $< /Fe$@ /link $(LFLAGS) $(LIBS) + @ $(ECHO) Compiling $@ + @ $(CC) $(EHFLAGS) $(CFLAGS) $(INCLUDES) $< /Fe$@ /link $(LFLAGS) $(CPLIB) .c.pre: - @ $(CC) /E $(CFLAGS) $(INCLUDES) /Fe$@ $< + @ $(CC) /E $(EHFLAGS) $(CFLAGS) $(INCLUDES) /Fe$@ $< $(COPYFILES): @ $(ECHO) Copying $@ @ $(CP) $(BUILD_DIR)\$@ . +pthread.dll: + @ $(CP) $(CPDLL) $*.dll + @ $(CP) $(CPLIB) $*.lib + clean: - $(RM) *.dll + - $(RM) *.lib - $(RM) pthread.h - $(RM) semaphore.h - $(RM) sched.h - - $(RM) *.lib - $(RM) *.e - $(RM) *.obj - $(RM) *.pdb @@ -117,3 +101,47 @@ clean: - $(RM) *.exe - $(RM) *.pass +loadfree.pass: pthread.dll +mutex1.pass: +mutex2.pass: +exit1.pass: +condvar1.pass: +self1.pass: +condvar2.pass: condvar1.pass +create1.pass: mutex2.pass +cancel1.pass: create1.pass +cancel2.pass: cancel1.pass +mutex3.pass: create1.pass +equal1.pass: create1.pass +exit2.pass: create1.pass +exit3.pass: create1.pass +join0.pass: create1.pass +join1.pass: create1.pass +join2.pass: create1.pass +count1.pass: join1.pass +once1.pass: create1.pass +tsd1.pass: join1.pass +self2.pass: create1.pass +eyal1.pass: tsd1.pass +condvar3.pass: create1.pass +condvar4.pass: create1.pass +condvar5.pass: condvar4.pass +condvar6.pass: condvar5.pass +condvar7.pass: condvar6.pass cleanup1.pass +condvar8.pass: condvar7.pass +condvar9.pass: condvar8.pass +errno1.pass: mutex3.pass +rwlock1.pass: condvar6.pass +rwlock2.pass: rwlock1.pass +rwlock3.pass: rwlock2.pass +rwlock4.pass: rwlock3.pass +rwlock5.pass: rwlock4.pass +rwlock6.pass: rwlock5.pass +context1.pass: cancel2.pass +cancel3.pass: context1.pass +cancel4.pass: cancel3.pass +cleanup0.pass: cancel4.pass +cleanup1.pass: cleanup0.pass +cleanup2.pass: cleanup1.pass +cleanup3.pass: cleanup2.pass +exception1.pass: cancel4.pass diff --git a/tests/README b/tests/README index fa3c0bf..b767f89 100644 --- a/tests/README +++ b/tests/README @@ -1,13 +1,31 @@ Running test cases in this directory ------------------------------------ -runtest.bat is included for compiling and running tests. +These make scripts expect to be able to copy the dll, libarary +and header files from this directory's parent directory, +which should be the pthreads-win32 source directory. -Usage: runtest cl|gcc testname +MS VC++ nmake +------------- - "cl" calls the VC++ cl compiler/linker - "gcc" calls the GNU gcc compiler/linker - "testname" is the name of the C source file without the .c +Run the target corresponding to the DLL version being tested: + +nmake clean VCE + +or: + +nmake clean VSE + + +GNU G++ make +------------ + +Run "make clean" and then "make". See the "Known bugs" section +in ..\README. + + +Writing Test Cases +------------------ Tests written in this test suite should behave in the following manner: diff --git a/tests/cancel3.c b/tests/cancel3.c index e2ffc2b..1a39ecb 100644 --- a/tests/cancel3.c +++ b/tests/cancel3.c @@ -60,8 +60,6 @@ struct bag_t_ { static bag_t threadbag[NUMTHREADS + 1]; -static pthread_mutex_t waitLock = PTHREAD_MUTEX_INITIALIZER; - void * mythread(void * arg) { diff --git a/tests/cleanup1.c b/tests/cleanup1.c index 2c8e9a6..68478fa 100644 --- a/tests/cleanup1.c +++ b/tests/cleanup1.c @@ -159,10 +159,9 @@ main() if (fail) { - fprintf(stderr, "Thread %d: started %d: count %d: result %d\n", + fprintf(stderr, "Thread %d: started %d: result %d\n", i, threadbag[i].started, - threadbag[i].count, result); } failed = (failed || fail); diff --git a/tests/cleanup2.c b/tests/cleanup2.c index 515f676..6d07d53 100644 --- a/tests/cleanup2.c +++ b/tests/cleanup2.c @@ -135,7 +135,7 @@ main() int fail = 0; int result = 0; - assert(pthread_join(t[i], (void *) &result) == 0); + assert(pthread_join(t[i], (void **) &result) == 0); fail = (result != 0); diff --git a/tests/cleanup3.c b/tests/cleanup3.c index 4f05eea..56b1a8f 100644 --- a/tests/cleanup3.c +++ b/tests/cleanup3.c @@ -138,7 +138,7 @@ main() int fail = 0; int result = 0; - assert(pthread_join(t[i], (void *) &result) == 0); + assert(pthread_join(t[i], (void **) &result) == 0); fail = (result != 0); diff --git a/tests/condvar3.c b/tests/condvar3.c index a25c15a..673feb5 100644 --- a/tests/condvar3.c +++ b/tests/condvar3.c @@ -96,7 +96,7 @@ main() abstime.tv_sec += 5; - while (! shared > 0) + while (! (shared > 0)) assert(pthread_cond_timedwait(&cv, &mutex, &abstime) == 0); assert(shared > 0); diff --git a/tests/condvar4.c b/tests/condvar4.c index 4729063..2ef1d79 100644 --- a/tests/condvar4.c +++ b/tests/condvar4.c @@ -118,7 +118,7 @@ main() abstime.tv_sec += 5; - while (! cvthing.shared > 0) + while (! (cvthing.shared > 0)) assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); assert(cvthing.shared > 0); diff --git a/tests/condvar5.c b/tests/condvar5.c index d0d15a1..56510c5 100644 --- a/tests/condvar5.c +++ b/tests/condvar5.c @@ -117,7 +117,7 @@ main() abstime.tv_sec += 5; - while (! cvthing.shared > 0) + while (! (cvthing.shared > 0)) assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); assert(cvthing.shared > 0); diff --git a/tests/condvar6.c b/tests/condvar6.c index 7348346..dc29f48 100644 --- a/tests/condvar6.c +++ b/tests/condvar6.c @@ -93,7 +93,7 @@ mythread(void * arg) assert(pthread_mutex_lock(&cvthing.lock) == 0); - while (! cvthing.shared > 0) + while (! (cvthing.shared > 0)) assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); assert(cvthing.shared > 0); diff --git a/tests/condvar7.c b/tests/condvar7.c index 3745f02..23e2441 100644 --- a/tests/condvar7.c +++ b/tests/condvar7.c @@ -95,7 +95,7 @@ mythread(void * arg) pthread_cleanup_push(pthread_mutex_unlock, (void *) &cvthing.lock); - while (! cvthing.shared > 0) + while (! (cvthing.shared > 0)) assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); pthread_cleanup_pop(0); diff --git a/tests/condvar8.c b/tests/condvar8.c index d1076e3..9e63b79 100644 --- a/tests/condvar8.c +++ b/tests/condvar8.c @@ -99,7 +99,7 @@ mythread(void * arg) */ pthread_cleanup_push(pthread_mutex_unlock, (void *) &cvthing.lock); - while (! cvthing.shared > 0) + while (! (cvthing.shared > 0)) assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); pthread_cleanup_pop(0); diff --git a/tests/condvar9.c b/tests/condvar9.c index 7d24d09..6591554 100644 --- a/tests/condvar9.c +++ b/tests/condvar9.c @@ -100,7 +100,7 @@ mythread(void * arg) */ pthread_cleanup_push(pthread_mutex_unlock, (void *) &cvthing.lock); - while (! cvthing.shared > 0) + while (! (cvthing.shared > 0)) assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); pthread_cleanup_pop(0); diff --git a/tests/exception1.c b/tests/exception1.c index eddd8fb..609e5ed 100644 --- a/tests/exception1.c +++ b/tests/exception1.c @@ -136,8 +136,8 @@ canceledThread(void * arg) for (count = 0; count < 100; count++) Sleep(100); } -#if defined(_MSC_VER) - AltCatchAll +#if defined(PtW32CatchAll) + PtW32CatchAll #else catch (...) #endif @@ -192,13 +192,13 @@ main() int result = 0; /* Canceled thread */ - assert(pthread_join(ct[i], (void *) &result) == 0); + assert(pthread_join(ct[i], (void **) &result) == 0); fail = (result != (int) PTHREAD_CANCELED); failed = (failed || fail); /* Exception thread */ - assert(pthread_join(et[i], (void *) &result) == 0); + assert(pthread_join(et[i], (void **) &result) == 0); fail = (result != ((int) PTHREAD_CANCELED + 2)); failed = (failed || fail); diff --git a/tests/exit1.c b/tests/exit1.c index 251a46c..06b7692 100644 --- a/tests/exit1.c +++ b/tests/exit1.c @@ -14,4 +14,5 @@ main(int argc, char * argv[]) /* Not reached */ assert(0); + return 0; } diff --git a/tests/rwlock6.c b/tests/rwlock6.c index 38bc419..7daccd7 100644 --- a/tests/rwlock6.c +++ b/tests/rwlock6.c @@ -53,9 +53,9 @@ main() Sleep(200); assert(pthread_create(&wrt2, NULL, wrfunc, NULL) == 0); - assert(pthread_join(wrt1, (void *) &wr1Result) == 0); - assert(pthread_join(wrt2, (void *) &wr2Result) == 0); - assert(pthread_join(rdt, (void *) &rdResult) == 0); + assert(pthread_join(wrt1, (void **) &wr1Result) == 0); + assert(pthread_join(wrt2, (void **) &wr2Result) == 0); + assert(pthread_join(rdt, (void **) &rdResult) == 0); assert(wr1Result == 10); assert(wr2Result == 20); -- cgit v1.2.3