summaryrefslogtreecommitdiff
path: root/pthread_key_delete.c
diff options
context:
space:
mode:
authorrpj <rpj>2005-05-06 07:27:10 +0000
committerrpj <rpj>2005-05-06 07:27:10 +0000
commit7523c7c4d75652f67cd31cb123e1268790394c8b (patch)
tree0920ebf089ccb971e0878542f85486171a541a8a /pthread_key_delete.c
parentcf42850c77554311e62d3780f6a36cbc38e5e002 (diff)
''
Diffstat (limited to 'pthread_key_delete.c')
-rw-r--r--pthread_key_delete.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/pthread_key_delete.c b/pthread_key_delete.c
index eacab03..99b00b9 100644
--- a/pthread_key_delete.c
+++ b/pthread_key_delete.c
@@ -44,7 +44,7 @@ pthread_key_delete (pthread_key_t key)
* ------------------------------------------------------
* DOCPUBLIC
* This function deletes a thread-specific data key. This
- * does not change the value of the thread spcific data key
+ * does not change the value of the thread specific data key
* for any thread and does not run the key's destructor
* in any thread so it should be used with caution.
*
@@ -55,7 +55,7 @@ pthread_key_delete (pthread_key_t key)
*
* DESCRIPTION
* This function deletes a thread-specific data key. This
- * does not change the value of the thread spcific data key
+ * does not change the value of the thread specific data key
* for any thread and does not run the key's destructor
* in any thread so it should be used with caution.
*
@@ -72,7 +72,7 @@ pthread_key_delete (pthread_key_t key)
{
if (key->threads != NULL &&
key->destructor != NULL &&
- pthread_mutex_lock (&(key->threadsLock)) == 0)
+ pthread_mutex_lock (&(key->keyLock)) == 0)
{
/*
* Run through all Thread<-->Key associations
@@ -93,28 +93,31 @@ pthread_key_delete (pthread_key_t key)
while (assoc != NULL)
{
- if (pthread_mutex_lock (&(assoc->lock)) == 0)
- {
- ThreadKeyAssoc *next;
+ ThreadKeyAssoc *next;
+ ptw32_thread_t * thread = assoc->thread;
- assoc->key = NULL;
+ if (thread != NULL
+ && pthread_mutex_lock (&(thread->threadLock)) == 0)
+ {
+ next = assoc->nextThread;
+ ptw32_tkAssocDestroy (assoc);
+ (void) pthread_mutex_unlock (&(thread->threadLock));
+ }
+ else
+ {
+ /* Thread or lock is no longer valid */
next = assoc->nextThread;
- assoc->nextThread = NULL;
-
- pthread_mutex_unlock (&(assoc->lock));
-
ptw32_tkAssocDestroy (assoc);
-
- assoc = next;
}
+ assoc = next;
}
- pthread_mutex_unlock (&(key->threadsLock));
+ pthread_mutex_unlock (&(key->keyLock));
}
TlsFree (key->key);
if (key->destructor != NULL)
{
- pthread_mutex_destroy (&(key->threadsLock));
+ pthread_mutex_destroy (&(key->keyLock));
}
#if defined( _DEBUG )