summaryrefslogtreecommitdiff
path: root/pthread_detach.c
diff options
context:
space:
mode:
authorrpj <rpj>2011-05-06 02:11:50 +0000
committerrpj <rpj>2011-05-06 02:11:50 +0000
commit2fe8aba6a8a4ce09f353f34881c77f93a9c01ca3 (patch)
treefd7f179b1abaa525ec55e34bef23b12f8fd89021 /pthread_detach.c
parent941d7cf87c60b55342b51e0b0fcd748589b76167 (diff)
Robust mutexes merged from devel branchpost_merge_with_ROBUST_MUTEXES
Diffstat (limited to 'pthread_detach.c')
-rw-r--r--pthread_detach.c34
1 files changed, 14 insertions, 20 deletions
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);