From db171f2f9435b98f05f33fcbc0dcf0c5cc1cb917 Mon Sep 17 00:00:00 2001 From: rpj Date: Thu, 24 Mar 2011 23:33:14 +0000 Subject: First pass of robust mutexes --- pthread_detach.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'pthread_detach.c') diff --git a/pthread_detach.c b/pthread_detach.c index 19bc24d..84bfe1a 100644 --- a/pthread_detach.c +++ b/pthread_detach.c @@ -92,6 +92,7 @@ pthread_detach (pthread_t thread) } else { + ptw32_mcs_local_node_t stateLock; /* * Joinable ptw32_thread_t structs are not scavenged until * a join or detach is done. The thread may have exited already, @@ -99,26 +100,19 @@ pthread_detach (pthread_t thread) */ result = 0; - if (pthread_mutex_lock (&tp->cancelLock) == 0) - { - if (tp->state != PThreadStateLast) - { - tp->detachState = PTHREAD_CREATE_DETACHED; - } - else if (tp->detachState != PTHREAD_CREATE_DETACHED) - { - /* - * Thread is joinable and has exited or is exiting. - */ - destroyIt = PTW32_TRUE; - } - (void) pthread_mutex_unlock (&tp->cancelLock); - } - else - { - /* cancelLock shouldn't fail, but if it does ... */ - result = ESRCH; - } + ptw32_mcs_lock_acquire (&tp->stateLock, &stateLock); + if (tp->state != PThreadStateLast) + { + tp->detachState = PTHREAD_CREATE_DETACHED; + } + else if (tp->detachState != PTHREAD_CREATE_DETACHED) + { + /* + * Thread is joinable and has exited or is exiting. + */ + destroyIt = PTW32_TRUE; + } + ptw32_mcs_lock_release (&stateLock); } ptw32_mcs_lock_release(&node); -- cgit v1.2.3