summaryrefslogtreecommitdiff
path: root/lib/librthread/rthread.c
AgeCommit message (Collapse)Author
2013-06-01something's not quite right yet. ticket locks result in more CPU usageTed Unangst
and spinning in kernel. partially back out, but in a way that makes going forward again easy. seen by ajacoutot
2013-06-01cleanup and consolidate the spinlock_lock (what a name!) code.Ted Unangst
it's now atomic_lock to better reflect its usage, and librthread now features a new spinlock that's really a ticket lock. thrlseep can handle both types of lock via a flag in the clock arg. (temp back compat hack) remove some old stuff that's accumulated along the way and no longer used. some feedback from dlg, who is concerned with all things ticket lock. (you need to boot a new kernel before installing librthread)
2013-04-06fix race when exiting a detached thread. observed by and ok guentherTed Unangst
2013-02-15Revert previous diff: sparc and sparc64 don't set the TCB to NULL in exec, yet,Philip Guenther
and vax doesn't support symbols that are both weak and undefined (yet?). sparc issue diagnosed by kettenis@, vax problem found by todd@
2013-02-14Make libpthread compatible with an ld.so that does TCB allocation:Philip Guenther
if the initial thread already has a TCB then don't override it, and if the _dl_allocate_tls() and _dl_free_tls() symbols exist then use them instead of malloc/free ok kettenis@
2012-08-22We want to check that the dynamic linker is available at run-time, soMatthew Dempsky
we should actually check for _DYNAMIC at run-time rather than checking for __PIC__ at compile time, since the two are actually independent. Problem and solution identified by guenther; minor tweaks by me. ok guenther
2012-08-22Test for __PIC__ instead of PIC in preparation for eliminating -DPICMatthew Dempsky
from bsd.lib.mk for C source files. ok deraadt, pascal
2012-08-15Oops, on a.out architectures __cerror() is called _cerror(). FixMatthew Dempsky
accordingly so vax can build again. ok deraadt
2012-08-13Add explicit references from rthread.o to all of the weak symbolMatthew Dempsky
overrides provided by libpthread.a. This ensures that statically linked threaded programs use (e.g.) __cerror() from libpthread.a instead of libc.a. (Same idea previously used by libuthread.) Thanks to fgsch@ for pointing out libuthread's solution to the static linking problem. ok guenther@, tedu@;
2012-06-21__tfork() needs to set the stack address of the new thread in the kernel,Philip Guenthe
so that it can't get a signal while still running on the parent thread's stack. Also, pass in sizeof(struct __tfork) to provide forward compat when more members are added. This is an ABI change, so switch syscall numbers and bump lib majors this time. ok deraadt@ matthew@
2012-04-10pthread_setcanceltype() shouldn't be a cancelation pointPhilip Guenthe
ok kurt@
2012-03-22Remove pthread_suspend* and related functions. This is part of theKurt Miller
rthreads major library bump from last night. okay kettenis@
2012-03-20Permit recursive locking in _rthread_dl_lock(), as an so's destructorPhilip Guenthe
may need to call dlclose(). problem observed by Antti Harri (iku at openbsd.fi), ok kurt@
2012-03-14Force sched_yield() to be resolved before calling dlctl(DL_SET*LCK) withPhilip Guenthe
a function that can call sched_yield(), to avoid recursion ok kurt@ kettenis@
2012-03-03Add sem_timewait() and fix sem_wait()'s handling of signals, soPhilip Guenthe
that it resumes waiting unless the thread was canceled. As part of this, change the internal _sem_wait() function to return zero on success and an errno value on failure instead of 1 on success and zero on failure.
2012-03-02for readability, put the label on it's own line.Federico G. Schwindt
2012-02-24sched_yield() is the standard name while pthread_yield() is thePhilip Guenthe
non-standard alias, so prefer the former
2012-02-19Use a form of designated initializer that works with gcc2Philip Guenthe
lint doesn't understand designated initializers, so hide them from it
2012-02-18Fix previous commit: _rthread_init() was static.Philip Guenthe
Improve consistency of error naming
2012-02-18Fix the handling of the stackaddr, stacksize, and guardsize attributes:Philip Guenthe
don't try to merge values, round the sizes separately, and don't try to unmap application-supplied stacks. Copy from uthread the caching of default-sized stacks. Have pthread_attr_init() and pthread_create() get the default attributes from staticly allocated pthread_attr_t. Cache the pagesize in _rthread_init() and provide a macro for rounding to it based on suggestions from kettenis@ and tedu@, ok kettenis@
2012-02-16Set __isthreaded in pthread_create() instead of _rthread_init() such that itMark Kettenis
properly represents whether a process is multi-threaded or not. This fixes a bug where if a forked child would create a new thread we would not set __isthreaded. ok guenther@
2012-01-17Reimplement mutexes, condvars, and rwlocks to eliminate bugs,Philip Guenthe
particularly the "consume the signal you just sent" hang, and putting the wait queues in userspace. Do cancellation handling in pthread_cond_*wait(), pthread_join(), and sem_wait(). Add __ prefix to thr{sleep,wakeup,exit,sigdivert}() syscalls; add 'abort" argument to thrsleep to close cancellation race; make thr{sleep,wakeup} return errno values via *retval to avoid touching userspace errno.
2011-12-28pthread_self() may be much cheaper and never more expensive than getthrid()Philip Guenthe
so prefer it for identifying the current thread
2011-12-27On failure, pthread_kill() should return the errno, not -1Philip Guenthe
2011-12-05Mark sigthr()'s sig argument as __unusedPhilip Guenthe
2011-12-05Implement cancelation for the basic syscall cancelation points,Philip Guenthe
using previously allocated SIGTHR to interrupt in-process syscalls and fixing the spelling of "cancelled" along the way. Modeled on FreeBSD's libthr
2011-11-09Oh yeah, with TLS-lite we can get the thread handle without walking thePhilip Guenthe
thread list reminded by dhill@
2011-11-06Move <machine/spinlock.h> into rthread.h; strip out unnecessary #includesPhilip Guenthe
2011-10-17Use __tfork, __get_tcb, and __set_tcb to have a real TCB and per-threadPhilip Guenthe
errno. The ASM bits for _cerror are sketchy or missing for some archs but that can be corrected in-tree.
2009-11-27Convert thrsleep() to an absolute timeout with clockid to eliminate aPhilip Guenthe
race condition and prep for later support of pthread_condattr_setclock() "get it in" deraadt@, tedu@, cheers by others
2009-11-27Change threxit() to take a pointer to a pid_t to zero out from thePhilip Guenthe
kernel so that librthread can detect when a thread is completely done with its stack without need a kqueue. The dying thread moves itself to a GC list, other threads scan the GC list on pthread_create() and pthread_join() and free the stack and handle once the thread's thread id is zeroed. "get it in" deraadt@, tedu@, cheers by others
2009-02-20Fix a race in the reaper discovered by Tobias Ulmer. kevents are identified ↵Ted Unangst
by pid, so in the event that two threads get the same pid in a row, as the second is dying it will update (not add) the kevent for the previous thread with its own stack, which it will then unmap soon after, which is bad. Doing the reaping first guarantees that there are no kevents with the same pid as the exiting thread when it registers itself. ok guenther kurt
2008-10-13use calloc() instead of malloc() and memset()Kevin Lo
"look good" tedu@
2008-08-14Match libpthread's behavior and make pthread_join(NULL, whatever) failPhilip Guenthe
instead of crashing ok kurt@ first observed by Jung <moorang at gmail.com>
2008-08-14Fix 5771/library: in pthread_exit(), delay the call to _sem_post() thatPhilip Guenthe
unblocks the pthread_join() for this thread until the exiting thread is completely done with its thread structure, as the joining thread will free it once unblocked. Also, don't bother to call _sem_post() if the thread is detached. ok kurt@
2008-08-14If the initial thread calls pthread_exit(), don't overwrite its threadPhilip Guenthe
structure, as the 'tid' member there is used by other parts of librthread to determine whether the current thread is the initial thread
2008-06-05- Add fork/vfork wrapper functions to reset state in the child process.Kurt Miller
- Make an effort to protect important libc and ld.so critical areas during the fork(2)/vfork(2) sys call. - Add pthread_atfork(3) implementation based on Daniel Eischen's code. Original diff by Philip Guenther <guenther at gmail.com> with some additions and refinements by me. Positive test report from brad@ with many kde apps. fork(2) and pthread_atfork(3) pthread regresses pass. okay tedu@, kettenis@, marc@
2007-05-18Register the locking hooks with ld.so.Artur Grabowski
drahn@ ok (long time ago)
2006-01-06Initialize thread debug in _rthread_init. The debug verbosityMarco S Hyman
can be set in the environment using RTHREAD_DEBUG. ok, tedu@
2006-01-06guess it's time to remove the init printf; sturm found a port thatTed Unangst
didn't like it.
2006-01-05In pthread_join(), check if we create a deadlock trying to joinOtto Moerbeek
with ourself and only free thread after a succesful join. ok marc@
2006-01-05move malloc lock to libc interface fileTed Unangst
2006-01-05add -Wstrict-prototypes -Wmissing-prototypes -Wsign-compareMarco S Hyman
Minor tweaks to compile with the above, primarily in fixing the conflicts between semaphore.h and rthread.h "i like the additional warnings" tedu@
2006-01-04Cleanup struct pthread and stack after thread exits. This version doesOtto Moerbeek
not use a separate reaper thread. ok tedu@ marc@
2006-01-04allow threads to be created in a detached stateMarco S Hyman
do not allow a join to a detached thread "it looks good" otto@
2006-01-01thread stack handling changes. Add guard zones and allow stackMarco S Hyman
size (and guard zone size) to be set using pthread_attr. Guard zones are specified in bytes, but implemented in terms of a page size. OK Otto@
2005-12-31Implement suspend/resume and creation of initially suspended threads.Otto Moerbeek
With this, java seems to be operational. Also make threads_ready non-static, which is needed for an upcoming diff. ok tedu@
2005-12-30Remove exitinng thread from the list of threads. ok tedu@Otto Moerbeek
2005-12-30use queue.h macros for thread house keeping; make some vars non-staticOtto Moerbeek
and fix a bug in thread creation error path. ok tedu@
2005-12-30__aligned__ isn't really necessary on the struct, an aligned memberTed Unangst
will make the right thing happen. verified by kettenis and drahn