123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #include <stdio.h>
- #include <stdlib.h>
- #include "pthread.h"
- #include "implement.h"
- int
- pthread_key_delete (pthread_key_t key)
- {
- int result = 0;
- if (key != NULL)
- {
- if (key->threads != NULL &&
- key->destructor != NULL &&
- pthread_mutex_lock (&(key->keyLock)) == 0)
- {
- ThreadKeyAssoc *assoc;
-
- while ((assoc = (ThreadKeyAssoc *) key->threads) != NULL)
- {
- pte_thread_t * thread = assoc->thread;
- if (assoc == NULL)
- {
-
- break;
- }
- if (pthread_mutex_lock (&(thread->threadLock)) == 0)
- {
-
- pte_tkAssocDestroy (assoc);
- (void) pthread_mutex_unlock (&(thread->threadLock));
- }
- else
- {
-
- pte_tkAssocDestroy (assoc);
- }
- }
- pthread_mutex_unlock (&(key->keyLock));
- }
- pte_osTlsFree (key->key);
- if (key->destructor != NULL)
- {
-
- while (EBUSY == (result = pthread_mutex_destroy (&(key->keyLock))))
- {
- pte_osThreadSleep(1);
- }
- }
- free (key);
- }
- return (result);
- }
|