summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_spec.c
diff options
context:
space:
mode:
authorjb <jb@FreeBSD.org>1998-06-09 23:21:05 +0000
committerjb <jb@FreeBSD.org>1998-06-09 23:21:05 +0000
commit765df5f4d29065eac50b4bfab3407a7da8a90323 (patch)
treee14930dc53674181c346bbe0f43647669e330569 /lib/libpthread/thread/thr_spec.c
parent5ed1d7e9485fa8756d1be3fdf6cfa5125ac45657 (diff)
downloadFreeBSD-src-765df5f4d29065eac50b4bfab3407a7da8a90323.zip
FreeBSD-src-765df5f4d29065eac50b4bfab3407a7da8a90323.tar.gz
Implement compile time debug support instead of tracking file name and
line number every time a file descriptor is locked. This looks like a big change but it isn't. It should reduce the size of libc_r and make it run slightly faster.
Diffstat (limited to 'lib/libpthread/thread/thr_spec.c')
-rw-r--r--lib/libpthread/thread/thr_spec.c39
1 files changed, 17 insertions, 22 deletions
diff --git a/lib/libpthread/thread/thr_spec.c b/lib/libpthread/thread/thr_spec.c
index eaad36d..745a145 100644
--- a/lib/libpthread/thread/thr_spec.c
+++ b/lib/libpthread/thread/thr_spec.c
@@ -46,19 +46,19 @@ pthread_key_create(pthread_key_t * key, void (*destructor) (void *))
{
for ((*key) = 0; (*key) < PTHREAD_KEYS_MAX; (*key)++) {
/* Lock the key table entry: */
- _spinlock(&key_table[*key].access_lock);
+ _SPINLOCK(&key_table[*key].lock);
if (key_table[(*key)].allocated == 0) {
key_table[(*key)].allocated = 1;
key_table[(*key)].destructor = destructor;
/* Unlock the key table entry: */
- _atomic_unlock(&key_table[*key].access_lock);
+ _SPINUNLOCK(&key_table[*key].lock);
return (0);
}
/* Unlock the key table entry: */
- _atomic_unlock(&key_table[*key].access_lock);
+ _SPINUNLOCK(&key_table[*key].lock);
}
return (EAGAIN);
}
@@ -70,7 +70,7 @@ pthread_key_delete(pthread_key_t key)
if (key < PTHREAD_KEYS_MAX) {
/* Lock the key table entry: */
- _spinlock(&key_table[key].access_lock);
+ _SPINLOCK(&key_table[key].lock);
if (key_table[key].allocated)
key_table[key].allocated = 0;
@@ -78,7 +78,7 @@ pthread_key_delete(pthread_key_t key)
ret = EINVAL;
/* Unlock the key table entry: */
- _atomic_unlock(&key_table[key].access_lock);
+ _SPINUNLOCK(&key_table[key].lock);
} else
ret = EINVAL;
return (ret);
@@ -90,25 +90,33 @@ _thread_cleanupspecific(void)
void *data;
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) {
/* Lock the key table entry: */
- _spinlock(&key_table[key].access_lock);
+ _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 (key_table[key].destructor)
- key_table[key].destructor(data);
+ destructor = key_table[key].destructor;
}
}
/* Unlock the key table entry: */
- _atomic_unlock(&key_table[key].access_lock);
+ _SPINUNLOCK(&key_table[key].lock);
+
+ /*
+ * If there is a destructore, call it
+ * with the key table entry unlocked:
+ */
+ if (destructor)
+ destructor(data);
} else {
free(_thread_run->specific_data);
return;
@@ -140,9 +148,6 @@ pthread_setspecific(pthread_key_t key, const void *value)
if ((pthread->specific_data) ||
(pthread->specific_data = pthread_key_allocate_data())) {
if (key < PTHREAD_KEYS_MAX) {
- /* Lock the key table entry: */
- _spinlock(&key_table[key].access_lock);
-
if (key_table[key].allocated) {
if (pthread->specific_data[key] == NULL) {
if (value != NULL)
@@ -155,10 +160,6 @@ pthread_setspecific(pthread_key_t key, const void *value)
ret = 0;
} else
ret = EINVAL;
-
- /* Unlock the key table entry: */
- _atomic_unlock(&key_table[key].access_lock);
-
} else
ret = EINVAL;
} else
@@ -177,9 +178,6 @@ pthread_getspecific(pthread_key_t key)
/* Check if there is specific data: */
if (pthread->specific_data != NULL && key < PTHREAD_KEYS_MAX) {
- /* Lock the key table entry: */
- _spinlock(&key_table[key].access_lock);
-
/* Check if this key has been used before: */
if (key_table[key].allocated) {
/* Return the value: */
@@ -191,9 +189,6 @@ pthread_getspecific(pthread_key_t key)
*/
data = NULL;
}
-
- /* Unlock the key table entry: */
- _atomic_unlock(&key_table[key].access_lock);
} else
/* No specific data has been created, so just return NULL: */
data = NULL;
OpenPOWER on IntegriCloud