summaryrefslogtreecommitdiff
path: root/pthread_key_delete.c
diff options
context:
space:
mode:
authorrpj <rpj>2005-05-06 07:31:28 +0000
committerrpj <rpj>2005-05-06 07:31:28 +0000
commit78f83cfa240ec14874b22c7302ff8d306c130aaf (patch)
treebf29a117aecb99e9ecb2d30bad398d8b20392b49 /pthread_key_delete.c
parente3845d9b6b0a18ffdfdf0cefd811a17fce62f1ac (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 )