From ee1de6a067c70fbd8cb73facd64c3b0b275f9f83 Mon Sep 17 00:00:00 2001 From: deischen Date: Wed, 24 Jan 2001 13:03:38 +0000 Subject: 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 --- lib/libpthread/thread/thr_spec.c | 51 ++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'lib/libpthread/thread/thr_spec.c') 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 #include #include -#ifdef _THREAD_SAFE #include #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 -- cgit v1.1