summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpj <rpj>2003-06-21 15:48:30 +0000
committerrpj <rpj>2003-06-21 15:48:30 +0000
commit4ab4cad3a48f0aa8a3abb2b23985f542f8d9e264 (patch)
tree158623ca5dc0cd5bcc3a6efb4ad71469bff95b93
parent4b79461c03e0dd4656c1ad4fdca4344fb2cd1b19 (diff)
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.
-rw-r--r--CONTRIBUTORS3
-rw-r--r--ChangeLog6
-rw-r--r--pthread_mutex_destroy.c55
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 <boozai@yahoo.com>
+
+ * 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 <Steven.Reddie@ca.com>
* 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;
}
}
}