From 4a6de6dc5632fd08588983a4f5bf6ac79d991deb Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Fri, 19 Mar 2004 04:18:42 +0000 Subject: 2004-03-19 Marcus Brinkmann * sysdeps/l4/bits/pthread-np.h (pthread_pool_add_np, pthread_pool_get_np): New prototypes. * sysdeps/l4/pt-pool-np.c: New file. * Makefile.am (libpthread_a_SOURCES): Add pt-pool-np.c. * sysdeps/l4/pt-thread-alloc.c (__pthread_thread_alloc): Try to allocate thread from pool. * sysdeps/l4/pt-thread-halt.c (__pthread_thread_halt): Add thread to pool after stopping it. --- sysdeps/l4/bits/pthread-np.h | 6 +++++ sysdeps/l4/pt-pool-np.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ sysdeps/l4/pt-thread-alloc.c | 4 ++++ sysdeps/l4/pt-thread-halt.c | 6 ++--- 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 sysdeps/l4/pt-pool-np.c (limited to 'sysdeps/l4') diff --git a/sysdeps/l4/bits/pthread-np.h b/sysdeps/l4/bits/pthread-np.h index b487e6d..7e80710 100644 --- a/sysdeps/l4/bits/pthread-np.h +++ b/sysdeps/l4/bits/pthread-np.h @@ -35,4 +35,10 @@ extern int pthread_create_from_l4_tid_np (pthread_t *thread, void *(*start_routine)(void *), void *arg); +/* Add the thread TID to the internal kernel thread pool. */ +int pthread_pool_add_np (l4_thread_id_t tid); + +/* Get the first thread from the pool. */ +l4_thread_id_t pthread_pool_get_np (void); + #endif /* bits/pthread-np.h */ diff --git a/sysdeps/l4/pt-pool-np.c b/sysdeps/l4/pt-pool-np.c new file mode 100644 index 0000000..c59e15a --- /dev/null +++ b/sysdeps/l4/pt-pool-np.c @@ -0,0 +1,52 @@ +/* Thread pool for L4 threads. + Copyright (C) 2004 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include + +static pthread_mutex_t pool_lock = PTHREAD_MUTEX_INITIALIZER; + +l4_thread_id_t pool_list = l4_nilthread; + +/* Add the thread TID to the pthread kernel thread pool. */ +int +pthread_pool_add_np (l4_thread_id_t tid) +{ + __pthread_mutex_lock (&pool_lock); + /* FIXME: Do error checking. */ + l4_set_user_defined_handle_of (tid, pool_list); + pool_list = tid; + __pthread_mutex_unlock (&pool_lock); + return 0; +} + + +/* Get the first thread from the pool. */ +l4_thread_id_t +pthread_pool_get_np (void) +{ + l4_thread_id_t tid; + + __pthread_mutex_lock (&pool_lock); + /* FIXME: Do error checking. */ + tid = pool_list; + pool_list = l4_user_defined_handle_of (tid); + __pthread_mutex_unlock (&pool_lock); + return tid; +} diff --git a/sysdeps/l4/pt-thread-alloc.c b/sysdeps/l4/pt-thread-alloc.c index 00e99ff..07784f5 100644 --- a/sysdeps/l4/pt-thread-alloc.c +++ b/sysdeps/l4/pt-thread-alloc.c @@ -36,6 +36,10 @@ __pthread_thread_alloc (struct __pthread *thread) } else { + thread->threadid = pthread_pool_get_np (); + if (thread->threadid != l4_nilthread) + return 0; + #if 0 CORBA_Environment env; diff --git a/sysdeps/l4/pt-thread-halt.c b/sysdeps/l4/pt-thread-halt.c index ea97eea..991123c 100644 --- a/sysdeps/l4/pt-thread-halt.c +++ b/sysdeps/l4/pt-thread-halt.c @@ -1,5 +1,5 @@ -/* Deallocate the kernel thread resources. Mach version. - Copyright (C) 2000,02 Free Software Foundation, Inc. +/* Deallocate the kernel thread resources. L4version. + Copyright (C) 2000, 2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -26,6 +26,6 @@ void __pthread_thread_halt (struct __pthread *thread) { - /* FIXME reuse thread somehow */ l4_stop (thread->threadid); + pthread_pool_add_np (thread->threadid); } -- cgit v1.2.3