From 9a59a1b4611cbd4b1fcf7549a97dc2cbe340b794 Mon Sep 17 00:00:00 2001 From: rpj Date: Tue, 6 Feb 2001 07:56:03 +0000 Subject: * 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 --- mutex.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'mutex.c') 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; -- cgit v1.2.3