aboutsummaryrefslogtreecommitdiff
path: root/lib/libkse/thread/thr_sig.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove the libkse directory. It was unhooked from the build and kernelBrooks Davis2014-04-161-1255/+0
| | | | | | | | | | support removed in 2008 (prior to 8.0). Approved by: deischen, imp MFC after: 3 days Notes: svn path=/head/; revision=264543
* Fix some "in in" typos in comments.Christian Brueffer2008-03-261-1/+1
| | | | | | | | | | PR: 121490 Submitted by: Anatoly Borodin <anatoly.borodin@gmail.com> Approved by: rwatson (mentor), jkoshy MFC after: 3 days Notes: svn path=/head/; revision=177626
* WARNS=3'ify.Daniel Eischen2007-11-301-9/+14
| | | | Notes: svn path=/head/; revision=174112
* Remove 3rd clause, renumber, ok per emailWarner Losh2007-01-121-4/+1
| | | | Notes: svn path=/head/; revision=165967
* o Remove a cruft prevented libpthread sigaction(2) wrapper toMaxim Konovalov2006-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 Notes: svn path=/head/; revision=159462
* Only catch SIGINFO (for dumping thread states) when LIBPTHREAD_DEBUGDaniel Eischen2006-03-061-16/+25
| | | | | | | | | is defined in the environment. Requested by: jmg & a few others Notes: svn path=/head/; revision=156330
* Use a generic way to back threads out of wait queues when handlingDaniel Eischen2004-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 Notes: svn path=/head/; revision=139023
* Save cancelflags in signal frame, this fixes a problem thatDavid Xu2004-11-011-0/+2
| | | | | | | | | | a thread in pthread_cond_wait handled a signal can no longer be canceled. Reviewed by: deischen Notes: svn path=/head/; revision=137105
* 1. Move thread list flags into new separate member, and atomicallyDavid Xu2004-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 Notes: svn path=/head/; revision=136846
* Decrease reference count if we won't use the thread, this avoids memoryDavid Xu2004-10-211-0/+4
| | | | | | | leak under some cases. Notes: svn path=/head/; revision=136735
* Let debugger check signal, make SIGINFO works.David Xu2004-07-131-12/+25
| | | | Notes: svn path=/head/; revision=132122
* Check pending signals, if there is signal will be unblocked byDavid Xu2004-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> Notes: svn path=/head/; revision=130374
* Kernel now supports per-thread sigaltstack, follow the change toDavid Xu2004-01-031-6/+1
| | | | | | | enable sigaltstack for scope system thread. Notes: svn path=/head/; revision=124095
* Fix a typo.David Xu2004-01-021-1/+1
| | | | Notes: svn path=/head/; revision=124055
* Implement sigaltstack() as per-threaded. Current only scope process threadDavid Xu2003-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 Notes: svn path=/head/; revision=123974
* Correctly retrieve sigaction flags.David Xu2003-12-281-2/+2
| | | | Notes: svn path=/head/; revision=123933
* Save and restore timeout field for signal frame just like what we didDavid Xu2003-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. Notes: svn path=/head/; revision=120338
* Fix bogus comment and assign sigmask in critical region, useDavid Xu2003-09-151-2/+4
| | | | | | | SIG_CANTMASK to remove unmaskable signal masks. Notes: svn path=/head/; revision=120079
* When invoking an old style signal handler, use true traditional BSD style toDavid Xu2003-09-141-6/+13
| | | | | | | | | invoke signal handler. Reviewed by: deischen Notes: svn path=/head/; revision=120073
* Repost masked signal to kernel for scope system thread, it hardly happensDavid Xu2003-08-211-6/+25
| | | | | | | | | in real world. Reviewed by: deischen Notes: svn path=/head/; revision=119249
* _thr_sig_check_pending is also called by scope system thread when it leavesDavid Xu2003-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. Notes: svn path=/head/; revision=119177
* Treat initial thread as scope system thread when KSE mode is not activatedDavid Xu2003-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 Notes: svn path=/head/; revision=119063
* Add some quick pathes to exit process when signal action is default andDavid Xu2003-08-101-0/+21
| | | | | | | | | signal can causes process to exit. Reviewed by: deischen Notes: svn path=/head/; revision=118748
* Initialize rtld lock just before turning on thread mode andDavid Xu2003-08-101-14/+4
| | | | | | | uninitialize rtld lock after thread mode shutdown. Notes: svn path=/head/; revision=118747
* Rethink the MD interfaces for libpthread to account forDaniel Eischen2003-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 Notes: svn path=/head/; revision=118510
* Simplify sigwait code a bit by using a waitset and removing oldsigmask.David Xu2003-07-271-15/+7
| | | | | | | Reviewed by: deischen Notes: svn path=/head/; revision=118075
* Move idle kse wakeup to outside of regions where locks are held.Daniel Eischen2003-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 Notes: svn path=/head/; revision=117907
* o Eliminate upcall for PTHREAD_SYSTEM_SCOPE thread, now itDavid Xu2003-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 Notes: svn path=/head/; revision=117706
* Don't resume sigwait thread If signal is masked.David Xu2003-07-091-8/+12
| | | | Notes: svn path=/head/; revision=117366
* POSIX says if a thread is in sigwait state, although a signal may not inDavid Xu2003-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. Notes: svn path=/head/; revision=117353
* Restore signal mask correctly after fork().David Xu2003-07-091-3/+4
| | | | Notes: svn path=/head/; revision=117345
* Add a newline to debug message.David Xu2003-07-071-1/+1
| | | | Notes: svn path=/head/; revision=117301
* Because there are only _SIG_MAXSIG elements in thread siginfo array,David Xu2003-06-301-14/+14
| | | | | | | use [signal number - 1] as subscript to access the array. Notes: svn path=/head/; revision=117066
* o Use a daemon thread to monitor signal events in kernel, if pendingDavid Xu2003-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(). Notes: svn path=/head/; revision=116977
* Explicitly widen int types before casting to pointer types. On 64-bitMarcel Moolenaar2003-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 Notes: svn path=/head/; revision=116773
* After selecting a thread to handle a signal and takingDaniel Eischen2003-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. Notes: svn path=/head/; revision=116061
* Save THR_FLAGS_IN_TDLIST in signal frame, otherwise if a thread receivedDavid Xu2003-05-301-1/+2
| | | | | | | | | | a signal will can not be removed from thread list after it exited. Reviewed by: deischen Approved by: re (jhb) Notes: svn path=/head/; revision=115413
* Don't really spin on a spinlock; silently convert it to the sameDaniel Eischen2003-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) Notes: svn path=/head/; revision=115381
* Change low-level locking a bit so that we can tell ifDaniel Eischen2003-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) Notes: svn path=/head/; revision=115278
* Add a method of yielding the current thread with the schedulerDaniel Eischen2003-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) Notes: svn path=/head/; revision=115080
* Fix suspend and resume.Daniel Eischen2003-05-041-6/+3
| | | | | | | Submitted (in part) by: Kazuaki Oda <kaakun@highway.ne.jp> Notes: svn path=/head/; revision=114664
* Create the thread signal lock as a KSE lock (as opposed toDaniel Eischen2003-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 Notes: svn path=/head/; revision=114254
* Use the correct link entry for walking the list of threads.Daniel Eischen2003-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> Notes: svn path=/head/; revision=114180
* Revamp libpthread so that it has a chance of working in an SMPDaniel Eischen2003-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 Notes: svn path=/head/; revision=113658
* Insert threads interrupted by a signal while running onto the run queue.Jonathan Mini2003-02-231-24/+2
| | | | Notes: svn path=/head/; revision=111360
* Deliver signals posted via an upcall to the appropriate thread.Jonathan Mini2003-02-171-523/+202
| | | | Notes: svn path=/head/; revision=111035
* Make the changes needed for libpthread to compile in its new home.Jonathan 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 Notes: svn path=/head/; revision=103388
* Remove much of the dereferencing of the fd table entries to lookDaniel Eischen2002-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 Notes: svn path=/head/; revision=102590
* Revamp suspend and resume. While I'm here add pthread_suspend_all_np()Daniel Eischen2002-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. Notes: svn path=/head/; revision=97204
* This has been sitting in my local tree long enough. Remove the useDaniel Eischen2002-02-091-118/+102
| | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=90431