diff options
Diffstat (limited to 'libpthread/sysdeps')
-rw-r--r-- | libpthread/sysdeps/l4/hurd/pt-sysdep.h | 2 | ||||
-rw-r--r-- | libpthread/sysdeps/l4/hurd/pt-thread-alloc.c | 7 | ||||
-rw-r--r-- | libpthread/sysdeps/l4/hurd/pt-thread-dealloc.c | 55 | ||||
-rw-r--r-- | libpthread/sysdeps/l4/hurd/pt-thread-halt.c | 80 |
4 files changed, 67 insertions, 77 deletions
diff --git a/libpthread/sysdeps/l4/hurd/pt-sysdep.h b/libpthread/sysdeps/l4/hurd/pt-sysdep.h index 08bcd14..5e9fabd 100644 --- a/libpthread/sysdeps/l4/hurd/pt-sysdep.h +++ b/libpthread/sysdeps/l4/hurd/pt-sysdep.h @@ -42,6 +42,8 @@ l4_thread_id_t threadid; \ addr_t exception_area[EXCEPTION_AREA_SIZE / PAGESIZE]; \ void *exception_area_va; \ + /* If the above four fields are valid. */ \ + bool have_kernel_resources; \ l4_word_t my_errno; extern inline struct __pthread * diff --git a/libpthread/sysdeps/l4/hurd/pt-thread-alloc.c b/libpthread/sysdeps/l4/hurd/pt-thread-alloc.c index ada7b3b..11af1d0 100644 --- a/libpthread/sysdeps/l4/hurd/pt-thread-alloc.c +++ b/libpthread/sysdeps/l4/hurd/pt-thread-alloc.c @@ -35,12 +35,15 @@ extern addr_t meta_data_activity; int __pthread_thread_alloc (struct __pthread *thread) { + if (thread->have_kernel_resources) + return 0; + + /* The main thread is already running of course. */ if (__pthread_num_threads == 1) { thread->object = __hurd_startup_data->thread; thread->threadid = l4_myself (); - return 0; } else { @@ -91,5 +94,7 @@ __pthread_thread_alloc (struct __pthread *thread) thread->object = storage.addr; } + thread->have_kernel_resources = true; + return 0; } diff --git a/libpthread/sysdeps/l4/hurd/pt-thread-dealloc.c b/libpthread/sysdeps/l4/hurd/pt-thread-dealloc.c new file mode 100644 index 0000000..71b3d96 --- /dev/null +++ b/libpthread/sysdeps/l4/hurd/pt-thread-dealloc.c @@ -0,0 +1,55 @@ +/* Deallocate a thread. Viengoos version. + Copyright (C) 2008 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 <assert.h> +#include <errno.h> + +#include <pt-internal.h> + +#include <hurd/exceptions.h> +#include <hurd/mutex.h> +#include <hurd/as.h> +#include <hurd/addr.h> + +void +__pthread_thread_dealloc (struct __pthread *thread) +{ + assert (thread != _pthread_self ()); + + /* Clean up the exception page. */ + exception_page_cleanup + (ADDR_TO_PTR (addr_extend (thread->exception_area[EXCEPTION_PAGE], + 0, PAGESIZE_LOG2))); + + /* Free the storage. */ + int i; + for (i = 0; i < EXCEPTION_AREA_SIZE / PAGESIZE; i ++) + { + assert (! ADDR_IS_VOID (thread->exception_area[i])); + storage_free (thread->exception_area[i], false); + } + + /* And the address space. */ + as_free (addr_chop (PTR_TO_ADDR (thread->exception_area_va), + EXCEPTION_AREA_SIZE_LOG2), false); + + storage_free (thread->object, false); + + thread->have_kernel_resources = 0; +} diff --git a/libpthread/sysdeps/l4/hurd/pt-thread-halt.c b/libpthread/sysdeps/l4/hurd/pt-thread-halt.c index 98fefaa..aef1395 100644 --- a/libpthread/sysdeps/l4/hurd/pt-thread-halt.c +++ b/libpthread/sysdeps/l4/hurd/pt-thread-halt.c @@ -22,83 +22,11 @@ #include <pt-internal.h> -#include <hurd/exceptions.h> -#include <hurd/mutex.h> -#include <hurd/as.h> -#include <hurd/addr.h> - -/* If we try to deallocate our self, we will end up causing a - deadlock. Thus, when a thread tries to free itself, we add it - here. The next thread to free a thread will free it. */ -ss_mutex_t saved_object_lock; -static addr_t saved_object; +#include <hurd/thread.h> void -__pthread_thread_halt (struct __pthread *thread, int need_dealloc) +__pthread_thread_halt (struct __pthread *thread) { - /* We may deallocate THREAD. First save any data we need. */ - - addr_t exception_area[EXCEPTION_AREA_SIZE / PAGESIZE]; - memcpy (exception_area, thread->exception_area, - sizeof (thread->exception_area)); - memset (thread->exception_area, 0, sizeof (thread->exception_area)); - - void *va = thread->exception_area_va; - - addr_t object = thread->object; - l4_thread_id_t tid = thread->threadid; - - if (need_dealloc) - __pthread_dealloc (thread); - - /* The THREAD data structure is no longer valid. */ - thread = NULL; - - /* Deallocate any saved object. */ - ss_mutex_lock (&saved_object_lock); - if (! ADDR_IS_VOID (saved_object)) - { - storage_free (saved_object, false); - saved_object = ADDR_VOID; - } - ss_mutex_unlock (&saved_object_lock); - - /* Free the exception area. */ - - /* Clean up the exception page. */ - exception_page_cleanup - (ADDR_TO_PTR (addr_extend (exception_area[EXCEPTION_PAGE], - 0, PAGESIZE_LOG2))); - - /* Free the storage. */ - int i; - for (i = 0; i < EXCEPTION_AREA_SIZE / PAGESIZE; i ++) - { - assert (! ADDR_IS_VOID (exception_area[i])); - storage_free (exception_area[i], false); - } - - /* And the address space. */ - as_free (addr_chop (PTR_TO_ADDR (va), EXCEPTION_AREA_SIZE_LOG2), false); - - if (tid == l4_myself ()) - /* If we try to storage_free (storage.addr), we will freeze in the - middle. That's no good. We set SAVED_OBJECT to our thread - object and the next thread in will free us. */ - { - ss_mutex_lock (&saved_object_lock); - saved_object = object; - ss_mutex_unlock (&saved_object_lock); - } - else - storage_free (object, false); - - if (tid == l4_myself ()) - { - l4_send_timeout (l4_myself (), L4_NEVER); - panic ("Failed to stop thread %x.%x!", - l4_thread_no (l4_myself ()), l4_version (l4_myself ())); - } - else - thread_stop (object); + if (thread->have_kernel_resources) + thread_stop (thread->object); } |