diff options
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | mutex.c | 21 |
2 files changed, 32 insertions, 8 deletions
@@ -25,6 +25,25 @@ 2001-01-10 Ross Johnson <rpj@setup1.ise.canberra.edu.au> + * 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> + * rwlock.c (ptw32_rwlock_cancelwrwait): Renamed. (ptw32_rwlock_cancelrdwait): Renamed. @@ -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; |