Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libthr/thread/thr_spec.c
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
#include "un-namespace.h" | #include "un-namespace.h" | ||||
#include "libc_private.h" | #include "libc_private.h" | ||||
#include "thr_private.h" | #include "thr_private.h" | ||||
/* Used in symbol lookup of libthread_db */ | /* Used in symbol lookup of libthread_db */ | ||||
struct pthread_key _thread_keytable[PTHREAD_KEYS_MAX]; | struct pthread_key _thread_keytable[PTHREAD_KEYS_MAX]; | ||||
__weak_reference(_pthread_key_create, pthread_key_create); | __weak_reference(_thr_key_create, pthread_key_create); | ||||
__weak_reference(_pthread_key_delete, pthread_key_delete); | __weak_reference(_thr_key_create, _pthread_key_create); | ||||
__weak_reference(_pthread_getspecific, pthread_getspecific); | __weak_reference(_thr_key_delete, pthread_key_delete); | ||||
__weak_reference(_pthread_setspecific, pthread_setspecific); | __weak_reference(_thr_key_delete, _pthread_key_delete); | ||||
__weak_reference(_thr_getspecific, pthread_getspecific); | |||||
__weak_reference(_thr_getspecific, _pthread_getspecific); | |||||
__weak_reference(_thr_setspecific, pthread_setspecific); | |||||
__weak_reference(_thr_setspecific, _pthread_setspecific); | |||||
int | int | ||||
_pthread_key_create(pthread_key_t *key, void (*destructor)(void *)) | _thr_key_create(pthread_key_t *key, void (*destructor)(void *)) | ||||
{ | { | ||||
struct pthread *curthread; | struct pthread *curthread; | ||||
int i; | int i; | ||||
_thr_check_init(); | _thr_check_init(); | ||||
curthread = _get_curthread(); | curthread = _get_curthread(); | ||||
Show All 11 Lines | for (i = 0; i < PTHREAD_KEYS_MAX; i++) { | ||||
} | } | ||||
} | } | ||||
THR_LOCK_RELEASE(curthread, &_keytable_lock); | THR_LOCK_RELEASE(curthread, &_keytable_lock); | ||||
return (EAGAIN); | return (EAGAIN); | ||||
} | } | ||||
int | int | ||||
_pthread_key_delete(pthread_key_t userkey) | _thr_key_delete(pthread_key_t userkey) | ||||
{ | { | ||||
struct pthread *curthread; | struct pthread *curthread; | ||||
int key, ret; | int key, ret; | ||||
key = userkey - 1; | key = userkey - 1; | ||||
if ((unsigned int)key >= PTHREAD_KEYS_MAX) | if ((unsigned int)key >= PTHREAD_KEYS_MAX) | ||||
return (EINVAL); | return (EINVAL); | ||||
curthread = _get_curthread(); | curthread = _get_curthread(); | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | _thread_cleanupspecific(void) | ||||
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) | _thr_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) | ||||
Show All 13 Lines | _thr_setspecific(pthread_key_t userkey, const void *value) | ||||
} else if (value == NULL) | } else if (value == NULL) | ||||
pthread->specific_data_count--; | pthread->specific_data_count--; | ||||
pthread->specific[key].data = value; | pthread->specific[key].data = value; | ||||
pthread->specific[key].seqno = _thread_keytable[key].seqno; | pthread->specific[key].seqno = _thread_keytable[key].seqno; | ||||
return (0); | return (0); | ||||
} | } | ||||
void * | void * | ||||
_pthread_getspecific(pthread_key_t userkey) | _thr_getspecific(pthread_key_t userkey) | ||||
{ | { | ||||
struct pthread *pthread; | struct pthread *pthread; | ||||
const void *data; | const void *data; | ||||
pthread_key_t key; | pthread_key_t key; | ||||
/* Check if there is specific data. */ | /* Check if there is specific data. */ | ||||
key = userkey - 1; | key = userkey - 1; | ||||
if ((unsigned int)key >= PTHREAD_KEYS_MAX) | if ((unsigned int)key >= PTHREAD_KEYS_MAX) | ||||
Show All 38 Lines |