summaryrefslogtreecommitdiff
path: root/ptw32_mutex_check_need_init.c
diff options
context:
space:
mode:
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