summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_sig.c
Commit message (Collapse)AuthorAgeFilesLines
* 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
* Instead of using a join queue for each thread, use a single pointer tojasone2001-05-201-9/+1
| | | | | | | | | | | keep track of a joiner. POSIX only supports a single joiner, so this simplification is acceptable. At the same time, make sure to mark a joined thread as detached so that its resources can be freed. Reviewed by: deischen PR: 24345
* Move the check for a pending signals to after the thread has beendeischen2001-05-041-0/+3
| | | | | | | | | | | | | | | placed in any scheduling queue(s). The process of dispatching signals to a thread can change its state which will attempt to add or remove the thread from any scheduling queue to which it belongs. This can break some assertions if the thread isn't in the queue(s) implied by its state. When adding dispatching a pending signal to a thread, be sure to remove the signal from the threads set of pending signals. PR: 27035 Tested by: brian MFC in: 1 week
* Correct a race condition where it was possible for a signaleddeischen2001-03-091-2/+8
| | | | | | | | thread to become stranded and not placed in the run queue. MFC Candidate Reported by: tegge
* Remove (int) file descriptor locking. It should be up to thedeischen2001-02-111-5/+0
| | | | | | | | | | | | | application to provide locking for I/O operations. This doesn't break any of my tests, but the old behavior can be restored by compiling with _FDLOCKS_ENABLED. This will eventually be removed when it is obvious it does not cause any problems. Remove most of flockfile implementation, with the exception of flockfile_debug. Make error messages more informational (submitted by Mike Heffner <spock@techfour.net>, who's now known as mikeh@FreeBSD.org).
* Add weak definitions for wrapped system calls. In general:deischen2001-01-241-20/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | _foo - wrapped system call foo - weak definition to _foo and for cancellation points: _foo - wrapped system call __foo - enter cancellation point, call _foo(), leave cancellation point foo - weak definition to __foo Change use of global _thread_run to call a function to get the currently running thread. Make all pthread_foo functions weak definitions to _pthread_foo, where _pthread_foo is the implementation. This allows an application to provide its own pthread functions. Provide slightly different versions of pthread_mutex_lock and pthread_mutex_init so that we can tell the difference between a libc mutex and an application mutex. Threads holding mutexes internal to libc should never be allowed to exit, call signal handlers, or cancel. Approved by: -arch
* Change a "while {}" loop to a "do {} while" to allow it to bedeischen2000-11-201-0/+4
| | | | | | | | | | | | | executed at least once, fixing pthread_mutex_lock() for recursive mutex lock attempts. Correctly set a threads signal mask while it is executing a signal handler. The mask should be the union of its current mask, the signal being handled, and the mask from the signal action. Reported by: Dan Nelson <dnelson@emsphone.com> MFC Candidate
* When entering the scheduler from the signal handler, telldeischen2000-11-141-1/+1
| | | | | | | | | | | the kernel to (re)use the alternate signal stack. In this case, we don't return normally from the signal handler, so the kernel still thinks we are using the signal stack. The fixes a nasty bug where the signal handler can start fiddling with the stack of a thread while the handler is actually running on the same stack. MFC candidate
* Don't needlessly poll file descriptors when there are nodeischen2000-11-091-297/+146
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | file descriptors needing to be polled (Doh!). Reported by Dan Nelson <dnelson@emsphone.com>. Don't install and start the scheduling timer until the first thread is created. This prevents the overhead of having a periodic scheduling signal in a single threaded program. Reported by Dan Nelson <dnelson@emsphone.com>. Allow builtin longjmps out of application installed signal handlers without the need perform any post-handler cleanup: o Change signal handling to save the threads interrupted context on the stack. The threads current context is now always stored in the same place (in the pthread). If and when a signal handler returns, the interrupted context is copied back to the storage area in the pthread. o Before calling invoking a signal handler for a thread, back the thread out of any internal waiting queues (mutex, CV, join, etc) to which it belongs. Rework uthread_info.c a bit to make it easier to change the format of a thread dump. Use an alternal signal stack for the thread library's signal handler. This allows us to fiddle with the main threads stack without fear of it being in use. Reviewed by: jasone
* Make pthread_kill() know about temporary signal handlers installeddeischen2000-10-251-29/+119
| | | | | | | by sigwait(). This prevents a signal from being sent to the process when there are no application installed signal handlers. Correct a typo in sigwait (foo -> foo[i]).
* We use ___setjmp (non-signal saving) to setup a signal frame. Whendeischen2000-10-221-1/+1
| | | | | | | adding a signal frame to a thread, be sure to label the context correctly so we don't restore an uninitialized process mask. Reported by: kimc@W8HD.ORG and Andrey Rouskol <anry@sovintel.ru>
OpenPOWER on IntegriCloud