summaryrefslogtreecommitdiff
path: root/ptw32_mutex_check_need_init.c
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 /ptw32_mutex_check_need_init.c
parentd5c1ab47d8cb1e11feae5719e44972015e284516 (diff)
Add PTHREAD_{RECURSIVE,ERRORCHECK}_MUTEX_INITIALIZER{,_NP}snap-2004-06-22
Diffstat (limited to 'ptw32_mutex_check_need_init.c')
-rw-r--r--ptw32_mutex_check_need_init.c24
1 files changed, 21 insertions, 3 deletions
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