From 78f83cfa240ec14874b22c7302ff8d306c130aaf Mon Sep 17 00:00:00 2001 From: rpj Date: Fri, 6 May 2005 07:31:28 +0000 Subject: '' --- ptw32_tkAssocDestroy.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'ptw32_tkAssocDestroy.c') diff --git a/ptw32_tkAssocDestroy.c b/ptw32_tkAssocDestroy.c index d80cd3f..f529e3c 100644 --- a/ptw32_tkAssocDestroy.c +++ b/ptw32_tkAssocDestroy.c @@ -56,10 +56,47 @@ ptw32_tkAssocDestroy (ThreadKeyAssoc * assoc) */ { - if ((assoc != NULL) && (assoc->key == NULL && assoc->thread.p == NULL)) + /* + * Both key->keyLock and thread->threadLock are locked on + * entry to this routine. + */ + if (assoc != NULL) { + ThreadKeyAssoc * prev, * next; - pthread_mutex_destroy (&(assoc->lock)); + prev = assoc->prevKey; + next = assoc->nextKey; + if (prev != NULL) + { + prev->nextKey = next; + } + if (next != NULL) + { + next->prevKey = prev; + } + + if (assoc->key->threads == assoc) + { + /* We're at the head of the threads chain */ + assoc->key->threads = next; + } + + prev = assoc->prevThread; + next = assoc->nextThread; + if (prev != NULL) + { + prev->nextThread = next; + } + if (next != NULL) + { + next->prevThread = prev; + } + + if (assoc->thread->keys == assoc) + { + /* We're at the head of the keys chain */ + assoc->thread->keys = next; + } free (assoc); } -- cgit v1.2.3