summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_sig.c
Commit message (Collapse)AuthorAgeFilesLines
* Repo copy libpthreads to libkse.obrien2007-10-091-1250/+0
| | | | | | This introduces the WITHOUT_LIBKSE nob, and changes WITHOUT_LIBPTHREADS to mean with neither threading libs. Approved by: re(kensmith)
* Remove 3rd clause, renumber, ok per emailimp2007-01-121-4/+1
|
* o Remove a cruft prevented libpthread sigaction(2) wrapper tomaxim2006-06-091-6/+0
| | | | | | | | | | | | | do its work for SIGINFO. Always install libpthread signal handler wrapper for SIGINFO even if user SIG_IGN's or SIG_DFL's it. SIGINFO has a special meaning for libpthread: when LIBPTHREAD_DEBUG enviroment variable defined it is used for dumping an information about threads to /tmp/. Reported by: mi Reviewed by: deischen MFC after: 2 weeks
* Only catch SIGINFO (for dumping thread states) when LIBPTHREAD_DEBUGdeischen2006-03-061-16/+25
| | | | | | is defined in the environment. Requested by: jmg & a few others
* Use a generic way to back threads out of wait queues when handlingdeischen2004-12-181-156/+119
| | | | | | | | | | | | | | | | | | | | | | | | | signals instead of having more intricate knowledge of thread state within signal handling. Simplify signal code because of above (by David Xu). Use macros for libpthread usage of pthread_cleanup_push() and pthread_cleanup_pop(). This removes some instances of malloc() and free() from the semaphore and pthread_once() implementations. When single threaded and forking(), make sure that the current thread's signal mask is inherited by the forked thread. Use private mutexes for libc and libpthread. Signals are deferred while threads hold private mutexes. This fix also breaks www/linuxpluginwrapper; a patch that fixes it is at http://people.freebsd.org/~deischen/kse/linuxpluginwrapper.diff Fix race condition in condition variables where handling a signal (pthread_kill() or kill()) may not see a wakeup (pthread_cond_signal() or pthread_cond_broadcast()). In collaboration with: davidxu
* Save cancelflags in signal frame, this fixes a problem thatdavidxu2004-11-011-0/+2
| | | | | | | a thread in pthread_cond_wait handled a signal can no longer be canceled. Reviewed by: deischen
* 1. Move thread list flags into new separate member, and atomicallydavidxu2004-10-231-2/+1
| | | | | | | | | | | put DEAD thread on GC list, this closes a race between pthread_join and thr_cleanup. 2. Introduce a mutex to protect tcb initialization, tls allocation and deallocation code in rtld seems no lock protection or it is broken, under stress testing, memory is corrupted. Reviewed by: deischen patch partly provided by: deischen
* Decrease reference count if we won't use the thread, this avoids memorydavidxu2004-10-211-0/+4
| | | | leak under some cases.
* Let debugger check signal, make SIGINFO works.davidxu2004-07-131-12/+25
|
* Check pending signals, if there is signal will be unblocked bydavidxu2004-06-121-1/+5
| | | | | | | | | | | | | | | | | | sigsuspend, thread shouldn't wait, in old code, it may be ignored. When a signal handler is invoked in sigsuspend, thread gets two different signal masks, one is in thread structure, sigprocmask() can retrieve it, another is in ucontext which is a third parameter of signal handler, the former is the result of sigsuspend mask ORed with sigaction's sa_mask and current signal, the later is the mask in thread structure before sigsuspend is called. After signal handler is called, the mask in ucontext should be copied into thread structure, and becomes CURRENT signal mask, then sigsuspend returns to user code. Reviewed by: deischen Tested by: Sean McNeil <sean@mcneil.com>
* Kernel now supports per-thread sigaltstack, follow the change todavidxu2004-01-031-6/+1
| | | | enable sigaltstack for scope system thread.
* Fix a typo.davidxu2004-01-021-1/+1
|
* Implement sigaltstack() as per-threaded. Current only scope process threaddavidxu2003-12-291-24/+123
| | | | | | | | is supported, for scope system process, kernel signal bits need to be changed. Reviewed by: deischen Tested on : i386 amd64 ia64
* Correctly retrieve sigaction flags.davidxu2003-12-281-2/+2
|
* Save and restore timeout field for signal frame just like what we diddavidxu2003-09-221-1/+3
| | | | | | for interrupted field. Also in _thr_sig_handler, retrieve current signal mask from kernel not from ucp, the later is pre-unioned mask, not current signal mask.
* Fix bogus comment and assign sigmask in critical region, usedavidxu2003-09-151-2/+4
| | | | SIG_CANTMASK to remove unmaskable signal masks.
* When invoking an old style signal handler, use true traditional BSD style todavidxu2003-09-141-6/+13
| | | | | | invoke signal handler. Reviewed by: deischen
* Repost masked signal to kernel for scope system thread, it hardly happensdavidxu2003-08-211-6/+25
| | | | | | in real world. Reviewed by: deischen
* _thr_sig_check_pending is also called by scope system thread when it leavesdavidxu2003-08-201-0/+3
| | | | | | | | | critical region, we wrap some syscalls for thread cancellation point, and when syscalls returns, we call _thr_leave_cancellation_point, at the time if a signal comes in, it would be buffered, and when the thread leaves _thr_leave_cancellation_point, buffered signals will be processed, to avoid messing up normal syscall errno, we should save and restore errno around signal handling code.
* Treat initial thread as scope system thread when KSE mode is not activateddavidxu2003-08-181-29/+24
| | | | | | | | | yet, so we can protect some locking code from being interrupted by signal handling. When KSE mode is turned on, reset the thread flag to scope process except we are running in 1:1 mode which we needn't turn it off. Also remove some unused member variables in structure kse. Tested by: deischen
* Add some quick pathes to exit process when signal action is default anddavidxu2003-08-101-0/+21
| | | | | | signal can causes process to exit. Reviewed by: deischen
* Initialize rtld lock just before turning on thread mode anddavidxu2003-08-101-14/+4
| | | | uninitialize rtld lock after thread mode shutdown.
* Rethink the MD interfaces for libpthread to account fordeischen2003-08-051-11/+10
| | | | | | | | | archs that can (or are required to) have per-thread registers. Tested on i386, amd64; marcel is testing on ia64 and will have some follow-up commits. Reviewed by: davidxu
* Simplify sigwait code a bit by using a waitset and removing oldsigmask.davidxu2003-07-271-15/+7
| | | | Reviewed by: deischen
* Move idle kse wakeup to outside of regions where locks are held.deischen2003-07-231-17/+27
| | | | | | | | This eliminates ping-ponging of locks, where the idle KSE wakes up only to find the lock it needs is being held. This gives little or no gain to M:N mode but greatly speeds up 1:1 mode. Reviewed & Tested by: davidxu
* o Eliminate upcall for PTHREAD_SYSTEM_SCOPE thread, now itdavidxu2003-07-171-136/+235
| | | | | | | | | | | | | is system bound thread and when it is blocked, no upcall is generated. o Add ability to libkse to allow it run in pure 1:1 threading mode, defining SYSTEM_SCOPE_ONLY in Makefile can turn on this option. o Eliminate code for installing dummy signal handler for sigwait call. o Add hash table to find thread. Reviewed by: deischen
* Don't resume sigwait thread If signal is masked.davidxu2003-07-091-8/+12
|
* POSIX says if a thread is in sigwait state, although a signal may not indavidxu2003-07-091-6/+23
| | | | | | | | its waitset, but if the signal is not masked by the thread, the signal can interrupt the thread and signal action can be invoked by the thread, sigwait should return with errno set to EINTR. Also save and restore thread internal state(timeout and interrupted) around signal handler invoking.
* Restore signal mask correctly after fork().davidxu2003-07-091-3/+4
|
* Add a newline to debug message.davidxu2003-07-071-1/+1
|
* Because there are only _SIG_MAXSIG elements in thread siginfo array,davidxu2003-06-301-14/+14
| | | | use [signal number - 1] as subscript to access the array.
* o Use a daemon thread to monitor signal events in kernel, if pendingdavidxu2003-06-281-343/+441
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | signals were changed in kernel, it will retrieve the pending set and try to find a thread to dispatch the signal. The dispatching process can be rolled back if the signal is no longer in kernel. o Create two functions _thr_signal_init() and _thr_signal_deinit(), all signal action settings are retrieved from kernel when threading mode is turned on, after a fork(), child process will reset them to user settings by calling _thr_signal_deinit(). when threading mode is not turned on, all signal operations are direct past to kernel. o When a thread generated a synchoronous signals and its context returned from completed list, UTS will retrieve the signal from its mailbox and try to deliver the signal to thread. o Context signal mask is now only used when delivering signals, thread's current signal mask is always the one in pthread structure. o Remove have_signals field in pthread structure, replace it with psf_valid in pthread_signal_frame. when psf_valid is true, in context switch time, thread will backout itself from some mutex/condition internal queues, then begin to process signals. when a thread is not at blocked state and running, check_pending indicates there are signals for the thread, after preempted and then resumed time, UTS will try to deliver signals to the thread. o At signal delivering time, not only pending signals in thread will be scanned, process's pending signals will be scanned too. o Change sigwait code a bit, remove field sigwait in pthread_wait_data, replace it with oldsigmask in pthread structure, when a thread calls sigwait(), its current signal mask is backuped to oldsigmask, and waitset is copied to its signal mask and when the thread gets a signal in the waitset range, its current signal mask is restored from oldsigmask, these are done in atomic fashion. o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait(). o Signal code locking is better than previous, there is fewer race conditions. o Temporary disable most of code in _kse_single_thread as it is not safe after fork().
* Explicitly widen int types before casting to pointer types. On 64-bitmarcel2003-06-241-3/+4
| | | | | | | | platforms the compiler warns about incompatible integer/pointer casts and on ia64 this generally is bad news. We know that what we're doing here is valid/correct, so suppress the warning. No functional change. Sleeps better: marcel
* After selecting a thread to handle a signal and takingdeischen2003-06-081-3/+8
| | | | | | | | its scheduling lock, make sure that the thread still has the signal unmasked. Make a debug statement conditional on debugging being enabled.
* Save THR_FLAGS_IN_TDLIST in signal frame, otherwise if a thread receiveddavidxu2003-05-301-1/+2
| | | | | | | a signal will can not be removed from thread list after it exited. Reviewed by: deischen Approved by: re (jhb)
* Don't really spin on a spinlock; silently convert it to the samedeischen2003-05-291-2/+3
| | | | | | | | | | | | low-level lock used by the libpthread implementation. In the future, we'll eliminate spinlocks from libc but that will wait until after 5.1-release. Don't call an application signal handler if the handler is the same as the library-installed handler. This seems to be possible after a fork and is the cause of konsole hangs. Approved by: re@ (jhb)
* Change low-level locking a bit so that we can tell ifdeischen2003-05-241-8/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | a lock is being waitied on. Fix a races in join and cancellation. When trying to wait on a CV and the library is not yet threaded, make it threaded so that waiting actually works. When trying to nanosleep() and we're not threaded, just call the system call nanosleep instead of adding the thread to the wait queue. Clean up adding/removing new threads to the "all threads queue", assigning them unique ids, and tracking how many active threads there are. Do it all when the thread is added to the scheduling queue instead of making pthread_create() know how to do it. Fix a race where a thread could be marked for signal delivery but it could be exited before we actually add the signal to it. Other minor cleanups and bug fixes. Submitted by: davidxu Approved by: re@ (blanket for libpthread)
* Add a method of yielding the current thread with the schedulerdeischen2003-05-161-117/+109
| | | | | | | | | | | | | | | | | | | | | | | lock held (_thr_sched_switch_unlocked()) and use this to avoid dropping the scheduler lock and having the scheduler retake the same lock again. Add a better way of detecting if a low-level lock is in use. When switching out a thread due to blocking in the UTS, don't switch to the KSE's scheduler stack only to switch back to another thread. If possible switch to the new thread directly from the old thread and avoid the overhead of the extra context switch. Check for pending signals on a thread when entering the scheduler and add them to the threads signal frame. This includes some other minor signal fixes. Most of this was a joint effor between davidxu and myself. Reviewed by: davidxu Approved by: re@ (blanket for libpthread)
* Fix suspend and resume.deischen2003-05-041-6/+3
| | | | Submitted (in part) by: Kazuaki Oda <kaakun@highway.ne.jp>
* Create the thread signal lock as a KSE lock (as opposed todeischen2003-04-291-3/+3
| | | | | | | | | | | | a thread lock). Better protect access to thread state while searching for threads to handle a signal. Better protect access to process pending signals while processing a thread in sigwait(). Submitted by: davidxu
* Use the correct link entry for walking the list of threads.deischen2003-04-281-9/+2
| | | | | | | | While I'm here, use the TAILQ_FOREACH macro instead of a more manual method which was inherited from libc_r (so we could remove elements from the list which isn't needed for libpthread). Submitted by: Kazuaki Oda <kaakun@highway.ne.jp>
* Revamp libpthread so that it has a chance of working in an SMPdeischen2003-04-181-427/+553
| | | | | | | | | | | | | | | | | | | environment. This includes support for multiple KSEs and KSEGs. The ability to create more than 1 KSE via pthread_setconcurrency() is in the works as well as support for PTHREAD_SCOPE_SYSTEM threads. Those should come shortly. There are still some known issues which davidxu and I are working on, but it'll make it easier for us by committing what we have. This library now passes all of the ACE tests that libc_r passes with the exception of one. It also seems to work OK with KDE including konqueror, kwrite, etc. I haven't been able to get mozilla to run due to lack of java plugin, so I'd be interested to see how it works with that. Reviewed by: davidxu
* Insert threads interrupted by a signal while running onto the run queue.mini2003-02-231-24/+2
|
* Deliver signals posted via an upcall to the appropriate thread.mini2003-02-171-523/+202
|
* Make the changes needed for libpthread to compile in its new home.mini2002-09-161-1/+1
| | | | | | | | The new libpthread will provide POSIX threading support using KSE. These files were previously repo-copied from src/lib/libc_r. Reviewed by: deischen Approved by: -arch
* Remove much of the dereferencing of the fd table entries to lookdeischen2002-08-291-1/+1
| | | | | | | | | | | at file flags and replace it with functions that will avoid null pointer checks. MFC to be done by archie ;-) PR: 42100 Reviewed by: archie, robert MFC after: 3 days
* Revamp suspend and resume. While I'm here add pthread_suspend_all_np()deischen2002-05-241-4/+12
| | | | | | | | | | | | | and pthread_resume_all_np(). These suspend and resume all threads except the current thread, respectively. The existing functions pthread_single_np() and pthread_multi_np(), which formerly had no effect, now exhibit the same behaviour and pthread_suspend_all_np() and pthread_resume_all_np(). These functions have been added mostly for the native java port. Don't allow the uthread kernel pipe to use the same descriptors as stdio. Mostily submitted by Oswald Buddenhagen <ossi@kde.org>. Correct some minor style nits.
* This has been sitting in my local tree long enough. Remove the usedeischen2002-02-091-119/+103
| | | | | | | | | | | | | | of an alternate signal stack for handling signals. Let the kernel send signals on the stack of the current thread and teach the threads signal handler how to deliver signals to the current thread if it needs to. Also, always store a threads context as a jmp_buf. Eventually this will change to be a ucontext_t or mcontext_t. Other small nits. Use struct pthread * instead of pthread_t in internal library routines. The threads code wants struct pthread *, and pthread_t doesn't necessarily have to be the same. Reviewed by: jasone
* Fix pthread_join so that it works if the target thread exits whiledeischen2001-11-171-1/+11
| | | | | | | the joining thread is in a signal handler. Reported by: Loren James Rittle <rittle@labs.mot.com> MFC after: 1 week
* Clear the in thread scheduler flag after jumping to the start ofdeischen2001-06-291-0/+6
| | | | | | a signal handler from the scheduler. MFC after: 1 week
OpenPOWER on IntegriCloud