summaryrefslogtreecommitdiff
path: root/sysdeps/hurd
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/hurd')
-rw-r--r--sysdeps/hurd/pt-destroy-specific.c12
-rw-r--r--sysdeps/hurd/pt-getspecific.c5
-rw-r--r--sysdeps/hurd/pt-init-specific.c1
-rw-r--r--sysdeps/hurd/pt-key-delete.c4
-rw-r--r--sysdeps/hurd/pt-key.h15
-rw-r--r--sysdeps/hurd/pt-setspecific.c21
6 files changed, 30 insertions, 28 deletions
diff --git a/sysdeps/hurd/pt-destroy-specific.c b/sysdeps/hurd/pt-destroy-specific.c
index f7896e5..642c61c 100644
--- a/sysdeps/hurd/pt-destroy-specific.c
+++ b/sysdeps/hurd/pt-destroy-specific.c
@@ -19,14 +19,12 @@
#include <pthread.h>
#include <stdlib.h>
-#include <hurd/ihash.h>
#include <pt-internal.h>
void
__pthread_destroy_specific (struct __pthread *thread)
{
- error_t err;
int i;
int seen_one;
@@ -43,18 +41,17 @@ __pthread_destroy_specific (struct __pthread *thread)
__pthread_mutex_lock (&__pthread_key_lock);
- for (i = 0; i < __pthread_key_count; i ++)
+ for (i = 0; i < __pthread_key_count && i < thread->thread_specifics_size; i ++)
{
void *value;
if (__pthread_key_destructors[i] == PTHREAD_KEY_INVALID)
continue;
- value = hurd_ihash_find (thread->thread_specifics, i);
+ value = thread->thread_specifics[i];
if (value)
{
- err = hurd_ihash_remove (thread->thread_specifics, i);
- assert (err == 1);
+ thread->thread_specifics[i] = 0;
if (__pthread_key_destructors[i])
{
@@ -74,6 +71,7 @@ __pthread_destroy_specific (struct __pthread *thread)
sched_yield ();
}
- hurd_ihash_free (thread->thread_specifics);
+ free (thread->thread_specifics);
thread->thread_specifics = 0;
+ thread->thread_specifics_size = 0;
}
diff --git a/sysdeps/hurd/pt-getspecific.c b/sysdeps/hurd/pt-getspecific.c
index 8a01470..1f49c03 100644
--- a/sysdeps/hurd/pt-getspecific.c
+++ b/sysdeps/hurd/pt-getspecific.c
@@ -18,7 +18,6 @@
Boston, MA 02111-1307, USA. */
#include <pthread.h>
-#include <hurd/ihash.h>
#include <pt-internal.h>
@@ -32,9 +31,9 @@ __pthread_getspecific (pthread_key_t key)
return NULL;
self = _pthread_self ();
- if (! self->thread_specifics)
+ if (key >= self->thread_specifics_size)
return 0;
- return hurd_ihash_find (self->thread_specifics, key);
+ return self->thread_specifics[key];
}
strong_alias (__pthread_getspecific, pthread_getspecific);
diff --git a/sysdeps/hurd/pt-init-specific.c b/sysdeps/hurd/pt-init-specific.c
index c1bacbc..78958cb 100644
--- a/sysdeps/hurd/pt-init-specific.c
+++ b/sysdeps/hurd/pt-init-specific.c
@@ -26,5 +26,6 @@ error_t
__pthread_init_specific (struct __pthread *thread)
{
thread->thread_specifics = 0;
+ thread->thread_specifics_size = 0;
return 0;
}
diff --git a/sysdeps/hurd/pt-key-delete.c b/sysdeps/hurd/pt-key-delete.c
index 8b2c8bb..499e9f3 100644
--- a/sysdeps/hurd/pt-key-delete.c
+++ b/sysdeps/hurd/pt-key-delete.c
@@ -52,8 +52,8 @@ pthread_key_delete (pthread_key_t key)
/* Just remove the key, no need to care whether it was
already there. */
- if (t->thread_specifics)
- hurd_ihash_remove (t->thread_specifics, key);
+ if (key < t->thread_specifics_size)
+ t->thread_specifics[key] = 0;
}
__pthread_rwlock_unlock (&__pthread_threads_lock);
}
diff --git a/sysdeps/hurd/pt-key.h b/sysdeps/hurd/pt-key.h
index 494e01d..46830d7 100644
--- a/sysdeps/hurd/pt-key.h
+++ b/sysdeps/hurd/pt-key.h
@@ -18,10 +18,11 @@
Boston, MA 02111-1307, USA. */
#include <pthread.h>
-#include <hurd/ihash.h>
+#include <libc-lockP.h>
#define PTHREAD_KEY_MEMBERS \
- hurd_ihash_t thread_specifics;
+ void **thread_specifics; /* This is only resized by the thread, and always growing */ \
+ unsigned thread_specifics_size; /* Number of entries in thread_specifics */
#define PTHREAD_KEY_INVALID (void *) (-1)
@@ -59,18 +60,18 @@ __pthread_key_lock_ready (void)
int err;
pthread_mutexattr_t attr;
- err = pthread_mutexattr_init (&attr);
+ err = __pthread_mutexattr_init (&attr);
assert_perror (err);
- err = pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
+ err = __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
assert_perror (err);
- err = pthread_mutex_init (&__pthread_key_lock, &attr);
+ err = _pthread_mutex_init (&__pthread_key_lock, &attr);
assert_perror (err);
- err = pthread_mutexattr_destroy (&attr);
+ err = __pthread_mutexattr_destroy (&attr);
assert_perror (err);
}
- pthread_once (&o, do_init);
+ __pthread_once (&o, do_init);
}
diff --git a/sysdeps/hurd/pt-setspecific.c b/sysdeps/hurd/pt-setspecific.c
index b3976cc..871560c 100644
--- a/sysdeps/hurd/pt-setspecific.c
+++ b/sysdeps/hurd/pt-setspecific.c
@@ -18,31 +18,34 @@
Boston, MA 02111-1307, USA. */
#include <pthread.h>
-#include <hurd/ihash.h>
#include <pt-internal.h>
int
__pthread_setspecific (pthread_key_t key, const void *value)
{
- error_t err;
struct __pthread *self = _pthread_self ();
if (key < 0 || key >= __pthread_key_count
|| __pthread_key_destructors[key] == PTHREAD_KEY_INVALID)
return EINVAL;
- if (! self->thread_specifics)
+ if (key >= self->thread_specifics_size)
{
- err = hurd_ihash_create (&self->thread_specifics, HURD_IHASH_NO_LOCP);
- if (err)
+ /* Amortize reallocation cost. */
+ int newsize = 2 * key + 1;
+ void **new = realloc (self->thread_specifics,
+ newsize * sizeof (new[0]));
+ if (! new )
return ENOMEM;
+
+ memset (&new[self->thread_specifics_size], 0,
+ (newsize - self->thread_specifics_size) * sizeof (new[0]));
+ self->thread_specifics = new;
+ self->thread_specifics_size = newsize;
}
- err = hurd_ihash_add (self->thread_specifics, key, (void *) value);
- if (err)
- return ENOMEM;
-
+ self->thread_specifics[key] = (void*) value;
return 0;
}
strong_alias (__pthread_setspecific, pthread_setspecific);