aboutsummaryrefslogtreecommitdiff
path: root/htl/pt-alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'htl/pt-alloc.c')
-rw-r--r--htl/pt-alloc.c50
1 files changed, 20 insertions, 30 deletions
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));
}