123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #include <errno.h>
- #include <stdlib.h>
- #include "pthreadP.h"
- int
- attribute_protected
- __pthread_setspecific (
- pthread_key_t key,
- const void *value)
- {
- struct pthread *self;
- unsigned int idx1st;
- unsigned int idx2nd;
- struct pthread_key_data *level2;
- unsigned int seq;
- self = THREAD_SELF;
-
- if (__builtin_expect (key < PTHREAD_KEY_2NDLEVEL_SIZE, 1))
- {
-
- if (KEY_UNUSED ((seq = __pthread_keys[key].seq)))
-
- return EINVAL;
- level2 = &self->specific_1stblock[key];
-
- if (value != NULL)
- THREAD_SETMEM (self, specific_used, true);
- }
- else
- {
- if (key >= PTHREAD_KEYS_MAX
- || KEY_UNUSED ((seq = __pthread_keys[key].seq)))
-
- return EINVAL;
- idx1st = key / PTHREAD_KEY_2NDLEVEL_SIZE;
- idx2nd = key % PTHREAD_KEY_2NDLEVEL_SIZE;
-
- level2 = THREAD_GETMEM_NC (self, specific, idx1st);
- if (level2 == NULL)
- {
- if (value == NULL)
-
- return 0;
- level2
- = (struct pthread_key_data *) calloc (PTHREAD_KEY_2NDLEVEL_SIZE,
- sizeof (*level2));
- if (level2 == NULL)
- return ENOMEM;
- THREAD_SETMEM_NC (self, specific, idx1st, level2);
- }
-
- level2 = &level2[idx2nd];
-
- THREAD_SETMEM (self, specific_used, true);
- }
-
- level2->seq = seq;
- level2->data = (void *) value;
- return 0;
- }
- strong_alias (__pthread_setspecific, pthread_setspecific)
- strong_alias (__pthread_setspecific, __pthread_setspecific_internal)
|