aboutsummaryrefslogtreecommitdiff
path: root/htl
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2021-09-15 20:11:08 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2021-09-16 01:04:05 +0200
commit166bb3eac351b88191d440b0fe8d5d7b757eaed0 (patch)
tree2a0366c36387bcee5c4ae2704ccca394cd969f48 /htl
parent4b6574a6f63b6c766f27be4a0b4c9376a35a4bd5 (diff)
downloadglibc-166bb3eac351b88191d440b0fe8d5d7b757eaed0.tar
glibc-166bb3eac351b88191d440b0fe8d5d7b757eaed0.tar.gz
glibc-166bb3eac351b88191d440b0fe8d5d7b757eaed0.tar.bz2
glibc-166bb3eac351b88191d440b0fe8d5d7b757eaed0.zip
htl: Move thread table to ld.so
The next commit is going to introduce a new implementation of THREAD_GSCOPE_WAIT which needs to access the list of threads. Since it must be usable from the dynamic laoder, we have to move the symbols for the list of threads into the loader. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20210915171110.226187-2-bugaevc@gmail.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Diffstat (limited to 'htl')
-rw-r--r--htl/Versions2
-rw-r--r--htl/pt-alloc.c50
-rw-r--r--htl/pt-create.c8
-rw-r--r--htl/pt-internal.h23
4 files changed, 31 insertions, 52 deletions
diff --git a/htl/Versions b/htl/Versions
index 4aea321016..4e0ebac285 100644
--- a/htl/Versions
+++ b/htl/Versions
@@ -168,8 +168,6 @@ libpthread {
GLIBC_PRIVATE {
__pthread_initialize_minimal;
- __pthread_threads;
-
__cthread_detach;
__cthread_fork;
__pthread_detach;
diff --git a/htl/pt-alloc.c b/htl/pt-alloc.c
index acc67f2711..f6e783be10 100644
--- a/htl/pt-alloc.c
+++ b/htl/pt-alloc.c
@@ -28,19 +28,9 @@
of the threads functions "shall fail" if "No thread could be found
corresponding to that specified by the given thread ID." */
-/* Thread ID lookup table. */
-struct __pthread **__pthread_threads;
-
/* The size of the thread ID lookup table. */
int __pthread_max_threads;
-/* The total number of thread IDs currently in use, or on the list of
- available thread IDs. */
-int __pthread_num_threads;
-
-/* A lock for the table, and the other variables above. */
-pthread_rwlock_t __pthread_threads_lock;
-
/* List of thread structures corresponding to free thread IDs. */
struct __pthread *__pthread_free_threads;
pthread_mutex_t __pthread_free_threads_lock;
@@ -132,25 +122,25 @@ __pthread_alloc (struct __pthread **pthread)
}
retry:
- __pthread_rwlock_wrlock (&__pthread_threads_lock);
+ __libc_rwlock_wrlock (GL (dl_pthread_threads_lock));
- if (__pthread_num_threads < __pthread_max_threads)
+ if (GL (dl_pthread_num_threads) < __pthread_max_threads)
{
/* We have a free slot. Use the slot number plus one as the
thread ID for the new thread. */
- new->thread = 1 + __pthread_num_threads++;
- __pthread_threads[new->thread - 1] = NULL;
+ new->thread = 1 + GL (dl_pthread_num_threads)++;
+ GL (dl_pthread_threads)[new->thread - 1] = NULL;
- __pthread_rwlock_unlock (&__pthread_threads_lock);
+ __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
*pthread = new;
return 0;
}
#ifdef PTHREAD_THREADS_MAX
- else if (__pthread_num_threads >= PTHREAD_THREADS_MAX)
+ else if (GL (dl_pthread_num_threads) >= PTHREAD_THREADS_MAX)
{
/* We have reached the limit on the number of threads per process. */
- __pthread_rwlock_unlock (&__pthread_threads_lock);
+ __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
free (new);
return EAGAIN;
@@ -162,7 +152,7 @@ retry:
memory allocation, since that's a potentially blocking operation. */
max_threads = __pthread_max_threads;
- __pthread_rwlock_unlock (&__pthread_threads_lock);
+ __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
/* Allocate a new lookup table that's twice as large. */
new_max_threads
@@ -174,13 +164,13 @@ retry:
return ENOMEM;
}
- __pthread_rwlock_wrlock (&__pthread_threads_lock);
+ __libc_rwlock_wrlock (GL (dl_pthread_threads_lock));
/* Check if nobody else has already enlarged the table. */
if (max_threads != __pthread_max_threads)
{
/* Yep, they did. */
- __pthread_rwlock_unlock (&__pthread_threads_lock);
+ __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
/* Free the newly allocated table and try again to allocate a slot. */
free (threads);
@@ -188,22 +178,22 @@ retry:
}
/* Copy over the contents of the old table. */
- memcpy (threads, __pthread_threads,
+ memcpy (threads, GL (dl_pthread_threads),
__pthread_max_threads * sizeof (struct __pthread *));
/* Save the location of the old table. We want to deallocate its
storage after we released the lock. */
- old_threads = __pthread_threads;
+ old_threads = GL (dl_pthread_threads);
/* Replace the table with the new one. */
__pthread_max_threads = new_max_threads;
- __pthread_threads = threads;
+ GL (dl_pthread_threads) = threads;
/* And allocate ourselves one of the newly created slots. */
- new->thread = 1 + __pthread_num_threads++;
- __pthread_threads[new->thread - 1] = NULL;
+ new->thread = 1 + GL (dl_pthread_num_threads)++;
+ GL (dl_pthread_threads)[new->thread - 1] = NULL;
- __pthread_rwlock_unlock (&__pthread_threads_lock);
+ __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
free (old_threads);
@@ -217,10 +207,10 @@ __pthread_init_static_tls (struct link_map *map)
{
int i;
- __pthread_rwlock_wrlock (&__pthread_threads_lock);
- for (i = 0; i < __pthread_num_threads; ++i)
+ __libc_rwlock_wrlock (GL (dl_pthread_threads_lock));
+ for (i = 0; i < GL (dl_pthread_num_threads); ++i)
{
- struct __pthread *t = __pthread_threads[i];
+ struct __pthread *t = GL (dl_pthread_threads)[i];
if (t == NULL)
continue;
@@ -237,5 +227,5 @@ __pthread_init_static_tls (struct link_map *map)
memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size),
'\0', map->l_tls_blocksize - map->l_tls_initimage_size);
}
- __pthread_rwlock_unlock (&__pthread_threads_lock);
+ __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
}
diff --git a/htl/pt-create.c b/htl/pt-create.c
index f0a1f1ab09..a6c9ab3e93 100644
--- a/htl/pt-create.c
+++ b/htl/pt-create.c
@@ -207,7 +207,7 @@ __pthread_create_internal (struct __pthread **thread,
creating thread. The set of signals pending for the new thread
shall be empty." If the currnet thread is not a pthread then we
just inherit the process' sigmask. */
- if (__pthread_num_threads == 1)
+ if (GL (dl_pthread_num_threads) == 1)
err = __sigprocmask (0, 0, &pthread->init_sigset);
else
err = __pthread_sigstate (_pthread_self (), 0, 0, &pthread->init_sigset, 0);
@@ -231,9 +231,9 @@ __pthread_create_internal (struct __pthread **thread,
could use __thread_setid, however, we only lock for reading as no
other thread should be using this entry (we also assume that the
store is atomic). */
- __pthread_rwlock_rdlock (&__pthread_threads_lock);
- __pthread_threads[pthread->thread - 1] = pthread;
- __pthread_rwlock_unlock (&__pthread_threads_lock);
+ __libc_rwlock_rdlock (GL (dl_pthread_threads_lock));
+ GL (dl_pthread_threads)[pthread->thread - 1] = pthread;
+ __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
/* At this point it is possible to guess our pthread ID. We have to
make sure that all functions taking a pthread_t argument can
diff --git a/htl/pt-internal.h b/htl/pt-internal.h
index 34e6da338e..b17f12b733 100644
--- a/htl/pt-internal.h
+++ b/htl/pt-internal.h
@@ -166,33 +166,24 @@ __pthread_dequeue (struct __pthread *thread)
/* The total number of threads currently active. */
extern unsigned int __pthread_total;
-/* The total number of thread IDs currently in use, or on the list of
- available thread IDs. */
-extern int __pthread_num_threads;
-
/* Concurrency hint. */
extern int __pthread_concurrency;
-/* Array of __pthread structures and its lock. Indexed by the pthread
- id minus one. (Why not just use the pthread id? Because some
- brain-dead users of the pthread interface incorrectly assume that 0
- is an invalid pthread id.) */
-extern struct __pthread **__pthread_threads;
+/* The size of the thread ID lookup table. */
extern int __pthread_max_threads;
-extern pthread_rwlock_t __pthread_threads_lock;
#define __pthread_getid(thread) \
({ struct __pthread *__t = NULL; \
- __pthread_rwlock_rdlock (&__pthread_threads_lock); \
+ __libc_rwlock_rdlock (GL (dl_pthread_threads_lock)); \
if (thread <= __pthread_max_threads) \
- __t = __pthread_threads[thread - 1]; \
- __pthread_rwlock_unlock (&__pthread_threads_lock); \
+ __t = GL (dl_pthread_threads)[thread - 1]; \
+ __libc_rwlock_unlock (GL (dl_pthread_threads_lock)); \
__t; })
#define __pthread_setid(thread, pthread) \
- __pthread_rwlock_wrlock (&__pthread_threads_lock); \
- __pthread_threads[thread - 1] = pthread; \
- __pthread_rwlock_unlock (&__pthread_threads_lock);
+ __libc_rwlock_wrlock (GL (dl_pthread_threads_lock)); \
+ GL (dl_pthread_threads)[thread - 1] = pthread; \
+ __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
/* Similar to pthread_self, but returns the thread descriptor instead
of the thread ID. */