summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpj <rpj>2002-03-02 01:53:08 +0000
committerrpj <rpj>2002-03-02 01:53:08 +0000
commit44c245b3ed9e82cc44a5ade4a941c99f63174021 (patch)
tree4a7b209123299d176826442200de02fed08afb7d
parent8200f6ff1edca15756a22e6359f20836c4b5425b (diff)
* errno.c: Compiler directive was incorrectly including code.
* pthread.h: Conditionally added some #defines from config.h needed when not building the library. e.g. NEED_ERRNO, NEED_SEM. (PTW32_DLLPORT): Now only defined if _DLL defined. (_errno): Compiler directive was incorrectly including prototype. * sched.h: Conditionally added some #defines from config.h needed when not building the library. * semaphore.h: Replace an instance of NEED_SEM that should have been NEED_ERRNO. This change currently has nil effect. * GNUmakefile: Correct some recent changes. * Makefile: Add rule to generate pre-processor output.
-rw-r--r--ANNOUNCE28
-rw-r--r--ChangeLog16
-rw-r--r--GNUmakefile17
-rw-r--r--Makefile4
-rw-r--r--errno.c21
-rw-r--r--pthread.h49
-rw-r--r--sched.h26
-rw-r--r--semaphore.h2
-rw-r--r--tests/ChangeLog8
-rw-r--r--tests/GNUmakefile4
-rw-r--r--tests/Makefile8
-rw-r--r--tests/exception3.c2
-rw-r--r--tests/rwlock2_t.c80
-rw-r--r--tests/rwlock3_t.c89
-rw-r--r--tests/rwlock4_t.c89
-rw-r--r--tests/rwlock5_t.c91
-rw-r--r--tests/rwlock6_t.c128
-rw-r--r--tests/rwlock6_t2.c121
-rw-r--r--tests/semaphore1.c159
19 files changed, 901 insertions, 41 deletions
diff --git a/ANNOUNCE b/ANNOUNCE
index bedeeb1..7e47bd4 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -259,11 +259,21 @@ Known bugs in this snapshot
---------------------------
1. Under MS VC++ (only tested with version 6.0), a term_func
- set via the standard C++ set_terminate() function is not called
- for some reason. The code in private.c ptw32_threadStart()
- retrieves and calls the user supplied terminate routine, which
- works as expected under MinGW32 g++, but doesn't run under
- MS VC++ 6.0, presumably because set_terminate() returns NULL.
+ set via the standard C++ set_terminate() function is not called.
+
+ Notes from the MSVC++ manual:
+ 1) A term_func() should call exit(), otherwise
+ abort() will be called on return to the caller.
+ A call to abort() raises SIGABRT and the default signal handler
+ for all signals terminates the calling program with
+ exit code 3.
+ 2) A term_func() must not throw an exception. Therefore
+ term_func() should not call pthread_exit(), which
+ works by throwing an exception (pthreadVCE or pthreadVSE)
+ or by calling longjmp (pthreadVC).
+
+ Workaround: avoid using pthread_exit() in C++ applications. Exit
+ threads by dropping through the end of the thread routine.
2. Cancellation problems in optimised code
- Milan Gardian
@@ -344,9 +354,13 @@ Known bugs in this snapshot
creation of production code is highly unreliable for the current version of
the pthreads library.
+3. errno
-Caveats
--------
+ Under MSVC, errno isn't working.
+
+
+Special notes
+-------------
1. [See also the discussion in the FAQ file - Q2, Q4, and Q5]
diff --git a/ChangeLog b/ChangeLog
index 9c1adff..9a2413d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2002-02-28 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
+
+ * errno.c: Compiler directive was incorrectly including code.
+ * pthread.h: Conditionally added some #defines from config.h
+ needed when not building the library. e.g. NEED_ERRNO, NEED_SEM.
+ (PTW32_DLLPORT): Now only defined if _DLL defined.
+ (_errno): Compiler directive was incorrectly including prototype.
+ * sched.h: Conditionally added some #defines from config.h
+ needed when not building the library.
+ * semaphore.h: Replace an instance of NEED_SEM that should
+ have been NEED_ERRNO. This change currently has nil effect.
+
+ * GNUmakefile: Correct some recent changes.
+
+ * Makefile: Add rule to generate pre-processor output.
+
2002-02-23 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
* pthread_rwlock_timedrdlock.c: New - untested.
diff --git a/GNUmakefile b/GNUmakefile
index 46558fd..c205458 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -432,30 +432,31 @@ tests:
.c.o:; $(CC) -c -o $@ $(CFLAGS) $(CLEANUP_FLAGS) $<
-$(PTHREAD_DEF): $(OBJS)
- dlltool -z pthread.def $(DLL_INLINED_OBJS)
-
-$(GC_DLL): $(DLL_OBJS) $(PTHREAD_DEF)
+$(GC_DLL): $(DLL_OBJS)
$(CC) $(OPT) -shared -o $(GC_DLL) $(DLL_OBJS) $(LFLAGS)
+ dlltool -z pthread.def $(DLL_OBJS)
dlltool -k --dllname $@ --output-lib $(GC_LIB) --def $(PTHREAD_DEF)
-$(GCE_DLL): $(DLL_OBJS) $(PTHREAD_DEF)
+$(GCE_DLL): $(DLL_OBJS)
$(CXX) $(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)
-$(GC_INLINED_STAMP): $(DLL_INLINED_OBJS) $(PTHREAD_DEF)
+$(GC_INLINED_STAMP): $(DLL_INLINED_OBJS)
$(CC) $(OPT) -shared -o $(GC_DLL) $(DLL_INLINED_OBJS) $(LFLAGS)
+ dlltool -z pthread.def $(DLL_INLINED_OBJS)
dlltool -k --dllname $(GC_DLL) --output-lib $(GC_LIB) --def $(PTHREAD_DEF)
echo touched > $(GC_INLINED_STAMP)
-$(GCE_INLINED_STAMP): $(DLL_INLINED_OBJS) $(PTHREAD_DEF)
+$(GCE_INLINED_STAMP): $(DLL_INLINED_OBJS)
$(CXX) $(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)
clean:
-$(RM) *~
- -$(RM) *.pre
+ -$(RM) *.i
-$(RM) *.o
-$(RM) *.exe
-$(RM) $(PTHREAD_DEF)
diff --git a/Makefile b/Makefile
index 5f8767a..b5d6231 100644
--- a/Makefile
+++ b/Makefile
@@ -388,6 +388,7 @@ clean:
if exist *.pdb del *.pdb
if exist *.exp del *.exp
if exist *.o del *.o
+ if exist *.i del *.i
install: $(DLLS)
@@ -407,6 +408,9 @@ $(INLINED_STAMPS): $(DLL_INLINED_OBJS)
.c.obj:
cl $(EHFLAGS) -c $<
+.c.i:
+ cl /P /O2 /Ob1 $(VCFLAGS) $<
+
attr.obj: attr.c $(ATTR_SRCS) $(INCL)
barrier.obj: barrier.c $(BARRIER_SRCS) $(INCL)
cancel.obj: cancel.c $(CANCEL_SRCS) $(INCL)
diff --git a/errno.c b/errno.c
index de913c3..385ad71 100644
--- a/errno.c
+++ b/errno.c
@@ -10,32 +10,32 @@
* Pthreads-win32 - POSIX Threads Library for Win32
* Copyright(C) 1998 John E. Bossom
* Copyright(C) 1999,2002 Pthreads-win32 contributors
- *
+ *
* Contact Email: rpj@ise.canberra.edu.au
- *
+ *
* The current list of contributors is contained
* in the file CONTRIBUTORS included with the source
* code distribution. The list can also be seen at the
* following World Wide Web location:
* http://sources.redhat.com/pthreads-win32/contributors.html
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library in the file COPYING.LIB;
* if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
-#if (! defined(HAVE_ERRNO)) && (! defined(_REENTRANT)) && (! defined(_MT))
+#if defined(NEED_ERRNO)
#include "pthread.h"
#include "implement.h"
@@ -56,11 +56,11 @@ static int reallyBad = ENOMEM;
* it on thread termination. We get all that for free
* by simply storing the errno on the pthread_t structure.
*
- * MSVC and Mingw32 already have there own thread-safe errno.
+ * MSVC and Mingw32 already have their own thread-safe errno.
*
* #if defined( _REENTRANT ) || defined( _MT )
* #define errno *_errno()
- *
+ *
* int *_errno( void );
* #else
* extern int errno;
@@ -72,7 +72,7 @@ int * _errno( void )
{
pthread_t self;
int *result;
-
+
if( ( self = pthread_self() ) == NULL )
{
/*
@@ -90,4 +90,5 @@ int * _errno( void )
} /* _errno */
-#endif /* (! HAVE_ERRNO) || (!_REENTRANT && (!_MT || !_MD)) */
+#endif /* (NEED_ERRNO) */
+
diff --git a/pthread.h b/pthread.h
index e197ebe..3e37f81 100644
--- a/pthread.h
+++ b/pthread.h
@@ -197,11 +197,32 @@
#include <setjmp.h>
+/*
+ * This is a duplicate of what is in the autoconf config.h,
+ * which is only used when building the pthread-win32 libraries.
+ */
+
+#ifndef PTW32_CONFIG_H
+# if defined(WINCE)
+# define NEED_ERRNO
+# define NEED_SEM
+# endif
+# if defined(_UWIN) || defined(__MINGW32__)
+# define HAVE_MODE_T
+# endif
+#endif
+
+/*
+ *
+ */
+
+#if PTW32_LEVEL >= PTW32_LEVEL_MAX
#ifdef NEED_ERRNO
-# include "need_errno.h"
+#include "need_errno.h"
#else
-# include <errno.h>
+#include <errno.h>
#endif
+#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
/*
* Several systems don't define ENOTSUP. If not, we use
@@ -447,13 +468,14 @@ extern "C"
* do NOT define PTW32_BUILD, and then the variables/functions will
* be imported correctly.
*/
-#ifdef PTW32_BUILD
-# define PTW32_DLLPORT __declspec (dllexport)
-#else
-# define PTW32_DLLPORT __declspec (dllimport)
+#ifdef _DLL
+# ifdef PTW32_BUILD
+# define PTW32_DLLPORT __declspec (dllexport)
+# else
+# define PTW32_DLLPORT __declspec (dllimport)
+# endif
#endif
-
#if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX
# include <sys/types.h>
#else
@@ -1104,9 +1126,16 @@ PTW32_DLLPORT int pthreadCancelableTimedWait (HANDLE waitHandle,
* Thread-Safe C Runtime Library Mappings.
*/
#ifndef _UWIN
-#if (! defined(HAVE_ERRNO)) && (! defined(_REENTRANT)) && (! defined(_MT))
-PTW32_DLLPORT int * _errno( void );
-#endif
+# if defined(NEED_ERRNO)
+ PTW32_DLLPORT int * _errno( void );
+# else
+# ifndef errno
+# if (defined(_MT) || defined(_DLL))
+ __declspec(dllimport) extern int * __cdecl _errno(void);
+# define errno (*_errno())
+# endif
+# endif
+# endif
#endif
/*
diff --git a/sched.h b/sched.h
index f6a732d..e822ca4 100644
--- a/sched.h
+++ b/sched.h
@@ -82,6 +82,32 @@
# define PTW32_DLLPORT __declspec (dllimport)
#endif
+/*
+ * This is a duplicate of what is in the autoconf config.h,
+ * which is only used when building the pthread-win32 libraries.
+ */
+
+#ifndef PTW32_CONFIG_H
+# if defined(WINCE)
+# define NEED_ERRNO
+# define NEED_SEM
+# endif
+# if defined(_UWIN) || defined(__MINGW32__)
+# define HAVE_MODE_T
+# endif
+#endif
+
+/*
+ *
+ */
+
+#if PTW32_LEVEL >= PTW32_LEVEL_MAX
+#ifdef NEED_ERRNO
+#include "need_errno.h"
+#else
+#include <errno.h>
+#endif
+#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
#if defined(__MINGW32__) || defined(_UWIN)
#if PTW32_LEVEL >= PTW32_LEVEL_MAX
diff --git a/semaphore.h b/semaphore.h
index 2956066..2fac0fe 100644
--- a/semaphore.h
+++ b/semaphore.h
@@ -102,7 +102,7 @@
*/
#if PTW32_LEVEL >= PTW32_LEVEL_MAX
-#ifdef NEED_SEM
+#ifdef NEED_ERRNO
#include "need_errno.h"
#else
#include <errno.h>
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 663db9b..bc42f7e 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,13 @@
2002-02-28 Ross Johnson <rpj@special.ise.canberra.edu.au>
+ * exception3.c: Correct recent change.
+
+ * semaphore1.c: New test.
+
+ * Makefile: Add rule to generate pre-processor output.
+
+2002-02-28 Ross Johnson <rpj@special.ise.canberra.edu.au>
+
* exception3.c (terminateFunction): For MSVC++, call
exit() rather than pthread_exit(). Add comments to explain
why.
diff --git a/tests/GNUmakefile b/tests/GNUmakefile
index 800d33a..9a0902e 100644
--- a/tests/GNUmakefile
+++ b/tests/GNUmakefile
@@ -65,7 +65,7 @@ COPYFILES = $(HDR) $(LIB) $(DLL)
# stop.
TESTS = loadfree \
- self1 mutex5 mutex1 mutex1e mutex1n mutex1r \
+ semaphore1 self1 mutex5 mutex1 mutex1e mutex1n mutex1r \
condvar1 condvar1_1 condvar1_2 condvar2 condvar2_1 exit1 create1 equal1 \
exit2 exit3 \
join0 join1 join2 \
@@ -222,6 +222,7 @@ rwlock6_t.pass: rwlock5_t.pass
rwlock6_t2.pass: rwlock6_t.pass
self1.pass:
self2.pass: create1.pass
+semaphore1.pass:
spin1.pass:
spin2.pass: spin1.pass
spin3.pass: spin2.pass
@@ -267,6 +268,7 @@ clean:
- $(RM) sched.h
- $(RM) *.a
- $(RM) *.e
+ - $(RM) *.i
- $(RM) *.obj
- $(RM) *.pdb
- $(RM) *.exe
diff --git a/tests/Makefile b/tests/Makefile
index 00e886f..f684f31 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -71,7 +71,7 @@ EHFLAGS =
# stop.
PASSES= loadfree.pass \
- self1.pass mutex5.pass \
+ semaphore1.pass self1.pass mutex5.pass \
mutex1.pass mutex1n.pass mutex1e.pass mutex1r.pass mutex2.pass mutex3.pass \
condvar1.pass condvar1_1.pass condvar1_2.pass condvar2.pass condvar2_1.pass \
exit1.pass create1.pass equal1.pass \
@@ -166,8 +166,8 @@ VCX-bench:
@ $(ECHO) $(CC) $(EHFLAGS) $(CFLAGS) $(INCLUDES) $< /Fe$@ /link $(LFLAGS) $(CPLIB)
@ $(CC) $(EHFLAGS) $(CFLAGS) $(INCLUDES) $< /Fe$@ /link $(LFLAGS) $(CPLIB)
-.c.pre:
- @ $(CC) /E $(EHFLAGS) $(CFLAGS) $(INCLUDES) /Fe$@ $<
+.c.i:
+ @ $(CC) /P $(EHFLAGS) $(CFLAGS) $(INCLUDES) $<
$(COPYFILES):
@ $(ECHO) Copying $@
@@ -184,6 +184,7 @@ clean:
- $(RM) semaphore.h
- $(RM) sched.h
- $(RM) *.e
+ - $(RM) *.i
- $(RM) *.obj
- $(RM) *.pdb
- $(RM) *.o
@@ -287,6 +288,7 @@ rwlock6_t.pass: rwlock5_t.pass
rwlock6_t2.pass: rwlock6_t.pass
self1.pass:
self2.pass: create1.pass
+semaphore.pass:
spin1.pass:
spin2.pass: spin1.pass
spin3.pass: spin2.pass
diff --git a/tests/exception3.c b/tests/exception3.c
index 3d9ea86..d3eb364 100644
--- a/tests/exception3.c
+++ b/tests/exception3.c
@@ -117,7 +117,7 @@ terminateFunction ()
* through or to MSVC++ code, and vice versa.
* Applications should probably not depend on this.
*/
- pthread_exit((void *) 0));
+ pthread_exit((void *) 0);
#else
/*
* Notes from the MSVC++ manual:
diff --git a/tests/rwlock2_t.c b/tests/rwlock2_t.c
new file mode 100644
index 0000000..b0c9998
--- /dev/null
+++ b/tests/rwlock2_t.c
@@ -0,0 +1,80 @@
+/*
+ * rwlock2_t.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@ise.canberra.edu.au
+ *
+ * The current list of contributors is contained
+ * in the file CONTRIBUTORS included with the source
+ * code distribution. The list can also be seen at the
+ * following World Wide Web location:
+ * http://sources.redhat.com/pthreads-win32/contributors.html
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Declare a static rwlock object, timed-lock it,
+ * and then unlock it again.
+ *
+ * Depends on API functions:
+ * pthread_rwlock_timedrdlock()
+ * pthread_rwlock_unlock()
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
+
+int
+main()
+{
+ struct timespec abstime = { 0, 0 };
+ struct _timeb currSysTime;
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ abstime.tv_sec += 1;
+
+ assert(rwlock == PTHREAD_RWLOCK_INITIALIZER);
+
+ assert(pthread_rwlock_timedrdlock(&rwlock, &abstime) == 0);
+
+ assert(rwlock != PTHREAD_RWLOCK_INITIALIZER);
+
+ assert(rwlock != NULL);
+
+ assert(pthread_rwlock_unlock(&rwlock) == 0);
+
+ assert(pthread_rwlock_destroy(&rwlock) == 0);
+
+ assert(rwlock == NULL);
+
+ return 0;
+}
diff --git a/tests/rwlock3_t.c b/tests/rwlock3_t.c
new file mode 100644
index 0000000..ad4ea2c
--- /dev/null
+++ b/tests/rwlock3_t.c
@@ -0,0 +1,89 @@
+/*
+ * rwlock3_t.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@ise.canberra.edu.au
+ *
+ * The current list of contributors is contained
+ * in the file CONTRIBUTORS included with the source
+ * code distribution. The list can also be seen at the
+ * following World Wide Web location:
+ * http://sources.redhat.com/pthreads-win32/contributors.html
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Declare a static rwlock object, timed-wrlock it, trywrlock it,
+ * and then unlock it again.
+ *
+ * Depends on API functions:
+ * pthread_rwlock_timedwrlock()
+ * pthread_rwlock_trywrlock()
+ * pthread_rwlock_unlock()
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
+
+static int washere = 0;
+
+void * func(void * arg)
+{
+ assert(pthread_rwlock_trywrlock(&rwlock1) == EBUSY);
+
+ washere = 1;
+
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t;
+ struct timespec abstime = { 0, 0 };
+ struct _timeb currSysTime;
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ abstime.tv_sec += 1;
+
+ assert(pthread_rwlock_timedwrlock(&rwlock1, &abstime) == 0);
+
+ assert(pthread_create(&t, NULL, func, NULL) == 0);
+
+ Sleep(2000);
+
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+
+ assert(washere == 1);
+
+ return 0;
+}
diff --git a/tests/rwlock4_t.c b/tests/rwlock4_t.c
new file mode 100644
index 0000000..68e1420
--- /dev/null
+++ b/tests/rwlock4_t.c
@@ -0,0 +1,89 @@
+/*
+ * rwlock4_t.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@ise.canberra.edu.au
+ *
+ * The current list of contributors is contained
+ * in the file CONTRIBUTORS included with the source
+ * code distribution. The list can also be seen at the
+ * following World Wide Web location:
+ * http://sources.redhat.com/pthreads-win32/contributors.html
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Declare a static rwlock object, timed-rdlock it, trywrlock it,
+ * and then unlock it again.
+ *
+ * Depends on API functions:
+ * pthread_rwlock_timedrdlock()
+ * pthread_rwlock_trywrlock()
+ * pthread_rwlock_unlock()
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
+
+static int washere = 0;
+
+void * func(void * arg)
+{
+ assert(pthread_rwlock_trywrlock(&rwlock1) == EBUSY);
+
+ washere = 1;
+
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t;
+ struct timespec abstime = { 0, 0 };
+ struct _timeb currSysTime;
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ abstime.tv_sec += 1;
+
+ assert(pthread_rwlock_timedrdlock(&rwlock1, &abstime) == 0);
+
+ assert(pthread_create(&t, NULL, func, NULL) == 0);
+
+ Sleep(2000);
+
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+
+ assert(washere == 1);
+
+ return 0;
+}
diff --git a/tests/rwlock5_t.c b/tests/rwlock5_t.c
new file mode 100644
index 0000000..dc3cd52
--- /dev/null
+++ b/tests/rwlock5_t.c
@@ -0,0 +1,91 @@
+/*
+ * rwlock5_t.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@ise.canberra.edu.au
+ *
+ * The current list of contributors is contained
+ * in the file CONTRIBUTORS included with the source
+ * code distribution. The list can also be seen at the
+ * following World Wide Web location:
+ * http://sources.redhat.com/pthreads-win32/contributors.html
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Declare a static rwlock object, timed-rdlock it, tryrdlock it,
+ * and then unlock it again.
+ *
+ * Depends on API functions:
+ * pthread_rwlock_timedrdlock()
+ * pthread_rwlock_tryrdlock()
+ * pthread_rwlock_unlock()
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
+
+static int washere = 0;
+
+void * func(void * arg)
+{
+ assert(pthread_rwlock_tryrdlock(&rwlock1) == 0);
+
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+
+ washere = 1;
+
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t;
+ struct timespec abstime = { 0, 0 };
+ struct _timeb currSysTime;
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ abstime.tv_sec += 1;
+
+ assert(pthread_rwlock_timedrdlock(&rwlock1, &abstime) == 0);
+
+ assert(pthread_create(&t, NULL, func, NULL) == 0);
+
+ Sleep(2000);
+
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+
+ assert(washere == 1);
+
+ return 0;
+}
diff --git a/tests/rwlock6_t.c b/tests/rwlock6_t.c
new file mode 100644
index 0000000..bf40258
--- /dev/null
+++ b/tests/rwlock6_t.c
@@ -0,0 +1,128 @@
+/*
+ * rwlock6_t.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@ise.canberra.edu.au
+ *
+ * The current list of contributors is contained
+ * in the file CONTRIBUTORS included with the source
+ * code distribution. The list can also be seen at the
+ * following World Wide Web location:
+ * http://sources.redhat.com/pthreads-win32/contributors.html
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Check writer and reader locking with reader timeouts
+ *
+ * Depends on API functions:
+ * pthread_rwlock_timedrdlock()
+ * pthread_rwlock_wrlock()
+ * pthread_rwlock_unlock()
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+static pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
+
+static int bankAccount = 0;
+
+void * wrfunc(void * arg)
+{
+ assert(pthread_rwlock_wrlock(&rwlock1) == 0);
+ Sleep(2000);
+ bankAccount += 10;
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+
+ return ((void *) bankAccount);
+}
+
+void * rdfunc(void * arg)
+{
+ int ba = -1;
+ struct timespec abstime = { 0, 0 };
+ struct _timeb currSysTime;
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+
+ if ((int) arg == 1)
+ {
+ abstime.tv_sec += 1;
+ assert(pthread_rwlock_timedrdlock(&rwlock1, &abstime) == ETIMEDOUT);
+ ba = 0;
+ }
+ else if ((int) arg == 2)
+ {
+ abstime.tv_sec += 3;
+ assert(pthread_rwlock_timedrdlock(&rwlock1, &abstime) == 0);
+ ba = bankAccount;
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+ }
+
+ return ((void *) ba);
+}
+
+int
+main()
+{
+ pthread_t wrt1;
+ pthread_t wrt2;
+ pthread_t rdt1;
+ pthread_t rdt2;
+ int wr1Result = 0;
+ int wr2Result = 0;
+ int rd1Result = 0;
+ int rd2Result = 0;
+
+ bankAccount = 0;
+
+ assert(pthread_create(&wrt1, NULL, wrfunc, NULL) == 0);
+ Sleep(500);
+ assert(pthread_create(&rdt1, NULL, rdfunc, (void *) 1) == 0);
+ Sleep(500);
+ assert(pthread_create(&wrt2, NULL, wrfunc, NULL) == 0);
+ Sleep(500);
+ assert(pthread_create(&rdt2, NULL, rdfunc, (void *) 2) == 0);
+
+ assert(pthread_join(wrt1, (void **) &wr1Result) == 0);
+ assert(pthread_join(rdt1, (void **) &rd1Result) == 0);
+ assert(pthread_join(wrt2, (void **) &wr2Result) == 0);
+ assert(pthread_join(rdt2, (void **) &rd2Result) == 0);
+
+ assert(wr1Result == 10);
+ assert(rd1Result == 0);
+ assert(wr2Result == 20);
+ assert(rd2Result == 20);
+
+ return 0;
+}
+
+
diff --git a/tests/rwlock6_t2.c b/tests/rwlock6_t2.c
new file mode 100644
index 0000000..532cc39
--- /dev/null
+++ b/tests/rwlock6_t2.c
@@ -0,0 +1,121 @@
+/*
+ * rwlock6_t2.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@ise.canberra.edu.au
+ *
+ * The current list of contributors is contained
+ * in the file CONTRIBUTORS included with the source
+ * code distribution. The list can also be seen at the
+ * following World Wide Web location:
+ * http://sources.redhat.com/pthreads-win32/contributors.html
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Check writer and reader timeouts.
+ *
+ * Depends on API functions:
+ * pthread_rwlock_timedrdlock()
+ * pthread_rwlock_timedwrlock()
+ * pthread_rwlock_unlock()
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+static pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
+
+static int bankAccount = 0;
+struct timespec abstime = { 0, 0 };
+
+void * wrfunc(void * arg)
+{
+ int result;
+
+ result = pthread_rwlock_timedwrlock(&rwlock1, &abstime);
+ if ((int) arg == 1)
+ {
+ assert(result == 0);
+ Sleep(2000);
+ bankAccount += 10;
+ assert(pthread_rwlock_unlock(&rwlock1) == 0);
+ return ((void *) bankAccount);
+ }
+ else if ((int) arg == 2)
+ {
+ assert(result == ETIMEDOUT);
+ return ((void *) 100);
+ }
+
+ return ((void *) -1);
+}
+
+void * rdfunc(void * arg)
+{
+ int ba = 0;
+
+ assert(pthread_rwlock_timedrdlock(&rwlock1, &abstime) == ETIMEDOUT);
+
+ return ((void *) ba);
+}
+
+int
+main()
+{
+ pthread_t wrt1;
+ pthread_t wrt2;
+ pthread_t rdt;
+ int wr1Result = 0;
+ int wr2Result = 0;
+ int rdResult = 0;
+ struct _timeb currSysTime;
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ abstime.tv_sec += 1;
+
+ bankAccount = 0;
+
+ assert(pthread_create(&wrt1, NULL, wrfunc, (void *) 1) == 0);
+ Sleep(100);
+ assert(pthread_create(&rdt, NULL, rdfunc, NULL) == 0);
+ Sleep(100);
+ assert(pthread_create(&wrt2, NULL, wrfunc, (void *) 2) == 0);
+
+ assert(pthread_join(wrt1, (void **) &wr1Result) == 0);
+ assert(pthread_join(rdt, (void **) &rdResult) == 0);
+ assert(pthread_join(wrt2, (void **) &wr2Result) == 0);
+
+ assert(wr1Result == 10);
+ assert(rdResult == 0);
+ assert(wr2Result == 100);
+
+ return 0;
+}
diff --git a/tests/semaphore1.c b/tests/semaphore1.c
new file mode 100644
index 0000000..c5911f9
--- /dev/null
+++ b/tests/semaphore1.c
@@ -0,0 +1,159 @@
+/*
+ * File: semaphore1.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2002 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@ise.canberra.edu.au
+ *
+ * The current list of contributors is contained
+ * in the file CONTRIBUTORS included with the source
+ * code distribution. The list can also be seen at the
+ * following World Wide Web location:
+ * http://sources.redhat.com/pthreads-win32/contributors.html
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Test Synopsis: Verify trywait() returns -1 and sets EAGAIN.
+ * -
+ *
+ * Test Method (Validation or Falsification):
+ * - Validation
+ *
+ * Requirements Tested:
+ * -
+ *
+ * Features Tested:
+ * -
+ *
+ * Cases Tested:
+ * -
+ *
+ * Description:
+ * -
+ *
+ * Environment:
+ * -
+ *
+ * Input:
+ * - None.
+ *
+ * Output:
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
+ *
+ * Assumptions:
+ * -
+ *
+ * Pass Criteria:
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+
+void *
+thr(void * arg)
+{
+ sem_t s;
+ int result;
+
+ assert(sem_init(&s, PTHREAD_PROCESS_PRIVATE, 0) == 0);
+
+ assert((result = sem_trywait(&s)) == -1);
+
+ if ( result == -1 )
+ {
+ perror("thread: sem_trywait 1"); // No error
+ assert(errno == EAGAIN);
+ }
+ else
+ {
+ printf("thread: ok 1\n");
+ }
+
+ assert((result = sem_post(&s)) == 0);
+
+ 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 0;
+}
+
+
+int
+main()
+{
+ pthread_t t;
+ sem_t s;
+ int result;
+
+ assert(pthread_create(&t, NULL, thr, NULL) == 0);
+ assert(pthread_join(t, (void **)&result) == 0);
+ assert(result == 0);
+
+ assert(sem_init(&s, PTHREAD_PROCESS_PRIVATE, 0) == 0);
+
+ assert((result = sem_trywait(&s)) == -1);
+
+ if ( result == -1 )
+ {
+ perror("main: sem_trywait 1"); // No error
+ assert(errno == EAGAIN);
+ }
+ else
+ {
+ printf("main: ok 1\n");
+ }
+
+ assert((result = sem_post(&s)) == 0);
+
+ assert((result = sem_trywait(&s)) == 0);
+
+ if ( result == -1 )
+ {
+ perror("main: sem_trywait 2");
+ }
+ else
+ {
+ printf("main: ok 2\n");
+ }
+
+ assert(sem_post(&s) == 0);
+
+ return 0;
+}
+