summaryrefslogtreecommitdiff
path: root/mutex.c
diff options
context:
space:
mode:
authorrpj <rpj>2001-02-06 07:56:03 +0000
committerrpj <rpj>2001-02-06 07:56:03 +0000
commit9a59a1b4611cbd4b1fcf7549a97dc2cbe340b794 (patch)
treed07b9cf23658b2af706be05fa72ba54e1431311d /mutex.c
parentced3d3f3827b360617e71fe557e6d1880ad56cb4 (diff)
* mutex.c (pthread_mutexattr_settype): New; allow
the following types of mutex: PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_RECURSIVE (pthread_mutex_lock): Process the lock request according to the mutex type. * mutex.c: No longer use Win32 mutexes as the basis of POSIX mutexes when TryEnterCriticalSection isn't supported; implement our own versions of ptw32_{Initialize,Delete,TryEnter,Enter,Leave}CriticalSection functions to emulate TryEnterCriticalSection when it isn't supported by the system; don't allow recursive mutex locks (similar to PTHREAD_MUTEX_ERRORCHECK on other systems). - Thomas Pfaff <tpfaff@gmx.net>
Diffstat (limited to 'mutex.c')
-rw-r--r--mutex.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/mutex.c b/mutex.c
index fd09044..4ef39c1 100644
--- a/mutex.c
+++ b/mutex.c
@@ -730,6 +730,9 @@ pthread_mutexattr_settype (pthread_mutexattr_t * attr,
* thread has locked will return with an error. A
* thread attempting to unlock an unlocked mutex will
* return with an error.
+ *
+ * PTHREAD_MUTEX_DEFAULT
+ * Same as PTHREAD_MUTEX_ERRORCHECK.
*
* PTHREAD_MUTEX_RECURSIVE
* A thread attempting to relock this mutex without
@@ -827,17 +830,14 @@ pthread_mutex_lock(pthread_mutex_t *mutex)
mx = *mutex;
self = pthread_self();
- ptw32_EnterCriticalSection(&mx->cs);
-
switch (mx->type)
{
case PTHREAD_MUTEX_NORMAL:
if (pthread_equal(mx->ownerThread, self))
{
- ptw32_LeaveCriticalSection(&mx->cs);
/*
* Pretend to be deadlocked but release the
- * mutex if we are canceled.
+ * mutex if we are [asynchronously] canceled.
*/
pthread_cleanup_push(pthread_mutex_unlock, (void *) mutex);
while (TRUE)
@@ -846,19 +846,24 @@ pthread_mutex_lock(pthread_mutex_t *mutex)
}
pthread_cleanup_pop(1);
}
+ else
+ {
+ ptw32_EnterCriticalSection(&mx->cs);
+ }
break;
case PTHREAD_MUTEX_DEFAULT:
case PTHREAD_MUTEX_ERRORCHECK:
if (pthread_equal(mx->ownerThread, self))
{
- ptw32_LeaveCriticalSection(&mx->cs);
result = EDEADLK;
}
+ else
+ {
+ ptw32_EnterCriticalSection(&mx->cs);
+ }
break;
case PTHREAD_MUTEX_RECURSIVE:
- /*
- * Nothing more to do.
- */
+ ptw32_EnterCriticalSection(&mx->cs);
break;
default:
result = EINVAL;