Age | Commit message (Collapse) | Author |
|
|
|
* Makefile (CPPFLAGS): Remove -DENABLE_TLS.
* pthread/pt-alloc.c: Remove ENABLE_TLS condition.
* pthread/pt-create.c: Likewise.
* pthread/pt-internal.h: Likewise.
|
|
* sysdeps/mach/hurd/bits/mutex.h: reformat copyright blurb intro to
match other files
* replace Free Software Foundation address using gnu.org URL from
upstream glibc copyright blurbs.
* apply upstream glibc scripts/update-copyrights
* update copyright date syntax per upstream glibc request
|
|
|
|
* pthread/pt-alloc.c (__pthread_alloc): Use __pthread_rwlock_wrlock and
__pthread_rwlock_unlock instead of pthread_rwlock_wrlock and
pthread_rwlock_unlock.
* pthread/pt-create.c (__pthread_create_internal): Use__pthread_rwlock_rdlock and
__pthread_rwlock_unlock instead of pthread_rwlock_rdlock and
pthread_rwlock_unlock.
* pthread/pt-dealloc.c (__pthread_dealloc): Use
__pthread_cond_broadcast, __pthread_mutex_lock, and
__pthread_mutex_unlock instead of pthread_cond_broadcast,
pthread_mutex_lock, and pthread_mutex_unlock
* pthread/pt-exit.c (__pthread_exit): Use __pthread_setcancelstate and
__pthread_cond_broadcast instead of pthread_setcancelstate and
pthread_cond_broadcast.
* pthread/pt-internal.h (__pthread_getid, __pthread_setid): Use
__pthread_rwlock_rdlock, __pthread_rwlock_wrlock, and
__pthread_rwlock_unlock instead of pthread_rwlock_rdlock,
pthread_rwlock_wrlock, and pthread_rwlock_unlock
* pthread/pt-join.c (pthread_join): Use __pthread_cond_wait instead of
pthread_cond_wait.
* sysdeps/hurd/pt-key-delete.c (pthread_key_delete): Use
__pthread_rwlock_rdlock and __pthread_rwlock_unlock instead of
pthread_rwlock_rdlock and pthread_rwlock_unlock.
|
|
* pthread/pt-alloc.c (initialize_pthread): Reset resolver state.
* pthread/pt-create.c: Include <resolv.h>.
(entry_point): Update the __resp TLS variable to point to the resolver
state of the current thread.
* pthread/pt-internal.h: Define __need_res_state and include <resolv.h>.
(struct __pthread): New `res_state' member.
|
|
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 patch solves two issues. The first one is cancellation handling
when a cancellation request is sent before reaching a cancellation
point (namely, pthread_cond_{timed,}wait). Cancellation is implemented
by pushing an appropriate cleanup handler and switching to
PTHREAD_CANCEL_ASYNCHRONOUS type. The main problem is that it doesn't
handle pending requests, only a cancellation that occurs while blocking.
Other problems occur when trying to correctly handle a timeout and a
cancellation request through the cleanup routine.
The other issue is correctly handling timeouts. This problem was already
well known, as explained by the following comment :
"FIXME: What do we do if we get a wakeup message before we disconnect
ourself? It may remain until the next time we block."
In addition, the prevp thread member is inconsistently used. It is
sometimes accessed while protected by the appropriate queue lock to
determine whether a thread is still queued, while at times, threads
are unqueued without holding a lock, as in pthread_cond_broadcast :
/* We can safely walk the list of waiting threads without holding
the lock since it is now decoupled from the condition. */
__pthread_dequeuing_iterate (wakeup, wakeup)
__pthread_wakeup (wakeup);
This is the root cause that triggers some assertion failures.
The solution brought by this patch is to consistently use the prevp link
to determine if both a thread has been unqueued and if a wakeup message
has been sent (both are needed to wake up a thread). A thread unblocked
because of a timeout can now accurately determine if it needs to drain
its message queue. A direct improvement is that the message queue size
can be limited to one message, and wakeups are guaranteed to be
non-blocking, which allows safely calling __pthread_wakeup from critical
sections.
As it now affects the cleanup cancellation routine of
__pthread_cond_timedwait_internal, cancellation is reworked as well.
Cancellation type is forced to PTHREAD_CANCEL_DEFERRED during the call,
and actually checked on both entry and return. A hook is set by the
blocking thread so that the waker doesn't need to know about the call
implementation. Cancellation members are now protected with a mutex for
truely safe access.
* pthread/pt-alloc.c (initialize_pthread): Initialize the new `cancel_lock',
`cancel_hook' and `cancel_hook_args' fields.
* pthread/pt-cancel.c (pthread_cancel): Rework cancellation handling.
* pthread/pt-internal.h (struct __pthread): Add `cancel_lock', `cancel_hook'
and `cancel_hook_args' fields.
(__pthread_dequeue): Assert thread->prevp isn't NULL.
* pthread/pt-join.c (pthread_join): Describe how the cancellation point is
implemented.
* pthread/pt-setcancelstate.c (__pthread_setcancelstate): Lock the given
thread cancellation lock when switching state.
* pthread/pt-setcanceltype.c (__pthread_setcanceltype): Likewise for
cancellation type.
* pthread/pt-testcancel.c (pthread_testcancel): Likewise for pending
cancellations.
* sysdeps/generic/pt-cond-brdcast.c (__pthread_cond_broadcast): Dequeue
and wake up threads with condition locked.
* sysdeps/generic/pt-cond-signal.c (cond_signal): Remove function, move
implementation to ...
(__pthread_cond_signal): ... this function. Remove unused `unblocked'
variable.
* sysdeps/generic/pt-cond-timedwait.c (struct cancel_ctx): New structure.
(cancel_hook): New static function.
(__pthread_cond_timedwait_internal): Fix cancellation and timeout handling.
* sysdeps/generic/pt-mutex-timedlock.c
(__pthread_mutex_timedlock_internal): Fix timeout handling.
* sysdeps/generic/pt-rwlock-timedrdlock.c
(__pthread_rwlock_timedrdlock_internal): Likewise.
* sysdeps/generic/pt-rwlock-timedwrlock.c
(__pthread_rwlock_timedwrlock_internal): Likewise.
* sysdeps/generic/pt-rwlock-unlock.c (pthread_rwlock_unlock): Dequeue and
wake up threads with rwlock internal lock held.
* sysdeps/generic/sem-timedwait.c (__sem_timedwait_internal): Fix timeout
handling.
* sysdeps/mach/hurd/pt-docancel.c (__pthread_do_cancel): Unlock the given
thread cancellation lock.
* sysdeps/mach/pt-thread-alloc.c (create_wakeupmsg): Limit the message
queue size of the wakeup port to 1.
* sysdeps/mach/pt-wakeup.c (__pthread_wakeup): Call __mach_msg in a
non-blocking way.
|
|
* 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.
|
|
* sysdeps/generic/bits/condition.h (__PTHREAD_COND_INITIALIZER):
Remove compound statement.
* pthread/pt-alloc.c (initialize_pthread): Use compound statement.
* sysdeps/generic/pt-cond-init.c (pthread_cond_init): 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>.
|
|
* sysdeps/generic/bits/mutex.h (__PTHREAD_MUTEX_INITIALIZER):
Remove compound statement.
(pthread_mutex_init): Use compound statement with initializer.
* pthread/pt-alloc.c (initialize_pthread): Likewise.
* sysdeps/generic/pt-mutex-init.c (_pthread_mutex_init): Likewise.
|
|
2005-05-12 Neal H. Walfield <neal@gnu.org>
* include/pthread/pthread.h (pthread_exit): Add noreturn
attribute.
* sysdeps/generic/bits/condition.h (__PTHREAD_COND_INITIALIZER):
Don't create a compound literal.
* sysdeps/generic/bits/mutex.h (__PTHREAD_MUTEX_INITIALIZER):
Don't create a compound literal.
(pthread_mutex_init): Don't assign to *__MUTEX directly.
Initialize an intermediate local variable and then copy the
result.
* sysdeps/generic/bits/rwlock.h (__PTHREAD_RWLOCK_INITIALIZER):
Don't create a compound literal.
(pthread_rwlock_init): Don't assign to *__RWLOCK directly.
Initialize an intermediate local variable and then copy the
result.
* sysdeps/i386/bits/spin-lock.h (__SPIN_LOCK_INITIALIZER):
Don't create a compound literal.
* pthread/pt-alloc.c (initialize_pthread): Cast
PTHREAD_MUTEX_INITIALIZER and PTHREAD_COND_INITIALIZER to create a
compound literal.
* tests/test-1.c (main): Use pthread_mutex_init, not
PTHREAD_MUTEX_INIT for mutex initialization
* sysdeps/generic/pt-barrier-init.c (pthread_barrier_init): Remove
assert. Copy ATTR if non-defaults are used.
* sysdeps/generic/pt-cond-init.c (pthread_cond_init): Include
<string.h>. Remove assert. Copy ATTR if non-defaults are used.
* sysdeps/generic/pt-mutex-init.c (_pthread_mutex_init): Cast
PTHREAD_MUTEX_INITIALIZER to create a compound literal.
* sysdeps/generic/pt-rwlock-init.c: Include <string.h>.
(_pthread_rwlock_init): Cast __PTHREAD_RWLOCK_INITIALIZER to
create a compound literal. Copy ATTR if non-defaults are used.
* sysdeps/generic/pt-cond-timedwait.c
(__pthread_cond_timedwait_internal): Check that ABSTIME->TV_NSEC
is valid. Don't shadow ERR. Don't return before cleaning up.
* sysdeps/generic/pt-mutex-timedlock.c (pthread_mutex_timedlock):
Move after __pthread_mutex_timedlock_internal. Check that
ABSTIME->TV_NSEC is valid.
* sysdeps/generic/pt-rwlock-timedrdlock.c
(pthread_rwlock_timedrdlock): Move after.
__pthread_rwlock_timedrdlock_internal.
(__pthread_rwlock_timedrdlock_internal): Check that
ABSTIME->TV_NSEC is valid.
* sysdeps/generic/pt-rwlock-timedwrlock.c
(pthread_rwlock_timedwrlock): Move after
__pthread_rwlock_timedwrlock_internal.
(__pthread_rwlock_timedwrlock_internal): Check that
ABSTIME->TV_NSEC is valid.
* sysdeps/generic/sem-timedwait.c (__sem_timedwait_internal):
Check that TIMEOUT->TV_NSEC is valid before enqueuing the thread.
* sysdeps/generic/pt-rwlock-rdlock.c
(__pthread_rwlock_timedrdlock_internal): Fix declaration.
* sysdeps/generic/pt-mutex-trylock.c (__pthread_mutex_trylock):
Don't return EDEADLK. POSIX does not allow it.
* sysdeps/mach/pt-timedblock.c (__pthread_timedblock): Calculate
the relative timeout without overflowing.
* sysdeps/mach/hurd/i386/pt-setup.c (stack_setup): Cast THREAD.
|
|
2005-05-02 Neal H. Walfield <neal@gnu.org>
* pthread/pt-alloc.c (__pthread_alloc): Set the thread id to the
table index plus one.
* pthread/pt-internal.h (__pthread_getid): Index __pthread_threads
using THREAD - 1, not THREAD.
(__pthread_setid): Likewise.
* pthread/pt-create.c (__pthread_create_internal): Likewise.
* sysdeps/generic/pt-mutex-trylock.c (__pthread_mutex_trylock):
When returning EBUSY, don't forget to first unlock MUTEX->__HELD.
|
|
|