Changeset View
Changeset View
Standalone View
Standalone View
lib/libthr/thread/thr_spec.c
Show First 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | for (key = 0; key < PTHREAD_KEYS_MAX && | ||||
if (destructor != NULL) { | if (destructor != NULL) { | ||||
THR_LOCK_RELEASE(curthread, &_keytable_lock); | THR_LOCK_RELEASE(curthread, &_keytable_lock); | ||||
destructor(__DECONST(void *, data)); | destructor(__DECONST(void *, data)); | ||||
THR_LOCK_ACQUIRE(curthread, &_keytable_lock); | THR_LOCK_ACQUIRE(curthread, &_keytable_lock); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
THR_LOCK_RELEASE(curthread, &_keytable_lock); | THR_LOCK_RELEASE(curthread, &_keytable_lock); | ||||
munmap(curthread->specific, PTHREAD_KEYS_MAX * sizeof(struct | __thr_free(curthread->specific); | ||||
pthread_specific_elem)); | |||||
curthread->specific = NULL; | curthread->specific = NULL; | ||||
if (curthread->specific_data_count > 0) { | if (curthread->specific_data_count > 0) { | ||||
stderr_debug("Thread %p has exited with leftover " | stderr_debug("Thread %p has exited with leftover " | ||||
"thread-specific data after %d destructor iterations\n", | "thread-specific data after %d destructor iterations\n", | ||||
curthread, PTHREAD_DESTRUCTOR_ITERATIONS); | curthread, PTHREAD_DESTRUCTOR_ITERATIONS); | ||||
} | } | ||||
} | } | ||||
int | int | ||||
_pthread_setspecific(pthread_key_t userkey, const void *value) | _pthread_setspecific(pthread_key_t userkey, const void *value) | ||||
{ | { | ||||
struct pthread *pthread; | struct pthread *pthread; | ||||
void *tmp; | void *tmp; | ||||
pthread_key_t key; | pthread_key_t key; | ||||
key = userkey - 1; | key = userkey - 1; | ||||
if ((unsigned int)key >= PTHREAD_KEYS_MAX || | if ((unsigned int)key >= PTHREAD_KEYS_MAX || | ||||
!_thread_keytable[key].allocated) | !_thread_keytable[key].allocated) | ||||
return (EINVAL); | return (EINVAL); | ||||
pthread = _get_curthread(); | pthread = _get_curthread(); | ||||
if (pthread->specific == NULL) { | if (pthread->specific == NULL) { | ||||
tmp = mmap(NULL, PTHREAD_KEYS_MAX * | tmp = __thr_calloc(PTHREAD_KEYS_MAX, | ||||
sizeof(struct pthread_specific_elem), | sizeof(struct pthread_specific_elem)); | ||||
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); | if (tmp == NULL) | ||||
if (tmp == MAP_FAILED) | |||||
return (ENOMEM); | return (ENOMEM); | ||||
pthread->specific = tmp; | pthread->specific = tmp; | ||||
} | } | ||||
if (pthread->specific[key].data == NULL) { | if (pthread->specific[key].data == NULL) { | ||||
if (value != NULL) | if (value != NULL) | ||||
pthread->specific_data_count++; | pthread->specific_data_count++; | ||||
} else if (value == NULL) | } else if (value == NULL) | ||||
pthread->specific_data_count--; | pthread->specific_data_count--; | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |