123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- #include "pthread.h"
- #include "implement.h"
- int
- pthread_setspecific (pthread_key_t key, const void *value)
- {
- pthread_t self;
- int result = 0;
- if (key != pte_selfThreadKey)
- {
-
- self = pthread_self ();
- if (self.p == NULL)
- {
- return ENOENT;
- }
- }
- else
- {
-
- pte_thread_t * sp = (pte_thread_t *) pthread_getspecific (pte_selfThreadKey);
- if (sp == NULL)
- {
- if (value == NULL)
- {
- return ENOENT;
- }
- self = *((pthread_t *) value);
- }
- else
- {
- self = sp->ptHandle;
- }
- }
- result = 0;
- if (key != NULL)
- {
- if (self.p != NULL && key->destructor != NULL && value != NULL)
- {
-
- ThreadKeyAssoc *assoc;
- if (pthread_mutex_lock(&(key->keyLock)) == 0)
- {
- pte_thread_t * sp = (pte_thread_t *) self.p;
- (void) pthread_mutex_lock(&(sp->threadLock));
- assoc = (ThreadKeyAssoc *) sp->keys;
-
- while (assoc != NULL)
- {
- if (assoc->key == key)
- {
-
- break;
- }
- assoc = assoc->nextKey;
- }
-
- if (assoc == NULL)
- {
- result = pte_tkAssocCreate (sp, key);
- }
- (void) pthread_mutex_unlock(&(sp->threadLock));
- }
- (void) pthread_mutex_unlock(&(key->keyLock));
- }
- if (result == 0)
- {
- if (pte_osTlsSetValue (key->key, (void *) value) != PTE_OS_OK)
- {
- result = EAGAIN;
- }
- }
- }
- return (result);
- }
|