Age | Commit message (Collapse) | Author |
|
Releasing a thread reference uses a mutex, which means the kernel
resources used for synchronization must be available until late during
the destruction process. For simplicity, merge __pthread_thread_dealloc
into __pthread_thread_terminate.
* Makefile (libpthread-routines): Remove pt-thread-dealloc.
* pthread/pt-create.c (__pthread_create_internal): Remove call to
__pthread_thread_dealloc.
* pthread/pt-exit.c (__pthread_exit): Likewise.
* pthread/pt-internal.h (__pthread_thread_dealloc): Remove declaration.
(__pthread_thread_terminate): Update description.
* sysdeps/mach/pt-thread-dealloc.c: Remove file.
* sysdeps/mach/pt-thread-terminate.c (__pthread_thread_terminate):
Destroy the wake up port.
|
|
This change makes libpthread release almost every resource allocated for
a thread, including the kernel thread, its send right, its reply port
and its stack. This improves resource usage after peaks of activity
during which servers can create hundreds or even thousands of threads.
To achieve this, the library relies on the recently added
thread_terminate_release one-way GNU Mach RPC, which allows threads to
release their last resources along with terminating in a single
operation. The pthread_exit function unconditionally releases all the
resources it can, including other kernel objects (namely the port used
for blocking and waking up) and signal states. When releasing the
pthread structure, a reference counter is used so that joinable threads
remain available. Once the reference counter drops to 0, the pthread
structure can be recycled. Thread local storage (TLS) is also recycled
since it needs to remain allocated while terminating the thread, as it
is there that the reply port is stored. TLS could be released too, after
grabbing the reply port name, but it is difficult to make sure no RPC
involving a reply port is used afterwards, so the simpler solution of
recycling TLS was chosen.
* Makefile (libpthread-routines): Replace pt-thread-halt with
pt-thread-terminate.
* pthread/pt-alloc.c (initialize_pthread): Set reference counter and
unconditionally initialize new threads completely.
(__pthread_alloc): Remove call to __pthread_thread_halt, update calls
to initialize_pthread.
* pthread/pt-create.c (__pthread_create_internal): Don't attempt to
reuse stacks, handle reference counter, update failure handling.
* pthread/pt-dealloc.c: Include bits/pt-atomic.h.
(__pthread_dealloc): Make pthread structure available for reuse when
reference counter reaches 0.
* pthread/pt-detach.c (pthread_detach): Assume the target thread takes
care of its own resources and, as a result, simply unreference its
pthread struct.
* pthread/pt-exit.c (__pthread_exit): Release resources and terminate.
* pthread/pt-internal.h (struct __pthread): New `nr_refs' member.
(__pthread_alloc): Update description.
(__pthread_dealloc): Likewise.
(__pthread_thread_dealloc): Likewise.
(__pthread_thread_terminate): New declaration.
* pthread/pt-join.c (pthread_join): Assume the target thread takes care
of its own resources and, as a result, simply unreference its pthread
struct.
* sysdeps/mach/hurd/pt-sigstate-destroy.c
(__pthread_sigstate_destroy): Call _hurd_sigstate_delete.
* sysdeps/mach/hurd/pt-sigstate-init.c (__pthread_sigstate_init): Call
_hurd_thread_sigstate and _hurd_sigstate_set_global_rcv when
appropriate.
* sysdeps/mach/hurd/pt-sysdep.c (__pthread_create_internal): Prevent
the library from releasing the stack of the main thread.
* sysdeps/mach/hurd/pt-sysdep.h (PTHREAD_SYSDEP_MEMBERS): Remove
`have_kernel_resources' from the list of sysdep members.
* sysdeps/mach/pt-thread-alloc.c (__pthread_thread_alloc): Update
thread allocation.
* sysdeps/mach/pt-thread-dealloc.c (__pthread_thread_dealloc): Update
description.
* sysdeps/mach/pt-thread-halt.c: Remove file.
* sysdeps/mach/pt-thread-start.c (__pthread_thread_start): Fix the
conditions under which a thread should actually be started.
* sysdeps/mach/pt-thread-terminate.c: New file.
|
|
Since libc functions used up to actual thread termination (including the
termination RPC itself) are to use TLS.
* pthread/pt-alloc.c (initialize_pthread): Set `tcb` field of `new` to NULL.
(__pthread_alloc): Deallocate TLS of to-be-reused `new` thread.
* pthread/pt-create.c (__pthread_create_internal): Reset `tcb` field to NULL
after deallocation.
* pthread/pt-exit.c (__pthread_exit): Do not deallocate TLS.
|
|
This avoids a conflict with glibc-provided bits/atomic.h
* sysdeps/ia32/bits/atomic.h: Rename to...
* sysdeps/ia32/bits/pt-atomic.h: ... this.
* pthread/pt-create.c: Include <bits/pt-atomic.h> instead of <bits/atomic.h>
* pthread/pt-exit.c: Likewise.
* pthread/pt-internal.h: Likewise.
|
|
Libc will need to be able to call them, so they need to have a different
name.
* pthread/pt-exit.c (pthread_exit): Rename with __ prefix and add strong alias.
* pthread/pt-self.c (pthread_self): Likewise.
* pthread/pt-setcancelstate.c (pthread_setcancelstate): Likewise
* pthread/pt-setcanceltype.c (pthread_setcanceltype): Likewise
* sysdeps/generic/pt-attr-destroy.c (pthread_attr_destroy): Likewise
* sysdeps/generic/pt-attr-getdetachstate.c (pthread_attr_getdetachstate): Likewise
* sysdeps/generic/pt-attr-getinheritsched.c (pthread_attr_getinheritsched): Likewise
* sysdeps/generic/pt-attr-getschedparam.c (pthread_attr_getschedparam): Likewise
* sysdeps/generic/pt-attr-getschedpolicy.c (pthread_attr_getschedpolicy): Likewise
* sysdeps/generic/pt-attr-getscope.c (pthread_attr_getscope): Likewise
* sysdeps/generic/pt-attr-init.c (pthread_attr_init): Likewise
* sysdeps/generic/pt-attr-setdetachstate.c (pthread_attr_setdetachstate): Likewise
* sysdeps/generic/pt-attr-setinheritsched.c (pthread_attr_setinheritsched): Likewise
* sysdeps/generic/pt-attr-setschedparam.c (pthread_attr_setschedparam): Likewise
* sysdeps/generic/pt-attr-setschedpolicy.c (pthread_attr_setschedpolicy): Likewise
* sysdeps/generic/pt-attr-setscope.c (pthread_attr_setscope): Likewise
* sysdeps/generic/pt-cond-brdcast.c (pthread_cond_broadcast): Likewise
* sysdeps/generic/pt-cond-destroy.c (pthread_cond_destroy): Likewise
* sysdeps/generic/pt-cond-init.c (pthread_cond_init): Likewise
* sysdeps/generic/pt-cond-signal.c (pthread_cond_signal): Likewise
* sysdeps/generic/pt-cond-timedwait.c (pthread_cond_timedwait): Likewise
* sysdeps/generic/pt-cond-wait.c (pthread_cond_wait): Likewise
* sysdeps/generic/pt-condattr-destroy.c (pthread_condattr_destroy): Likewise
* sysdeps/generic/pt-condattr-init.c (pthread_condattr_init): Likewise
* sysdeps/generic/pt-equal.c (pthread_equal): Likewise
* sysdeps/generic/pt-getschedparam.c (pthread_getschedparam): Likewise
* sysdeps/generic/pt-setschedparam.c (pthread_setschedparam): Likewise
|
|
Conflicts:
ChangeLog
Makefile
pthread/pt-exit.c
pthread/pt-internal.h
sysdeps/mach/hurd/ia32/pt-setup.c
sysdeps/mach/hurd/pt-docancel.c
sysdeps/mach/hurd/pt-sysdep.h
|
|
* Makefile (CFLAGS): Define ENABLE_TLS.
* pthread/pt-create.c (__pthread_create_internal) [ENABLE_TLS]: Call
into glibc to allocate static TLS block.
* pthread/pt-exit.c (pthread_exit) [ENABLE_TLS]: Call into glibc to
deallocate static TLS block.
* pthread/pt-internal.h [ENABLE_TLS] (tcbhead_t): New structure; as in
glibc.
(__pthread) [ENABLE_TLS]: Add TCB member.
[ENABLE_TLS] (_dl_allocate_tls, _dl_deallocate_tls): Declare; from
glibc.
* sysdeps/mach/hurd/pt-sysdep.h (__thread_set_pcsp): Rename to
__thread_set_pcsptp. Add SET_TP and TP parameters. Change all
callers.
* sysdeps/mach/hurd/i386/pt-machdep.c (__thread_set_pcsptp): Imlement
TLS support.
* sysdeps/mach/hurd/i386/pt-setup.c (__pthread_setup): Likewise.
|
|
* pthread/cthreads-compat.c: #include <stddef.h> for NULL.
* pthread/pt-exit.c (pthread_exit): Remove stray need_dealloc variable.
* sysdeps/generic/pt-attr-getschedparam.c: #include <string.h> for memcpy.
* sysdeps/mach/hurd/ia32/pt-setup.c (stack_setup): Apply some more typecasting.
* tests/test-1.c: #include <assert.h>.
* tests/test-6.c: Likewise.
* tests/test-7.c: Likewise.
* tests/test-16.c (handler): Take parameters for sa_handler, not sa_sigaction.
|
|
* pthread/pt-alloc.c: Don't include <bits/atomic.h>.
(__pthread_free_threads): Change to a struct __pthread *.
(__pthread_free_threads_lock): New variable.
(__pthread_alloc): When looking for a TCB to reuse, iterate over
__pthread_free_threads taking the first for which the STATE field
is PTHREAD_TERMINATED. When reusing a TCB, first call
__pthread_thread_halt on it.
* pthread/pt-dealloc.c: Don't include <bits/atomic.h>.
(__pthread_free_threads): Change to a struct __pthread *.
(__pthread_free_threads_lock): New declaration.
(__pthread_dealloc): Enqueue PTHREAD on __PTHREAD_FREE_THREADS.
Set PTHREAD->STATE to PTHREAD_TERMINATED after everything else.
* pthread/pt-join.c (pthread_join): Call __pthread_thread_halt
before destroying the thread. When destroying the thread, call
__pthread_thread_dealloc on it.
* pthread/pt-detach.c (pthread_detach): If destroying the thread,
call __pthread_thread_halt before deallocating the stack. In this
case, also call __pthread_thread_dealloc on the tcb.
* pthread/pt-exit.c (pthread_exit): Call __pthread_dealloc only if
the thread is detached and then as the last thing we do before
calling __pthread_thread_halt.
* pthread/pt-internal.h (__pthread_thread_halt): Remove argument
NEED_DEALLOC. Update users.
* sysdeps/mach/pt-thread-halt.c (__pthread_thread_halt): Remove
argument need_dealloc.
* sysdeps/mach/hurd/pt-sysdep.h (PTHREAD_SYSDEP_MEMBERS): Add field
have_kernel_resources.
* sysdeps/mach/hurd/pt-thread-alloc.c (__pthread_thread_alloc): If
THREAD->HAVE_KERNEL_RESOURCES is true, just return. After
allocating the resources, set THREAD->HAVE_KERNEL_RESOURCES to
true.
|
|
Merge changes from hurd-l4 fork.
* Makefile (SRCS): Add pt-startup.c and pt-mutex-transfer-np.c.
(sysdeps_headers): Add pthread-np.h.
2008-08-12 Neal H. Walfield <neal@gnu.org>
* sysdeps/generic/bits/pthread-np.h: New file.
2008-08-12 Neal H. Walfield <neal@gnu.org>
* sysdeps/generic/pt-startup.c: New file.
2008-08-12 Neal H. Walfield <neal@gnu.org>
* sysdeps/generic/bits/mutex.h (__PTHREAD_RECURSIVE_MUTEX_INITIALIZER):
Define.
(__PTHREAD_MUTEX_RECURSIVE_INITIALIZER): Don't define.
* include/pthread/pthread.h
(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) [__USE_GNU]: Define.
(PTHREAD_MUTEX_RECURSIVE_INITIALIZER_NP): Don't define.
2008-08-12 Neal H. Walfield <neal@gnu.org>
* include/pthread/pthread.h: Include <sys/cdefs.h>.
(__extern_inline): If not defined, define appropriately.
2008-06-01 Neal H. Walfield <neal@gnu.org>
* include/pthread/pthread.h (PTHREAD_MUTEX_RECURSIVE_INITIALIZER_NP):
New definition.
* sysdeps/generic/bits/mutex.h
(__PTHREAD_MUTEX_RECURSIVE_INITIALIZER): New definition.
* sysdeps/generic/bits/mutex-attr.h (__pthread_recursive_mutexattr):
New definition.
* sysdeps/generic/pt-mutexattr.c (__pthread_recursive_mutexattr):
New declaration.
* sysdeps/generic/pt-mutex-init.c (_pthread_mutex_init): If ATTR
is &__PTHREAD_RECURSIVE_MUTEXATTR, don't allocate a copy, just
save in MUTEX->ATTR.
* sysdeps/generic/pt-mutex-destroy.c (_pthread_mutex_destroy): If
MUTEX->ATTR is &__PTHREAD_RECURSIVE_MUTEXATTR, don't free it.
2008-05-29 Thomas Schwinge <tschwinge@gnu.org>
* sysdeps/generic/sem-timedwait.c: Don't include <error.h>.
2008-05-21 Neal H. Walfield <neal@gnu.org>
* include/pthread/pthread.h: Include <bits/pthread-np.h>.
2008-03-01 Neal H. Walfield <neal@gnu.org>
* sysdeps/generic/pt-mutex-transfer-np.c: New file.
* pthread/pt-self.c (pthread_self): Assert that SELF is not NULL.
2007-12-23 Neal H. Walfield <neal@gnu.org>
* pthread/pt-join.c (pthread_join): Cast argument to
pthread_cleanup_push to avoid warning.
2007-11-23 Neal H. Walfield <neal@gnu.org>
* pthread/pt-internal.h (__pthread_startup): Add declaration.
* pthread/pt-create.c (entry_point): Call __pthread_startup.
|
|
Merge changes from mainline Hurd. Update L4 bits to compile with
those changes.
* sysdeps/l4/pt-block.c (__pthread_block): Call l4_receive, not
L4_Receive.
* sysdeps/l4/pt-create-np.c (pthread_create_from_l4_tid_np): Don't
pass TID to __pthread_create_internal. Emit a warning.
* sysdeps/l4/pt-stack-alloc.c (allocate_page): Remove function.
(__pthread_stack_alloc): Don't require that STACKSIZE is equal to
__pthread_stacksize. Call mmap.
* sysdeps/l4/pt-thread-halt.c (__pthread_thread_halt): Take
additional argument, need_dealloc. Call __pthread_dealloc. Stop
the thread.
* sysdeps/l4/hurd/pt-sysdep.c (init_routine): When calling
__pthread_create_internal, don't pass the tid.
* tests/test-1.c (main): Use pthread_mutex_init, not
PTHREAD_MUTEX_INITIALIZER.
* pthread/pt-alloc.c: Don't include <bits/atomic.h>. Include
<atomic.h>.
(__pthread_free_threads): Make it an atomicptr_t, not an
__atomicptr_t.
(__pthread_alloc): Don't use __atomicptr_compare_and_swap, use
atomic_compare_and_exchange_val_acq.
* pthread/pt-create.c: Don't include <bits/atomic.h>. Include
<atomic.h>.
(__pthread_total): Make it an atomic_fast32_t, not an __atomic_t.
(__pthread_create_internal): Use atomic_increment and
atomic_decrement, not __atomic_inc and __atomic_dec.
* pthread/pt-dealloc.c: Don't include <bits/atomic.h>. Include
<atomic.h>.
(__pthread_free_threads): Make it an atomicptr_t, not an
__atomicptr_t.
(__pthread_dealloc): Use atomic_compare_and_exchange_val_acq, not
__atomicptr_compare_and_swap.
* pthread/pt-exit.c: Don't include <bits/atomic.h>. Include
<atomic.h>.
(pthread_exit): Use atomic_decrement_and_test, not
__atomic_dec_and_test.
* pthread/pt-internal.h: Don't include <bits/atomic.h>. Include
<atomic.h>.
(__pthread_total): Make it an atomic_fast32_t, not an __atomic_t.
* sysdeps/powerpc/bits/atomic.h: Remove file.
* sysdeps/ia32/bits/atomic.h: Likewise.
|
|
* pthread/pt-internal.h: Include <atomic.h>, not <bits/atomic.h>.
(__pthread_total): Change type of declaration to uatomic_max_t.
* pthread/pt-alloc.c: Include <atomic.h>, not <bits/atomic.h>.
(__pthread_free_threads): Change type to uatomicptr_t.
(__pthread_alloc): Call atomic_compare_and_exchange_val_acq
instead of __atomicptr_compare_and_swap.
* pthread/pt-create.c: Include <atomic.h>, not <bits/atomic.h>.
(__pthread_total): Change type to uatomic_max_t.
(__pthread_create_internal): Call atomic_increment, not
__atomic_inc and atomic_decrement, not __atomic_dec.
* pthread/pt-dealloc.c: Include <atomic.h>, not <bits/atomic.h>.
(__pthread_free_threads): Declare as uatomicptr_t.
(__pthread_dealloc): Call atomic_compare_and_exchange_val_acq
instead of __atomicptr_compare_and_swap.
* pthread/pt-exit.c: Include <atomic.h>, not <bits/atomic.h>.
(pthread_exit): Call atomic_decrement_and_test instead of
__atomic_dec_and_test.
* sysdeps/l4/pt-create-np.c: Do not include <bits/atomic.h>.
|
|
2005-05-04 Neal H. Walfield <neal@gnu.org>
* Makefile (SRCS): Add pt-thread_dealloc.c.
* sysdeps/mach/pt-thread-dealloc.c: New file.
* pthread/pt-internal.h (__pthread_thread_dealloc): New
declaration.
(__pthread_thread_halt): Add parameter NEED_DEALLOC. Update
callers.
* sysdeps/mach/pt-thread-halt.c (__pthread_thread_halt): Respect
new NEED_DEALLOC parameter. Move code which deallocates kernel
resources from here ...
* sysdeps/mach/pt-thread-dealloc.c (__pthread_thread_dealloc):
...to here.
* pthread/pt-create.c (__pthread_create_internal): Call
__pthread_thread_dealloc on failure.
* pthread/pt-exit.c (pthread_exit): Call __pthread_thread_dealloc.
* sysdeps/mach/pt-thread-alloc.c (create_wakeupmsg): Call
__mach_port_destroy to deallocate the receive right.
__mach_port_deallocate won't do it.
* pthread/pt-detach.c (pthread_detach): Don't call
__pthread_thread_halt a second time.
* sysdeps/mach/hurd/pt-sysdep.c (_cthread_init_routine): Fix
declaration.
(init_routine): Update declaration and remove gratuitous cast.
|
|
|