summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpj <rpj>2004-06-22 06:12:54 +0000
committerrpj <rpj>2004-06-22 06:12:54 +0000
commitcf236808ad018ce10123321fab0917550e181aa2 (patch)
treeea0b63b989688fb6205675424a7d1626166a3c35
parentd5c1ab47d8cb1e11feae5719e44972015e284516 (diff)
Add PTHREAD_{RECURSIVE,ERRORCHECK}_MUTEX_INITIALIZER{,_NP}snap-2004-06-22
-rw-r--r--ANNOUNCE4
-rw-r--r--ChangeLog21
-rw-r--r--Nmakefile.tests16
-rw-r--r--global.c3
-rw-r--r--implement.h4
-rw-r--r--pthread.h8
-rw-r--r--pthread_mutex_destroy.c4
-rw-r--r--pthread_mutex_lock.c2
-rw-r--r--pthread_mutex_timedlock.c2
-rw-r--r--pthread_mutex_trylock.c2
-rw-r--r--pthread_mutex_unlock.c2
-rw-r--r--ptw32_mutex_check_need_init.c24
-rw-r--r--tests/ChangeLog36
-rw-r--r--tests/GNUmakefile11
-rw-r--r--tests/Makefile9
-rw-r--r--tests/mutex2e.c66
-rw-r--r--tests/mutex2r.c66
-rw-r--r--tests/mutex3e.c75
-rw-r--r--tests/mutex3r.c75
-rw-r--r--tests/mutex6es.c94
-rw-r--r--tests/mutex6rs.c92
-rw-r--r--tests/mutex6s.c93
22 files changed, 679 insertions, 30 deletions
diff --git a/ANNOUNCE b/ANNOUNCE
index 144455e..9784535 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,4 +1,4 @@
- PTHREADS-WIN32 SNAPSHOT 2004-05-16
+ PTHREADS-WIN32 SNAPSHOT 2004-06-22
----------------------------------
Web Site: http://sources.redhat.com/pthreads-win32/
FTP Site: ftp://sources.redhat.com/pub/pthreads-win32
@@ -258,6 +258,8 @@ The following functions are implemented:
---------------------------
PTHREAD_ONCE_INIT
PTHREAD_MUTEX_INITIALIZER
+ PTHREAD_RECURSIVE_MUTEX_INITIALIZER (also: PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
+ PTHREAD_ERRORCHECK_MUTEX_INITIALIZER (also: PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP)
PTHREAD_COND_INITIALIZER
PTHREAD_RWLOCK_INITIALIZER
PTHREAD_SPINLOCK_INITIALIZER
diff --git a/ChangeLog b/ChangeLog
index bcc44be..2641d99 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,23 @@
-2004-05-20 Ross Johnson <ross@special.ise.canberra.edu.au>
+2004-06-21 Ross Johnson <rpj@callisto.canberra.edu.au>
+
+ * pthread.h (PTHREAD_RECURSIVE_MUTEX_INITIALIZER): Mutex
+ initialiser added for compatibility with Linux threads and
+ others; currently not included in SUSV3.
+ * pthread.h (PTHREAD_ERRORCHECK_MUTEX_INITIALIZER): Likewise.
+ * pthread.h (PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP): Likewise.
+ * pthread.h (PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP): Likewise.
+
+ * ptw32_mutex_check_need_init.c (ptw32_mutex_check_need_init):
+ Add new initialisers.
+
+ * pthread_mutex_lock.c (pthread_mutex_lock): Check for new
+ initialisers.
+ * pthread_mutex_trylock.c (pthread_mutex_trylock): Likewise.
+ * pthread_mutex_timedlock.c (pthread_mutex_timedlock): Likewise.
+ * pthread_mutex_unlock.c (pthread_mutex_unlock): Likewise.
+ * pthread_mutex_destroy.c (pthread_mutex_destroy): Likewise.
+
+2004-05-20 Ross Johnson <rpj@callisto.canberra.edu.au>
* README.NONPORTABLE: Document pthread_win32_test_features_np().
* FAQ: Update various answers.
diff --git a/Nmakefile.tests b/Nmakefile.tests
index 54fe0d1..8f2f527 100644
--- a/Nmakefile.tests
+++ b/Nmakefile.tests
@@ -24,7 +24,9 @@ mutex1:: mutex1.c
mutex1e:: mutex1e.c
mutex1n:: mutex1n.c
mutex1r:: mutex1r.c
-mutex2:: mutex1.2
+mutex2:: mutex2.c
+mutex2r:: mutex2r.c
+mutex2e:: mutex2e.c
exit1:: exit1.c
condvar1:: condvar1.c
condvar1_1:: condvar1_1.c
@@ -40,6 +42,8 @@ create2.:: create2.c
cancel1:: cancel1.c
cancel2:: cancel2.c
mutex3:: mutex3.c
+mutex3r:: mutex3r.c
+mutex3e:: mutex3e.c
mutex4:: mutex4.c
mutex5:: mutex5.c
mutex6:: mutex6.c
@@ -47,6 +51,9 @@ mutex6e:: mutex6e.c
mutex6n:: mutex6n.c
mutex6r:: mutex6r.c
mutex7:: mutex7.c
+mutex6s:: mutex6s.c
+mutex6rs:: mutex6rs.c
+mutex6es:: mutex6es.c
mutex7e:: mutex7e.c
mutex7n:: mutex7n.c
mutex7r:: mutex7r.c
@@ -136,6 +143,8 @@ semaphore2 :test: loadfree
mutex5 :test: loadfree
mutex1 :test: loadfree
mutex2 :test: loadfree
+mutex2r :test: loadfree
+mutex2e :test: loadfree
exit1 :test: loadfree
condvar1 :test: loadfree
kill1 :test: loadfree
@@ -151,11 +160,16 @@ reuse2 :test: reuse1
cancel1 :test: create1
cancel2 :test: cancel1
mutex3 :test: create1
+mutex3r :test: create1
+mutex3e :test: create1
mutex4 :test: mutex3
mutex6 :test: mutex4
mutex6n :test: mutex4
mutex6e :test: mutex4
mutex6r :test: mutex4
+mutex6s :test: mutex6
+mutex6rs :test: mutex6r
+mutex6es :test: mutex6e
mutex7 :test: mutex6
mutex7n :test: mutex6n
mutex7e :test: mutex6e
diff --git a/global.c b/global.c
index 0f7622b..fc9ab91 100644
--- a/global.c
+++ b/global.c
@@ -75,8 +75,7 @@ DWORD (*ptw32_register_cancelation) (PAPCFUNC, HANDLE, DWORD) = NULL;
CRITICAL_SECTION ptw32_thread_reuse_lock;
/*
- * Global lock for testing internal state of PTHREAD_MUTEX_INITIALIZER
- * created mutexes.
+ * Global lock for testing internal state of statically declared mutexes.
*/
CRITICAL_SECTION ptw32_mutex_test_init_lock;
diff --git a/implement.h b/implement.h
index ac5bed4..4ce91cd 100644
--- a/implement.h
+++ b/implement.h
@@ -45,8 +45,8 @@
/*
* In case windows.h doesn't define it (e.g. WinCE perhaps)
*/
-#ifndef PAPCFUNC
-# define PAPCFUNC (void CALLBACK (*)(DWORD))
+#ifdef WINCE
+typedef VOID (APIENTRY *PAPCFUNC)(DWORD dwParam);
#endif
/*
diff --git a/pthread.h b/pthread.h
index 0c42fc6..729458c 100644
--- a/pthread.h
+++ b/pthread.h
@@ -620,6 +620,14 @@ struct pthread_once_t_
* ====================
*/
#define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1)
+#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t) -2)
+#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t) -3)
+
+/*
+ * Compatibility with LinuxThreads
+ */
+#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER
+#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP PTHREAD_ERRORCHECK_MUTEX_INITIALIZER
#define PTHREAD_COND_INITIALIZER ((pthread_cond_t) -1)
diff --git a/pthread_mutex_destroy.c b/pthread_mutex_destroy.c
index d23af53..a777598 100644
--- a/pthread_mutex_destroy.c
+++ b/pthread_mutex_destroy.c
@@ -52,7 +52,7 @@ pthread_mutex_destroy (pthread_mutex_t * mutex)
/*
* Check to see if we have something to delete.
*/
- if (*mutex != PTHREAD_MUTEX_INITIALIZER)
+ if (*mutex < PTHREAD_ERRORCHECK_MUTEX_INITIALIZER)
{
mx = *mutex;
@@ -115,7 +115,7 @@ pthread_mutex_destroy (pthread_mutex_t * mutex)
/*
* Check again.
*/
- if (*mutex == PTHREAD_MUTEX_INITIALIZER)
+ if (*mutex >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER)
{
/*
* This is all we need to do to destroy a statically
diff --git a/pthread_mutex_lock.c b/pthread_mutex_lock.c
index a59666a..f92b39b 100644
--- a/pthread_mutex_lock.c
+++ b/pthread_mutex_lock.c
@@ -58,7 +58,7 @@ pthread_mutex_lock (pthread_mutex_t * mutex)
* again inside the guarded section of ptw32_mutex_check_need_init()
* to avoid race conditions.
*/
- if (*mutex == PTHREAD_MUTEX_INITIALIZER)
+ if (*mutex >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER)
{
if ((result = ptw32_mutex_check_need_init (mutex)) != 0)
{
diff --git a/pthread_mutex_timedlock.c b/pthread_mutex_timedlock.c
index 1abc391..a5d6b59 100644
--- a/pthread_mutex_timedlock.c
+++ b/pthread_mutex_timedlock.c
@@ -225,7 +225,7 @@ pthread_mutex_timedlock (pthread_mutex_t * mutex,
* again inside the guarded section of ptw32_mutex_check_need_init()
* to avoid race conditions.
*/
- if (*mutex == PTHREAD_MUTEX_INITIALIZER)
+ if (*mutex >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER)
{
if ((result = ptw32_mutex_check_need_init (mutex)) != 0)
{
diff --git a/pthread_mutex_trylock.c b/pthread_mutex_trylock.c
index 463e031..6f137f0 100644
--- a/pthread_mutex_trylock.c
+++ b/pthread_mutex_trylock.c
@@ -55,7 +55,7 @@ pthread_mutex_trylock (pthread_mutex_t * mutex)
* again inside the guarded section of ptw32_mutex_check_need_init()
* to avoid race conditions.
*/
- if (*mutex == PTHREAD_MUTEX_INITIALIZER)
+ if (*mutex >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER)
{
result = ptw32_mutex_check_need_init (mutex);
}
diff --git a/pthread_mutex_unlock.c b/pthread_mutex_unlock.c
index aff3637..05677c8 100644
--- a/pthread_mutex_unlock.c
+++ b/pthread_mutex_unlock.c
@@ -56,7 +56,7 @@ pthread_mutex_unlock (pthread_mutex_t * mutex)
* race condition. If another thread holds the
* lock then we shouldn't be in here.
*/
- if (mx != PTHREAD_MUTEX_INITIALIZER)
+ if (mx < PTHREAD_ERRORCHECK_MUTEX_INITIALIZER)
{
if (mx->ownerThread == (pthread_t) PTW32_MUTEX_OWNER_ANONYMOUS
|| pthread_equal (mx->ownerThread, pthread_self ()))
diff --git a/ptw32_mutex_check_need_init.c b/ptw32_mutex_check_need_init.c
index bcaaf8b..5bd01e1 100644
--- a/ptw32_mutex_check_need_init.c
+++ b/ptw32_mutex_check_need_init.c
@@ -37,11 +37,19 @@
#include "pthread.h"
#include "implement.h"
+static struct pthread_mutexattr_t_ ptw32_recursive_mutexattr_s =
+ {PTHREAD_PROCESS_PRIVATE, PTHREAD_MUTEX_RECURSIVE};
+static struct pthread_mutexattr_t_ ptw32_errorcheck_mutexattr_s =
+ {PTHREAD_PROCESS_PRIVATE, PTHREAD_MUTEX_ERRORCHECK};
+static pthread_mutexattr_t ptw32_recursive_mutexattr = &ptw32_recursive_mutexattr_s;
+static pthread_mutexattr_t ptw32_errorcheck_mutexattr = &ptw32_errorcheck_mutexattr_s;
+
INLINE int
ptw32_mutex_check_need_init (pthread_mutex_t * mutex)
{
- int result = 0;
+ register int result = 0;
+ register pthread_mutex_t mtx;
/*
* The following guarded test is specifically for statically
@@ -74,11 +82,21 @@ ptw32_mutex_check_need_init (pthread_mutex_t * mutex)
* re-initialise it only by calling pthread_mutex_init()
* explicitly.
*/
- if (*mutex == PTHREAD_MUTEX_INITIALIZER)
+ mtx = *mutex;
+
+ if (mtx == PTHREAD_MUTEX_INITIALIZER)
{
result = pthread_mutex_init (mutex, NULL);
}
- else if (*mutex == NULL)
+ else if (mtx == PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
+ {
+ result = pthread_mutex_init (mutex, &ptw32_recursive_mutexattr);
+ }
+ else if (mtx == PTHREAD_ERRORCHECK_MUTEX_INITIALIZER)
+ {
+ result = pthread_mutex_init (mutex, &ptw32_errorcheck_mutexattr);
+ }
+ else if (mtx == NULL)
{
/*
* The mutex has been destroyed while we were waiting to
diff --git a/tests/ChangeLog b/tests/ChangeLog
index f10e570..09a7b50 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,20 +1,30 @@
-2004-05-21 Ross Johnson <ross@special.ise.canberra.edu.au>
+2004-06-21 Ross Johnson <rpj@callisto.canberra.edu.au>
- * join3.c: New test.
+ * mutex2r.c: New test.
+ * mutex2e.c: New test.
+ * mutex3r.c: New test.
+ * mutex3e.c: New test.
+ * mutex6s.c: New test.
+ * mutex6rs.c: New test.
+ * mutex6es.c: New test.
+
+2004-05-21 Ross Johnson <rpj@callisto.canberra.edu.au>
+
+ * join3.c: New test.
2004-05-16 Ross Johnson <rpj@callisto.canberra.edu.au>
- * condvar2.c (WIN32_WINNT): Define to avoid redefinition warning
- from inclusion of implement.h.
- * convar2_1.c: Likewise.
- * condvar3_1.c: Likewise.
- * condvar3_2.c: Likewise.
- * context1.c: Likewise.
- * sizes.c: Likewise.
- * Makefile: Don't define _WIN32_WINNT on compiler command line.
- * GNUmakefile: Likewise.
- * priority1.c (main): Add column to output for actual win32
- priority.
+ * condvar2.c (WIN32_WINNT): Define to avoid redefinition warning
+ from inclusion of implement.h.
+ * convar2_1.c: Likewise.
+ * condvar3_1.c: Likewise.
+ * condvar3_2.c: Likewise.
+ * context1.c: Likewise.
+ * sizes.c: Likewise.
+ * Makefile: Don't define _WIN32_WINNT on compiler command line.
+ * GNUmakefile: Likewise.
+ * priority1.c (main): Add column to output for actual win32
+ priority.
2004-05-16 Ross Johnson <rpj@callisto.canberra.edu.au>
diff --git a/tests/GNUmakefile b/tests/GNUmakefile
index b9a5e5c..323f24b 100644
--- a/tests/GNUmakefile
+++ b/tests/GNUmakefile
@@ -76,7 +76,9 @@ TESTS = sizes loadfree \
kill1 valid1 valid2 \
exit2 exit3 exit4 exit5 \
join0 join1 join2 join3 \
- mutex2 mutex3 mutex4 mutex6 mutex6n mutex6e mutex6r \
+ mutex2 mutex2r mutex2e mutex3 mutex3r mutex3e \
+ mutex4 mutex6 mutex6n mutex6e mutex6r \
+ mutex6s mutex6es mutex6rs \
mutex7 mutex7n mutex7e mutex7r mutex8 mutex8n mutex8e mutex8r \
count1 once1 tsd1 self2 cancel1 cancel2 \
delay1 delay2 eyal1 \
@@ -203,13 +205,20 @@ mutex1n.pass: mutex1.pass
mutex1e.pass: mutex1.pass
mutex1r.pass: mutex1.pass
mutex2.pass: mutex1.pass
+mutex2r.pass: mutex2.pass
+mutex2e.pass: mutex2.pass
mutex3.pass: create1.pass
+mutex3r.pass: mutex3.pass
+mutex3e.pass: mutex3.pass
mutex4.pass: mutex3.pass
mutex5.pass:
mutex6.pass: mutex4.pass
mutex6n.pass: mutex4.pass
mutex6e.pass: mutex4.pass
mutex6r.pass: mutex4.pass
+mutex6s.pass: mutex6.pass
+mutex6rs.pass: mutex6r.pass
+mutex6es.pass: mutex6e.pass
mutex7.pass: mutex6.pass
mutex7n.pass: mutex6n.pass
mutex7e.pass: mutex6e.pass
diff --git a/tests/Makefile b/tests/Makefile
index 4a70b84..6aefab7 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -82,12 +82,14 @@ EHFLAGS =
PASSES= sizes.pass loadfree.pass \
semaphore1.pass semaphore2.pass self1.pass mutex5.pass \
mutex1.pass mutex1n.pass mutex1e.pass mutex1r.pass mutex2.pass mutex3.pass \
+ mutex2r.pass mutex2e.pass mutex3r.pass mutex3e.pass \
condvar1.pass condvar1_1.pass condvar1_2.pass condvar2.pass condvar2_1.pass \
exit1.pass create1.pass create2.pass reuse1.pass reuse2.pass equal1.pass \
kill1.pass valid1.pass valid2.pass \
exit2.pass exit3.pass exit4 exit5 \
join0.pass join1.pass join2.pass join3.pass \
mutex4.pass mutex6.pass mutex6n.pass mutex6e.pass mutex6r.pass \
+ mutex6s.pass mutex6es.pass mutex6rs.pass \
mutex7.pass mutex7n.pass mutex7e.pass mutex7r.pass \
mutex8.pass mutex8n.pass mutex8e.pass mutex8r.pass \
count1.pass once1.pass tsd1.pass \
@@ -287,13 +289,20 @@ mutex1n.pass: mutex1.pass
mutex1e.pass: mutex1.pass
mutex1r.pass: mutex1.pass
mutex2.pass: mutex1.pass
+mutex2r.pass: mutex2.pass
+mutex2e.pass: mutex2.pass
mutex3.pass: create1.pass
+mutex3r.pass: mutex3.pass
+mutex3e.pass: mutex3.pass
mutex4.pass: mutex3.pass
mutex5.pass:
mutex6.pass: mutex4.pass
mutex6n.pass: mutex4.pass
mutex6e.pass: mutex4.pass
mutex6r.pass: mutex4.pass
+mutex6s.pass: mutex6.pass
+mutex6rs.pass: mutex6r.pass
+mutex6es.pass: mutex6e.pass
mutex7.pass: mutex6.pass
mutex7n.pass: mutex6n.pass
mutex7e.pass: mutex6e.pass
diff --git a/tests/mutex2e.c b/tests/mutex2e.c
new file mode 100644
index 0000000..6448204
--- /dev/null
+++ b/tests/mutex2e.c
@@ -0,0 +1,66 @@
+/*
+ * mutex2e.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2003 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@callisto.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 mutex object, lock it,
+ * and then unlock it again.
+ *
+ * Depends on API functions:
+ * pthread_mutex_lock()
+ * pthread_mutex_unlock()
+ */
+
+#include "test.h"
+
+pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER;
+
+int
+main()
+{
+ assert(mutex == PTHREAD_ERRORCHECK_MUTEX_INITIALIZER);
+
+ assert(pthread_mutex_lock(&mutex) == 0);
+
+ assert(mutex != PTHREAD_ERRORCHECK_MUTEX_INITIALIZER);
+
+ assert(mutex != NULL);
+
+ assert(pthread_mutex_unlock(&mutex) == 0);
+
+ assert(pthread_mutex_destroy(&mutex) == 0);
+
+ assert(mutex == NULL);
+
+ return 0;
+}
diff --git a/tests/mutex2r.c b/tests/mutex2r.c
new file mode 100644
index 0000000..9317a6e
--- /dev/null
+++ b/tests/mutex2r.c
@@ -0,0 +1,66 @@
+/*
+ * mutex2r.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2003 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@callisto.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 mutex object, lock it,
+ * and then unlock it again.
+ *
+ * Depends on API functions:
+ * pthread_mutex_lock()
+ * pthread_mutex_unlock()
+ */
+
+#include "test.h"
+
+pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
+
+int
+main()
+{
+ assert(mutex == PTHREAD_RECURSIVE_MUTEX_INITIALIZER);
+
+ assert(pthread_mutex_lock(&mutex) == 0);
+
+ assert(mutex != PTHREAD_RECURSIVE_MUTEX_INITIALIZER);
+
+ assert(mutex != NULL);
+
+ assert(pthread_mutex_unlock(&mutex) == 0);
+
+ assert(pthread_mutex_destroy(&mutex) == 0);
+
+ assert(mutex == NULL);
+
+ return 0;
+}
diff --git a/tests/mutex3e.c b/tests/mutex3e.c
new file mode 100644
index 0000000..271fe6e
--- /dev/null
+++ b/tests/mutex3e.c
@@ -0,0 +1,75 @@
+/*
+ * mutex3e.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2003 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@callisto.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 mutex object, lock it, trylock it,
+ * and then unlock it again.
+ *
+ * Depends on API functions:
+ * pthread_mutex_lock()
+ * pthread_mutex_trylock()
+ * pthread_mutex_unlock()
+ */
+
+#include "test.h"
+
+pthread_mutex_t mutex1 = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER;
+
+static int washere = 0;
+
+void * func(void * arg)
+{
+ assert(pthread_mutex_trylock(&mutex1) == EBUSY);
+
+ washere = 1;
+
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t;
+
+ assert(pthread_mutex_lock(&mutex1) == 0);
+
+ assert(pthread_create(&t, NULL, func, NULL) == 0);
+ assert(pthread_join(t, NULL) == 0);
+
+ assert(pthread_mutex_unlock(&mutex1) == 0);
+
+ assert(washere == 1);
+
+ return 0;
+}
diff --git a/tests/mutex3r.c b/tests/mutex3r.c
new file mode 100644
index 0000000..8ff6a73
--- /dev/null
+++ b/tests/mutex3r.c
@@ -0,0 +1,75 @@
+/*
+ * mutex3r.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2003 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@callisto.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 mutex object, lock it, trylock it,
+ * and then unlock it again.
+ *
+ * Depends on API functions:
+ * pthread_mutex_lock()
+ * pthread_mutex_trylock()
+ * pthread_mutex_unlock()
+ */
+
+#include "test.h"
+
+pthread_mutex_t mutex1 = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
+
+static int washere = 0;
+
+void * func(void * arg)
+{
+ assert(pthread_mutex_trylock(&mutex1) == EBUSY);
+
+ washere = 1;
+
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t;
+
+ assert(pthread_mutex_lock(&mutex1) == 0);
+
+ assert(pthread_create(&t, NULL, func, NULL) == 0);
+ assert(pthread_join(t, NULL) == 0);
+
+ assert(pthread_mutex_unlock(&mutex1) == 0);
+
+ assert(washere == 1);
+
+ return 0;
+}
diff --git a/tests/mutex6es.c b/tests/mutex6es.c
new file mode 100644
index 0000000..d59a1c8
--- /dev/null
+++ b/tests/mutex6es.c
@@ -0,0 +1,94 @@
+/*
+ * mutex6es.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2003 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@callisto.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
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Tests PTHREAD_MUTEX_ERRORCHECK static mutex type.
+ * Thread locks mutex twice (recursive lock).
+ * This should fail with an EDEADLK error.
+ * The second unlock attempt should fail with an EPERM error.
+ *
+ * Depends on API functions:
+ * pthread_create()
+ * pthread_join()
+ * pthread_mutexattr_init()
+ * pthread_mutexattr_destroy()
+ * pthread_mutexattr_settype()
+ * pthread_mutexattr_gettype()
+ * pthread_mutex_init()
+ * pthread_mutex_destroy()
+ * pthread_mutex_lock()
+ * pthread_mutex_unlock()
+ */
+
+#include "test.h"
+
+static int lockCount = 0;
+
+static pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER;
+
+void * locker(void * arg)
+{
+ assert(pthread_mutex_lock(&mutex) == 0);
+ lockCount++;
+ assert(pthread_mutex_lock(&mutex) == EDEADLK);
+ lockCount++;
+ assert(pthread_mutex_unlock(&mutex) == 0);
+ assert(pthread_mutex_unlock(&mutex) == EPERM);
+
+ return (void *) 555;
+}
+
+int
+main()
+{
+ pthread_t t;
+ int result = 0;
+
+ assert(mutex == PTHREAD_ERRORCHECK_MUTEX_INITIALIZER);
+
+ assert(pthread_create(&t, NULL, locker, NULL) == 0);
+
+ assert(pthread_join(t, (void **) &result) == 0);
+ assert(result == 555);
+
+ assert(lockCount == 2);
+
+ assert(pthread_mutex_destroy(&mutex) == 0);
+
+ exit(0);
+
+ /* Never reached */
+ return 0;
+}
+
diff --git a/tests/mutex6rs.c b/tests/mutex6rs.c
new file mode 100644
index 0000000..23c5555
--- /dev/null
+++ b/tests/mutex6rs.c
@@ -0,0 +1,92 @@
+/*
+ * mutex6rs.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2003 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@callisto.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
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Tests PTHREAD_MUTEX_RECURSIVE static mutex type.
+ * Thread locks mutex twice (recursive lock).
+ * Both locks and unlocks should succeed.
+ *
+ * Depends on API functions:
+ * pthread_create()
+ * pthread_join()
+ * pthread_mutexattr_init()
+ * pthread_mutexattr_destroy()
+ * pthread_mutexattr_settype()
+ * pthread_mutexattr_gettype()
+ * pthread_mutex_init()
+ * pthread_mutex_destroy()
+ * pthread_mutex_lock()
+ * pthread_mutex_unlock()
+ */
+
+#include "test.h"
+
+static int lockCount = 0;
+
+static pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
+
+void * locker(void * arg)
+{
+ assert(pthread_mutex_lock(&mutex) == 0);
+ lockCount++;
+ assert(pthread_mutex_lock(&mutex) == 0);
+ lockCount++;
+ assert(pthread_mutex_unlock(&mutex) == 0);
+ assert(pthread_mutex_unlock(&mutex) == 0);
+
+ return (void *) 555;
+}
+
+int
+main()
+{
+ pthread_t t;
+ int result = 0;
+
+ assert(mutex == PTHREAD_RECURSIVE_MUTEX_INITIALIZER);
+
+ assert(pthread_create(&t, NULL, locker, NULL) == 0);
+
+ assert(pthread_join(t, (void **) &result) == 0);
+ assert(result == 555);
+
+ assert(lockCount == 2);
+
+ assert(pthread_mutex_destroy(&mutex) == 0);
+
+ exit(0);
+
+ /* Never reached */
+ return 0;
+}
diff --git a/tests/mutex6s.c b/tests/mutex6s.c
new file mode 100644
index 0000000..b6e74e9
--- /dev/null
+++ b/tests/mutex6s.c
@@ -0,0 +1,93 @@
+/*
+ * mutex6s.c
+ *
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Pthreads-win32 - POSIX Threads Library for Win32
+ * Copyright(C) 1998 John E. Bossom
+ * Copyright(C) 1999,2003 Pthreads-win32 contributors
+ *
+ * Contact Email: rpj@callisto.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 the default (type not set) static mutex type.
+ * Should be the same as PTHREAD_MUTEX_NORMAL.
+ * Thread locks mutex twice (recursive lock).
+ * Locking thread should deadlock on second attempt.
+ *
+ * Depends on API functions:
+ * pthread_mutex_lock()
+ * pthread_mutex_trylock()
+ * pthread_mutex_unlock()
+ */
+
+#include "test.h"
+
+static int lockCount = 0;
+
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+void * locker(void * arg)
+{
+ assert(pthread_mutex_lock(&mutex) == 0);
+ lockCount++;
+
+ /* Should wait here (deadlocked) */
+ assert(pthread_mutex_lock(&mutex) == 0);
+ lockCount++;
+ assert(pthread_mutex_unlock(&mutex) == 0);
+
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t;
+
+ assert(mutex == PTHREAD_MUTEX_INITIALIZER);
+
+ assert(pthread_create(&t, NULL, locker, NULL) == 0);
+
+ Sleep(1000);
+
+ assert(lockCount == 1);
+
+ /*
+ * Should succeed even though we don't own the lock
+ * because FAST mutexes don't check ownership.
+ */
+ assert(pthread_mutex_unlock(&mutex) == 0);
+
+ Sleep (1000);
+
+ assert(lockCount == 2);
+
+ exit(0);
+
+ /* Never reached */
+ return 0;
+}