diff options
author | rpj <rpj> | 2011-05-06 02:11:50 +0000 |
---|---|---|
committer | rpj <rpj> | 2011-05-06 02:11:50 +0000 |
commit | 2fe8aba6a8a4ce09f353f34881c77f93a9c01ca3 (patch) | |
tree | fd7f179b1abaa525ec55e34bef23b12f8fd89021 /pthread_key_delete.c | |
parent | 941d7cf87c60b55342b51e0b0fcd748589b76167 (diff) |
Robust mutexes merged from devel branchpost_merge_with_ROBUST_MUTEXES
Diffstat (limited to 'pthread_key_delete.c')
-rw-r--r-- | pthread_key_delete.c | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/pthread_key_delete.c b/pthread_key_delete.c index 0737e9e..09d70c6 100644 --- a/pthread_key_delete.c +++ b/pthread_key_delete.c @@ -66,15 +66,15 @@ pthread_key_delete (pthread_key_t key) * ------------------------------------------------------ */ { + ptw32_mcs_local_node_t keyLock; int result = 0; if (key != NULL) { - if (key->threads != NULL && - key->destructor != NULL && - pthread_mutex_lock (&(key->keyLock)) == 0) + if (key->threads != NULL && key->destructor != NULL) { ThreadKeyAssoc *assoc; + ptw32_mcs_lock_acquire (&(key->keyLock), &keyLock); /* * Run through all Thread<-->Key associations * for this key. @@ -85,6 +85,7 @@ pthread_key_delete (pthread_key_t key) */ while ((assoc = (ThreadKeyAssoc *) key->threads) != NULL) { + ptw32_mcs_local_node_t threadLock; ptw32_thread_t * thread = assoc->thread; if (assoc == NULL) @@ -93,34 +94,25 @@ pthread_key_delete (pthread_key_t key) break; } - if (pthread_mutex_lock (&(thread->threadLock)) == 0) - { - /* - * Since we are starting at the head of the key's threads - * chain, this will also point key->threads at the next assoc. - * While we hold key->keyLock, no other thread can insert - * a new assoc via pthread_setspecific. - */ - ptw32_tkAssocDestroy (assoc); - (void) pthread_mutex_unlock (&(thread->threadLock)); - } - else - { - /* Thread or lock is no longer valid? */ - ptw32_tkAssocDestroy (assoc); - } + ptw32_mcs_lock_acquire (&(thread->threadLock), &threadLock); + /* + * Since we are starting at the head of the key's threads + * chain, this will also point key->threads at the next assoc. + * While we hold key->keyLock, no other thread can insert + * a new assoc via pthread_setspecific. + */ + ptw32_tkAssocDestroy (assoc); + ptw32_mcs_lock_release (&threadLock); + ptw32_mcs_lock_release (&keyLock); } - pthread_mutex_unlock (&(key->keyLock)); } TlsFree (key->key); if (key->destructor != NULL) { /* A thread could be holding the keyLock */ - while (EBUSY == pthread_mutex_destroy (&(key->keyLock))) - { - Sleep(0); /* Ugly */ - } + ptw32_mcs_lock_acquire (&(key->keyLock), &keyLock); + ptw32_mcs_lock_release (&keyLock); } #if defined( _DEBUG ) |