From 52c1047709bbc61fa793bcc6a28daabea88d2a20 Mon Sep 17 00:00:00 2001 From: rpj Date: Wed, 11 Dec 2002 00:40:17 +0000 Subject: 2002-12-11 Thomas Pfaff * pthread_mutex_trylock.c: Should return EBUSY rather than EDEADLK. * pthread_mutex_destroy.c: Remove redundant ownership test (the trylock call does this for us); do not destroy a recursively locked mutex. --- ChangeLog | 7 +++++++ pthread_mutex_destroy.c | 13 +++---------- pthread_mutex_trylock.c | 25 +++++++++---------------- tests/ChangeLog | 4 ++++ tests/mutex7e.c | 4 ++-- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 15aa349..4f1fa49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-12-11 Thomas Pfaff + + * pthread_mutex_trylock.c: Should return EBUSY rather than EDEADLK. + * pthread_mutex_destroy.c: Remove redundant ownership test (the + trylock call does this for us); do not destroy a recursively locked + mutex. + 2002-09-20 Michael Johnson * pthread_cond_destroy.c (pthread_cond_destroy): diff --git a/pthread_mutex_destroy.c b/pthread_mutex_destroy.c index 22d78a1..e217bec 100644 --- a/pthread_mutex_destroy.c +++ b/pthread_mutex_destroy.c @@ -60,17 +60,10 @@ pthread_mutex_destroy(pthread_mutex_t *mutex) result = pthread_mutex_trylock(&mx); /* - * The mutex type may not be RECURSIVE therefore trylock may return EBUSY if - * we already own the mutex. Here we are assuming that it's OK to destroy - * a mutex that we own and have locked recursively. - * - * For FAST mutexes we record the owner as ANONYMOUS for speed. In this - * case we assume that the thread calling pthread_mutex_destroy() is the - * owner, if the mutex is owned at all. + * If trylock succeeded and the mutex is not recursively locked it + * can be destroyed. */ - if (result == 0 - || mx->ownerThread == (pthread_t) PTW32_MUTEX_OWNER_ANONYMOUS - || pthread_equal( mx->ownerThread, pthread_self() ) ) + if (result == 0 && 1 == mx->recursive_count) { /* * FIXME!!! diff --git a/pthread_mutex_trylock.c b/pthread_mutex_trylock.c index 66eb96e..97f33cd 100644 --- a/pthread_mutex_trylock.c +++ b/pthread_mutex_trylock.c @@ -76,22 +76,15 @@ pthread_mutex_trylock(pthread_mutex_t *mutex) } else { - if( mx->kind != PTHREAD_MUTEX_FAST_NP && - pthread_equal( mx->ownerThread, pthread_self() ) ) - { - if( mx->kind == PTHREAD_MUTEX_RECURSIVE_NP ) - { - mx->recursive_count++; - } - else - { - result = EDEADLK; - } - } - else - { - result = EBUSY; - } + if( mx->kind == PTHREAD_MUTEX_RECURSIVE_NP && + pthread_equal( mx->ownerThread, pthread_self() ) ) + { + mx->recursive_count++; + } + else + { + result = EBUSY; + } } } diff --git a/tests/ChangeLog b/tests/ChangeLog index e9266a5..b3916d2 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,7 @@ +2002-12-11 Ross Johnson + + * mutex7e.c: Assert EBUSY return instead of EDEADLK. + 2002-06-03 Ross Johnson * semaphore2.c: New test. diff --git a/tests/mutex7e.c b/tests/mutex7e.c index 5b8e68f..8d3a2d3 100644 --- a/tests/mutex7e.c +++ b/tests/mutex7e.c @@ -37,7 +37,7 @@ * * Tests PTHREAD_MUTEX_ERRORCHECK mutex type. * Thread locks and then trylocks mutex (attempted recursive lock). - * Trylock should fail with an EDEADLK error. + * Trylock should fail with an EBUSY error. * The second unlock attempt should fail with an EPERM error. * * Depends on API functions: @@ -64,7 +64,7 @@ void * locker(void * arg) { assert(pthread_mutex_lock(&mutex) == 0); lockCount++; - assert(pthread_mutex_trylock(&mutex) == EDEADLK); + assert(pthread_mutex_trylock(&mutex) == EBUSY); lockCount++; assert(pthread_mutex_unlock(&mutex) == 0); assert(pthread_mutex_unlock(&mutex) == EPERM); -- cgit v1.2.3