diff options
author | deischen <deischen@FreeBSD.org> | 2001-01-24 13:03:38 +0000 |
---|---|---|
committer | deischen <deischen@FreeBSD.org> | 2001-01-24 13:03:38 +0000 |
commit | ee1de6a067c70fbd8cb73facd64c3b0b275f9f83 (patch) | |
tree | 71d2853de2f283028592fa4119320bab82c18d68 /lib/libpthread/thread/thr_spec.c | |
parent | 274959d59337555267567d4bde9a5a841c47d84f (diff) | |
download | FreeBSD-src-ee1de6a067c70fbd8cb73facd64c3b0b275f9f83.zip FreeBSD-src-ee1de6a067c70fbd8cb73facd64c3b0b275f9f83.tar.gz |
Add weak definitions for wrapped system calls. In general:
_foo - wrapped system call
foo - weak definition to _foo
and for cancellation points:
_foo - wrapped system call
__foo - enter cancellation point, call _foo(), leave
cancellation point
foo - weak definition to __foo
Change use of global _thread_run to call a function to get the
currently running thread.
Make all pthread_foo functions weak definitions to _pthread_foo,
where _pthread_foo is the implementation. This allows an application
to provide its own pthread functions.
Provide slightly different versions of pthread_mutex_lock and
pthread_mutex_init so that we can tell the difference between
a libc mutex and an application mutex. Threads holding mutexes
internal to libc should never be allowed to exit, call signal
handlers, or cancel.
Approved by: -arch
Diffstat (limited to 'lib/libpthread/thread/thr_spec.c')
-rw-r--r-- | lib/libpthread/thread/thr_spec.c | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/lib/libpthread/thread/thr_spec.c b/lib/libpthread/thread/thr_spec.c index 1485cbb..783617f 100644 --- a/lib/libpthread/thread/thr_spec.c +++ b/lib/libpthread/thread/thr_spec.c @@ -35,15 +35,20 @@ #include <stdlib.h> #include <string.h> #include <errno.h> -#ifdef _THREAD_SAFE #include <pthread.h> #include "pthread_private.h" /* Static variables: */ static struct pthread_key key_table[PTHREAD_KEYS_MAX]; +#pragma weak pthread_key_create=_pthread_key_create +#pragma weak pthread_key_delete=_pthread_key_delete +#pragma weak pthread_getspecific=_pthread_getspecific +#pragma weak pthread_setspecific=_pthread_setspecific + + int -pthread_key_create(pthread_key_t * key, void (*destructor) (void *)) +_pthread_key_create(pthread_key_t * key, void (*destructor) (void *)) { for ((*key) = 0; (*key) < PTHREAD_KEYS_MAX; (*key)++) { /* Lock the key table entry: */ @@ -65,7 +70,7 @@ pthread_key_create(pthread_key_t * key, void (*destructor) (void *)) } int -pthread_key_delete(pthread_key_t key) +_pthread_key_delete(pthread_key_t key) { int ret = 0; @@ -88,23 +93,24 @@ pthread_key_delete(pthread_key_t key) void _thread_cleanupspecific(void) { - void *data = NULL; - int key; - int itr; + struct pthread *curthread = _get_curthread(); + void *data = NULL; + int key; + int itr; void (*destructor)( void *); for (itr = 0; itr < PTHREAD_DESTRUCTOR_ITERATIONS; itr++) { for (key = 0; key < PTHREAD_KEYS_MAX; key++) { - if (_thread_run->specific_data_count) { + if (curthread->specific_data_count) { /* Lock the key table entry: */ _SPINLOCK(&key_table[key].lock); destructor = NULL; if (key_table[key].allocated) { - if (_thread_run->specific_data[key]) { - data = (void *) _thread_run->specific_data[key]; - _thread_run->specific_data[key] = NULL; - _thread_run->specific_data_count--; + if (curthread->specific_data[key]) { + data = (void *) curthread->specific_data[key]; + curthread->specific_data[key] = NULL; + curthread->specific_data_count--; destructor = key_table[key].destructor; } } @@ -119,14 +125,14 @@ _thread_cleanupspecific(void) if (destructor) destructor(data); } else { - free(_thread_run->specific_data); - _thread_run->specific_data = NULL; + free(curthread->specific_data); + curthread->specific_data = NULL; return; } } } - free(_thread_run->specific_data); - _thread_run->specific_data = NULL; + free(curthread->specific_data); + curthread->specific_data = NULL; } static inline const void ** @@ -140,13 +146,13 @@ pthread_key_allocate_data(void) } int -pthread_setspecific(pthread_key_t key, const void *value) +_pthread_setspecific(pthread_key_t key, const void *value) { - pthread_t pthread; - int ret = 0; + struct pthread *pthread; + int ret = 0; /* Point to the running thread: */ - pthread = _thread_run; + pthread = _get_curthread(); if ((pthread->specific_data) || (pthread->specific_data = pthread_key_allocate_data())) { @@ -171,13 +177,13 @@ pthread_setspecific(pthread_key_t key, const void *value) } void * -pthread_getspecific(pthread_key_t key) +_pthread_getspecific(pthread_key_t key) { - pthread_t pthread; + struct pthread *pthread; void *data; /* Point to the running thread: */ - pthread = _thread_run; + pthread = _get_curthread(); /* Check if there is specific data: */ if (pthread->specific_data != NULL && key < PTHREAD_KEYS_MAX) { @@ -197,4 +203,3 @@ pthread_getspecific(pthread_key_t key) data = NULL; return (data); } -#endif |