summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2014-12-04Fix pthread_create return value on TLS allocation failureSamuel Thibault
* pthread/pt-create.c (__pthread_create_internal): When _dl_allocate_tls returns NULL, set `err' to ENOMEM.
2014-11-02Fix safety of pthread_barrier_waitSamuel Thibault
The barrier queue uses threads' next field, so it can not actually be safely walked without holding the barrier lock. * sysdeps/generic/pt-barrier-wait.c (pthread_barrier_wait): Record an array of __pthread to wake while holding the lock, and wake them only after unlocking it.
2014-11-02Wake up queued threads without spin lock heldSamuel Thibault
so that they may have a chance to actually preempt us. Otherwise they will merely immediately fail to acquire the spin lock, and thus preemption will have served no purpose. * sysdeps/generic/pt-rwlock-unlock.c (pthread_rwlock_unlock): Record an array of __pthread to wake while holding the lock, and wake them only after unlocking it.
2014-11-02Wake up queued threads without spin lock heldSamuel Thibault
so that they may have a chance to actually preempt us. Otherwise they will merely immediately fail to acquire the spin lock, and thus preemption will have served no purpose. * sysdeps/generic/pt-cond-brdcast.c (__pthread_cond_broadcast): Unlock cond->__lock while waking the queued thread.
2014-09-28Fetch stack size from rlimitSamuel Thibault
* pthread/pt-create.c: Include <hurd/resource.h> (__pthread_create_internal): When `attr''s stacksize is 0, try to get the desired size from the RLIMIT_STACK rlimit before defaulting to PTHREAD_STACK_DEFAULT. * sysdeps/generic/pt-attr.c (__pthread_default_attr): Set stacksize to 0 instead of PTHREAD_STACK_DEFAULT.
2014-08-31Fix stack address computationSamuel Thibault
stackaddr is supposed to be an adressable byte, i.e. not inside the guard size. * pthread/pt-getattr.c (pthread_getattr_np): Take guard size into account when returning the stack bottom address.
2014-08-20Add __pthread_key_create aliasSamuel Thibault
Some versions of std::thread use it to detect the presence of libpthread (don't ask why) * sysdeps/hurd/pt-key-create.c (pthread_key_create): Rename to __pthread_key_create. (pthread_key_create): Define as strong alias of __pthread_key_create. * Versions (libpthread): Add __pthread_key_create.
2014-08-20Fix guard size computationSamuel Thibault
* pthread/pt-create.c (__pthread_create_internal): On thread creation failure, take guard size into account when deallocating the stack. * sysdeps/mach/pt-thread-terminate.c (__pthread_thread_terminate): Take guard size into account when deallocating the stack.
2014-06-02Remove unused signals implementationSamuel Thibault
* signal/README: Remove file. * signal/TODO: Likewise. * signal/kill.c: Likewise. * signal/pt-kill-siginfo-np.c: Likewise. * signal/sig-internal.c: Likewise. * signal/sig-internal.h: Likewise. * signal/sigaction.c: Likewise. * signal/sigaltstack.c: Likewise. * signal/signal-dispatch.c: Likewise. * signal/signal.h: Likewise. * signal/sigpending.c: Likewise. * signal/sigsuspend.c: Likewise. * signal/sigtimedwait.c: Likewise. * signal/sigwaiter.c: Likewise. * signal/sigwaitinfo.c: Likewise.
2014-05-23Fix guardsize computationSamuel Thibault
* pthread/pt-create.c (__pthread_create_internal): Round guardsize up to page size. Fill `guardsize' field of thread structure. * sysdeps/mach/hurd/i386/pt-setup.c (stack_setup): Add guardsize to computation of the top of the stack.
2014-05-02Fix guardsize semanticSamuel Thibault
POSIX says guardsize is in addition to stacksize, not included. * pthread/pt-create.c (__pthread_create_internal): Use setup->guardsize + setup->stacksize as stack allocation size. Do not truncate guardsize to stacksize. * pthread/pt-internal.h (guardsize): Remove comment. * sysdeps/generic/pt-attr-setstacksize.c (pthread_attr_setstacksize): Do not truncate guardsize to stacksize.
2014-04-07Merge branch 'foo'Samuel Thibault
2014-04-07We don't have Hurd TSD any more, drop TODO entrySamuel Thibault
2014-04-04Use only clock_gettime, do not depend on librtSamuel Thibault
clock_gettime is actually provided by libc, not librt, so we don't need the latter, and thus avoid the librt dependency, which would cause initialization issues. * sysdeps/generic/pt-condattr-setclock.c (pthread_condattr_setclock): Use clock_gettime instead of clock_getres to test for clock availability. * Makefile: Do not link against librt.
2014-02-19Make name resolution thread-safeRichard Braun
* 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.
2014-01-22Fix up the main thread TCBRichard Braun
Unlike other threads, the TCB of the main thread is created by the C library before libpthread is initialized and needs special care. * sysdeps/mach/hurd/i386/pt-setup.c (__pthread_setup): Set the `self' member of the main thread TCB.
2014-01-22Fix thread destructionRichard Braun
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.
2014-01-02Revert "Fix glibc spinlock inclusion"Samuel Thibault
This reverts commit 414e0bbabb6ac7a5cff148b927ec874dff922be1. It's these versions which would end up being installed. Some other way needs to be found, or else we'll have to just duplicate or move the content.
2014-01-02Fix glibc spinlock inclusionSamuel Thibault
Using an i386 Implies would change inclusion order in the rest of libc too, entailing a lot of issues. We can simply make mach/i386 include i386 instead. * sysdeps/mach/i386/bits/spin-lock-inline.h: Include ../../../sysdeps/i386/bits/spin-lock-inline.h. * sysdeps/mach/i386/bits/spin-lock.h: Include ../../../sysdeps/i386/bits/spin-lock.h.
2014-01-02add FIXME commentSamuel Thibault
2014-01-01Revert "Add missing dependency to get i386 spinlocks"Samuel Thibault
This reverts commit 40376cfa5d8bd4814b29b777a7d0a6b2b6ed2a7c.
2014-01-01Add missing dependency to get i386 spinlocksSamuel Thibault
* sysdeps/mach/hurd/i386/Implies: Add i386.
2014-01-01Merge branch 'tmp'Samuel Thibault
2014-01-01Add warnings about non-implemented functions.Samuel Thibault
* sysdeps/generic/pt-getcpuclockid.c (pthread_getcpuclockid): Add warning stub. * sysdeps/generic/pt-getschedparam.c (pthread_getschedparam): Likewise. * sysdeps/generic/pt-key-create.c (pthread_key_create): Likewise. * sysdeps/generic/pt-key-delete.c (pthread_key_delete): Likewise. * sysdeps/generic/pt-mutex-getprioceiling.c (pthread_mutex_getprioceiling): Likewise. * sysdeps/generic/pt-mutex-setprioceiling.c (pthread_mutex_setprioceiling): Likewise. * sysdeps/generic/pt-mutexattr-getprioceiling.c (pthread_mutexattr_getprioceiling): Likewise. * sysdeps/generic/pt-mutexattr-setprioceiling.c (pthread_mutexattr_setprioceiling): Likewise. * sysdeps/generic/pt-setschedparam.c (pthread_setschedparam): Likewise. * sysdeps/generic/pt-setschedprio.c (pthread_setschedprio): Likewise.
2014-01-01Add compatibility with kernels without __thread_terminate_releaseSamuel Thibault
This would leak, but at least let the user reboot nicely into a newer kernel. * sysdeps/mach/pt-thread-terminate.c (__pthread_thread_terminate): If __thread_terminate_release returns, use __thread_terminate to terminate the thread anyway.
2013-12-29Revert "Allow applications to set the default stack size"Richard Braun
This reverts commit 536420a581f9f822cdef0fc460b5176a840f49e5. Now that threadvars have been replaced with TLS, this hack is no longer needed.
2013-12-26Implement thread destructionRichard Braun
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.
2013-11-01Let libc get sigthread stack layout in static buildsSamuel Thibault
Libc only uses a weak reference, we need a stronger reference to get the symbol from libpthread2.a * libpthread.a (pthread_getattr_np, pthread_attr_getstack): Add references. * libpthread_pic.a (pthread_getattr_np, pthread_attr_getstack): Likewise.
2013-10-24Really use user-provided stackSamuel Thibault
* pthread/pt-create.c (__pthread_create_internal): When the user provides a `stackaddr`, use it instead of allocating a stack. * pthread/pt-detach.c (pthread_detach): Only deallocate the stack when it was allocated by libpthread. * pthread/pt-join.c (pthread_join): Likewise.
2013-10-20Drop threadvars entirelySamuel Thibault
2013-10-20Use function parameter instead of global variableSamuel Thibault
* sysdeps/mach/pt-stack-alloc.c(__pthread_stack_alloc): Use `stacksize` parameter instead of `__pthread_stacksize` global variable.
2013-10-16Delay TLS deallocation outside thread terminationSamuel Thibault
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.
2013-09-21Merge branch 'master' of git.savannah.gnu.org:/srv/git/hurd/libpthreadSamuel Thibault
2013-09-21Add pthread_atfork supportSamuel Thibault
* Versions (libc): Add __register_atfork with GLIBC_PRIVATE version. * forward.c: Include <errno.h> (atfork): New structure. (atfork_lock): New mutex. (fork_handlers, fork_last_handler): New variables. (atfork_pthread_prepare, atfork_pthread_parent, atfork_pthread_child): New atfork hooks (__register_atfork): New function. * sysdeps/generic/pt-atfork.c (pthread_atfork): Call __register_atfork.
2013-06-29Fix a subtle thread creation bugRichard Braun
* pthread/pt-create.c (__pthread_create_internal): Store pthread ID in caller-provided memory before starting the new thread.
2013-06-11Initialize ctypeSamuel Thibault
* pthread/pt-create.c (entry_point) [IS_IN_libpthread]: Call __ctype_init.
2013-02-15Add pthread_hurd_cond_timedwait_npRichard Braun
This new Hurd-specific function is meant to allow Hurd servers to wait for events during a bounded period of time. * Makefile (libpthread-routines): Add pt-hurd-cond-timedwait. * Versions: Include pthread_hurd_cond_timedwait_np in version GLIBC_2.17 of libpthread. * sysdeps/mach/hurd/bits/pthread-np.h (pthread_hurd_cond_timedwait_np): New declaration. * sysdeps/mach/hurd/pt-hurd-cond-timedwait.c: New file that provides __pthread_hurd_cond_timedwait_internal and __pthread_hurd_cond_timedwait_np. * sysdeps/mach/hurd/pt-hurd-cond-wait.c (__pthread_hurd_cond_wait_np): Rewrite as a call to __pthread_hurd_cond_timedwait_internal with no timeout.
2013-02-04Fix pthread timeout handling and cancellation issuesRichard Braun
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.
2013-01-25New Makefile snippet for the "pthread" sysdepPino Toscano
Hook the libpthread version when compiling glibc's confstr.c, so that confstr can show it. * sysdeps/pthread/Makefile: New file.
2013-01-25Require the "pthread" sysdepPino Toscano
This allows the use of glibc sysdeps that use pthread-based implementations. * sysdeps/mach/hurd/Implies: Add pthread.
2013-01-22Fix versions of _IO_flockfile, _IO_ftrylockfile and _IO_funlockfileRichard Braun
* Versions: Include _IO_flockfile, _IO_ftrylockfile and _IO_funlockfile in version 2.2.6 of libpthread.
2012-11-25Fix pthread_hurd_cond_wait_np versionsSamuel Thibault
* Version: Do not include pthread_hurd_cond_wait_np in libc, as we don't define a forward for it. Include pthread_hurd_cond_wait_np in version GLIBC_2.17 of libpthread, as this is a new symbol.
2012-11-25Allow applications to set the default stack sizeRichard Braun
This change is a temporary hack intended for the Hurd servers. Once Hurd threadvars are replaced with TLS, this commit should be reverted. * pthread/pt-internal.h (__pthread_default_attr): Remove const qualifier. * sysdeps/generic/pt-attr.c (__pthread_default_attr): Likewise. * sysdeps/mach/hurd/pt-sysdep.c (__pthread_stack_default_size): New variable. (init_routine): Set __pthread_default_attr.stacksize if __pthread_stack_default_size exists.
2012-11-25Add Hurd-specific condition wait functionRichard Braun
* Makefile (libpthread-routines): Add pt-hurd-cond-wait. * Versions (libc): Add pthread_hurd_cond_wait_np. (libpthread): Likewise. * sysdeps/mach/hurd/bits/pthread-np.h: New file. * sysdeps/mach/hurd/pt-hurd-cond-wait.c: Likewise.
2012-11-24Merge branch 'master' of git.savannah.gnu.org:/srv/git/hurd/libpthreadSamuel Thibault
2012-11-24Set elf=yes if not defined alreadyPino Toscano
glibc 2.16 dropped support for any binary format other than ELF, and the ELF variable has been removed too; this causes a build failure when built as glibc addon with glibc >= 2.16, since it would not link to ld.so. Defining ELF to 'yes' if not defined allows to retain compatibility with older glibc versions. * Makefile [$(..) != ''] [$(elf) = ''] (elf): Define to 'yes'.
2012-11-13Remove .cvsignore, obsoletePino Toscano
* .cvsignore: Remove file.
2012-09-15Merge branch 'master' of git.savannah.gnu.org:/srv/git/hurd/libpthreadSamuel Thibault
2012-09-15pthread_create: turn ENOMEM to EAGAINPino Toscano
ENOMEM can be returned if some malloc fail, but it is not a valid POSIX error number for pthread_create; thus turn it to EAGAIN. * pthread/pt-create.c (pthread_create): Turn ENOMEM to EAGAIN.
2012-08-07tests/Makefile: Support INSTALL_ROOT environment variable.Thomas Schwinge
* tests/Makefile [ifdef INSTALL_ROOT] (INSTALL_ROOT_CPPFLAGS) (INSTALL_ROOT_LDFLAGS): New variables. (%.o: %.c, %: %.o): New rules. (%-static: %.o): Update rule. * tests/README: Update.