diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2017-09-26 21:16:41 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2017-09-26 21:24:06 +0200 |
commit | 6bb20b2e064e1e4473683fa6e598e80f4ea8aa00 (patch) | |
tree | e2ce059d7cb9c31a1569656018d7498959916932 | |
parent | 596061769ee34741a42eb375b1a2e06fffb4c5a3 (diff) |
Remove libihash use
It poses compilation bootstrapping inconvenience, non-standard symbol
exposition, and this is overkill, considering the usual use of TSD, and the
availability of TLS.
* sysdeps/hurd/pt-key.h: Do not include <hurd/ihash.h>.
(PTHREAD_KEY_MEMBERS): Turn thread_specifics to a void**, add unsigned
thread_specifics_size.
* sysdeps/hurd/pt-init-specific.c (__pthread_init_specific): Initialize
thread_specifics_size to 0.
* sysdeps/hurd/pt-setspecific.c: Do not include <hurd/ihash.h>.
(__pthread_setspecific): Expand and access thread_specifics array instead of
hash table.
* sysdeps/hurd/pt-getspecific.c: Do not include <hurd/ihash.h>.
(__pthread_getspecific): Access thread_specifics array instead of hash
table.
* sysdeps/hurd/pt-key-delete.c (pthread_key_delete): Clean thread_specifics
array instead of hash table.
* sysdeps/hurd/pt-destroy-specific.c: Do not include <hurd/ihash.h>.
(__pthread_destroy_specific): Clean and free thread_specifics array
instead of hash table.
* Makeconfig (LDLIBS-tst-interpose-static-thread): Remove -lihash.
(LDLIBS-tst-linkall-static): Remove -lihash.
* Makefile (HURDLIBS): Remove ihash.
(LDLIBS-pthread.so): Remove -lihash.
* libpthread.a: Remove -lihash.
* libpthread_pic.a: Remove -lihash_pic.
-rw-r--r-- | Makeconfig | 7 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | libpthread.a | 2 | ||||
-rw-r--r-- | libpthread_pic.a | 2 | ||||
-rw-r--r-- | sysdeps/hurd/pt-destroy-specific.c | 12 | ||||
-rw-r--r-- | sysdeps/hurd/pt-getspecific.c | 5 | ||||
-rw-r--r-- | sysdeps/hurd/pt-init-specific.c | 1 | ||||
-rw-r--r-- | sysdeps/hurd/pt-key-delete.c | 4 | ||||
-rw-r--r-- | sysdeps/hurd/pt-key.h | 4 | ||||
-rw-r--r-- | sysdeps/hurd/pt-setspecific.c | 21 |
10 files changed, 26 insertions, 38 deletions
@@ -8,13 +8,6 @@ shared-thread-library = $(common-objpfx)libpthread/libpthread_nonshared.a \ static-thread-library = $(common-objpfx)libpthread/libpthread.a bounded-thread-library = $(static-thread-library) -ifeq ($(subdir),malloc) -LDLIBS-tst-interpose-static-thread += -lihash -endif -ifeq ($(subdir),elf) -LDLIBS-tst-linkall-static += -lihash -endif - rpath-dirs += libpthread +includes += -I$(..)libpthread/include @@ -220,12 +220,6 @@ SYSDEP_PATH = $(srcdir)/sysdeps/$(MICROKERNEL)/hurd/i386 \ VPATH += $(SYSDEP_PATH) ifeq ($(IN_GLIBC),no) -HURDLIBS = ihash -else -LDLIBS-pthread.so = -lihash -endif - -ifeq ($(IN_GLIBC),no) installhdrs := installhdrsubdir := . diff --git a/libpthread.a b/libpthread.a index 7d3f8d3..e5bd2cc 100644 --- a/libpthread.a +++ b/libpthread.a @@ -19,4 +19,4 @@ EXTERN(_cthreads_ftrylockfile) EXTERN(pthread_getattr_np) EXTERN(pthread_attr_getstack) -GROUP(-lpthread2 -lihash -lrt) +GROUP(-lpthread2 -lrt) diff --git a/libpthread_pic.a b/libpthread_pic.a index cf0bd90..33346b4 100644 --- a/libpthread_pic.a +++ b/libpthread_pic.a @@ -19,4 +19,4 @@ EXTERN(_cthreads_ftrylockfile) EXTERN(pthread_getattr_np) EXTERN(pthread_attr_getstack) -GROUP(-lpthread2_pic -lihash_pic) +GROUP(-lpthread2_pic) 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 7b6a2c2..46830d7 100644 --- a/sysdeps/hurd/pt-key.h +++ b/sysdeps/hurd/pt-key.h @@ -18,11 +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) 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); |