summaryrefslogtreecommitdiff
path: root/pthread_key_delete.c
diff options
context:
space:
mode:
authorrpj <rpj>2011-03-24 23:33:14 +0000
committerrpj <rpj>2011-03-24 23:33:14 +0000
commitdb171f2f9435b98f05f33fcbc0dcf0c5cc1cb917 (patch)
tree9d617a20a9e0ad1fcf415e353057c53e6d77d0f3 /pthread_key_delete.c
parente5229a33f8724a90cbb0b56c3ecc1d6691bf54d7 (diff)
First pass of robust mutexes
Diffstat (limited to 'pthread_key_delete.c')
-rw-r--r--pthread_key_delete.c40
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 )