From 4ab4cad3a48f0aa8a3abb2b23985f542f8d9e264 Mon Sep 17 00:00:00 2001 From: rpj Date: Sat, 21 Jun 2003 15:48:30 +0000 Subject: pthread_mutex_destroy.c (pthread_mutex_destroy): When called with a recursive mutex that was locked by the current thread, the function was failing with a success return code. --- CONTRIBUTORS | 3 ++- ChangeLog | 6 ++++++ pthread_mutex_destroy.c | 55 +++++++++++++++++++++++++++++-------------------- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 7823ef4..9f6ba6a 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -102,4 +102,5 @@ Rob Fanner rfanner@stonethree.com Bug fix. Michael Johnson michaelj@maine.rr.com Bug fix. - +Nicolas Barry boozai@yahoo.com + Bug fix. diff --git a/ChangeLog b/ChangeLog index 95702a0..75dbf93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-06-22 Nicolas Barry + + * pthread_mutex_destroy.c (pthread_mutex_destroy): When called + with a recursive mutex that was locked by the current thread, the + function was failing with a success return code. + 2003-05-15 Steven Reddie * pthread_win32_attach_detach_np.c (pthread_win32_process_detach_np): diff --git a/pthread_mutex_destroy.c b/pthread_mutex_destroy.c index e217bec..fc4e684 100644 --- a/pthread_mutex_destroy.c +++ b/pthread_mutex_destroy.c @@ -63,35 +63,46 @@ pthread_mutex_destroy(pthread_mutex_t *mutex) * If trylock succeeded and the mutex is not recursively locked it * can be destroyed. */ - if (result == 0 && 1 == mx->recursive_count) + if (result == 0) { - /* - * FIXME!!! - * The mutex isn't held by another thread but we could still - * be too late invalidating the mutex below since another thread - * may already have entered mutex_lock and the check for a valid - * *mutex != NULL. - * - * Note that this would be an unusual situation because it is not - * common that mutexes are destroyed while they are still in - * use by other threads. - */ - *mutex = NULL; + if (1 == mx->recursive_count) + { + /* + * FIXME!!! + * The mutex isn't held by another thread but we could still + * be too late invalidating the mutex below since another thread + * may already have entered mutex_lock and the check for a valid + * *mutex != NULL. + * + * Note that this would be an unusual situation because it is not + * common that mutexes are destroyed while they are still in + * use by other threads. + */ + *mutex = NULL; - result = pthread_mutex_unlock(&mx); + result = pthread_mutex_unlock(&mx); - if (result == 0) - { - (void) sem_destroy( &mx->wait_sema ); - DeleteCriticalSection( &mx->wait_cs ); - free(mx); + if (result == 0) + { + (void) sem_destroy( &mx->wait_sema ); + DeleteCriticalSection( &mx->wait_cs ); + free(mx); + } + else + { + /* + * Restore the mutex before we return the error. + */ + *mutex = mx; + } } - else + else /* mx->recursive_count > 1 */ { /* - * Restore the mutex before we return the error. + * The mutex must be recursive and already locked by us (this thread). */ - *mutex = mx; + mx->recursive_count--; /* Undo effect of pthread_mutex_trylock() above */ + result = EBUSY; } } } -- cgit v1.2.3