summaryrefslogtreecommitdiff
path: root/pthread_win32_attach_detach_np.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_win32_attach_detach_np.c
parent941d7cf87c60b55342b51e0b0fcd748589b76167 (diff)
Robust mutexes merged from devel branchpost_merge_with_ROBUST_MUTEXES
Diffstat (limited to 'pthread_win32_attach_detach_np.c')
-rw-r--r--pthread_win32_attach_detach_np.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/pthread_win32_attach_detach_np.c b/pthread_win32_attach_detach_np.c
index 8116dd7..65e0913 100644
--- a/pthread_win32_attach_detach_np.c
+++ b/pthread_win32_attach_detach_np.c
@@ -190,15 +190,35 @@ pthread_win32_thread_detach_np ()
if (sp != NULL) // otherwise Win32 thread with no implicit POSIX handle.
{
+ ptw32_mcs_local_node_t stateLock;
ptw32_callUserDestroyRoutines (sp->ptHandle);
- (void) pthread_mutex_lock (&sp->cancelLock);
+ ptw32_mcs_lock_acquire (&sp->stateLock, &stateLock);
sp->state = PThreadStateLast;
/*
* If the thread is joinable at this point then it MUST be joined
* or detached explicitly by the application.
*/
- (void) pthread_mutex_unlock (&sp->cancelLock);
+ ptw32_mcs_lock_release (&stateLock);
+
+ /*
+ * Robust Mutexes
+ */
+ while (sp->robustMxList != NULL)
+ {
+ pthread_mutex_t mx = sp->robustMxList->mx;
+ ptw32_robust_mutex_remove(&mx, sp);
+ (void) PTW32_INTERLOCKED_EXCHANGE(
+ (LPLONG)&mx->robustNode->stateInconsistent,
+ -1L);
+ /*
+ * If there are no waiters then the next thread to block will
+ * sleep, wakeup immediately and then go back to sleep.
+ * See pthread_mutex_lock.c.
+ */
+ SetEvent(mx->event);
+ }
+
if (sp->detachState == PTHREAD_CREATE_DETACHED)
{