summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread
Commit message (Collapse)AuthorAgeFilesLines
* Correct the logic for checking the emptiness of the waiting queue.deischen2000-11-111-1/+1
| | | | | | | This fixes a potential problem where the file descriptors would not be polled causing waiting threads to stay waiting. Doh! MFC candidate.
* Don't needlessly poll file descriptors when there are nodeischen2000-11-0913-660/+594
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* At the beginning of pthread_mutex_lock(), call _thread_init() ifjdp2000-11-011-0/+3
| | | | | necessary. This works around a bug in old versions of libgcc_r.a which are statically linked into old executables.
* Make pthread_kill() know about temporary signal handlers installeddeischen2000-10-252-32/+124
| | | | | | | 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>
* Try and get libc_r to compile again on the alpha after deischen's commitpeter2000-10-171-3/+3
|
* #include <sys/types.h>brian2000-10-151-0/+2
|
* Implement zero system call thread switching. Performance ofdeischen2000-10-1324-1100/+1688
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | thread switches should be on par with that under scheduler activations. o Timing is achieved through the use of a fixed interval timer (ITIMER_PROF) to count scheduling ticks instead of retrieving the time-of-day upon every thread switch and calculating elapsed real time. o Polling for I/O readiness is performed once for each scheduling tick instead of every thread switch. o The non-signal saving/restoring versions of setjmp/longjmp are used to save and restore thread contexts. This may allow the removal of _THREAD_SAFE macros from setjmp() and longjmp() - needs more investigation. Change signal handling so that signals are handled in the context of the thread that is receiving the signal. When signals are dispatched to a thread, a special signal handling frame is created on top of the target threads stack. The frame contains the threads saved state information and a new context in which the thread can run. The applications signal handler is invoked through a wrapper routine that knows how to restore the threads saved state and unwind to previous frames. Fix interruption of threads due to signals. Some states were being improperly interrupted while other states were not being interrupted. This should fix several PRs. Signal handlers, which are invoked as a result of a process signal (not by pthread_kill()), are now called with the code (or siginfo_t if SA_SIGINFO was set in sa_flags) and sigcontext_t as received from the process signal handler. Modify the search for a thread to which a signal is delivered. The search algorithm is now: o First thread found in sigwait() with signal in wait mask. o First thread found sigsuspend()'d on the signal. o Current thread if signal is unmasked. o First thread found with signal unmasked. Collapse machine dependent support into macros defined in pthread_private.h. These should probably eventually be moved into separate MD files. Change the range of settable priorities to be compliant with POSIX (0-31). The threads library uses higher priorities internally for real-time threads (not yet implemented) and threads executing signal handlers. Real-time threads and threads running signal handlers add 64 and 32, respectively, to a threads base priority. Some other small changes and cleanups. PR: 17757 18559 21943 Reviewed by: jasone
* Add thread-safe wrapper for fpathconf(2) syscall.sobomax2000-09-192-0/+2
| | | | Reviewed by: jlemon
* The second call to _thread_kern_sig_defer() in sem_post() should be a calljasone2000-08-231-1/+1
| | | | to _thread_kern_sig_undefer().
* Fix an off-by-one error in the recursive mutex handling that made italfred2000-08-131-3/+3
| | | | | | | prematurely release recursive mutexes. Test case provided by: Bradley T. Hughes <bhughes@trolltech.com> Reviewed by: deischen
* Add wrapper for kevent() syscalljlemon2000-08-073-2/+3
| | | | Noted as missing by: nicolas.leonard@animaths.com
* Make sem_post() safe to call from within a signal handler, as required byjasone2000-08-011-0/+7
| | | | POSIX/SUSv2.
* Call _thread_init() from pthread_once() if it has not already been called.dfr2000-07-211-0/+2
| | | | | | | This fixes a segfault in some C++ programs which use exceptions before main() has been called (i.e. from global constructors). Reviewed by: deischen
* Change my email address in the copyright notices for the sake of consistencyjasone2000-07-1810-10/+10
| | | | (jasone@canonware.com --> jasone@freebsd.org).
* Deal correctly with statically initialized condition variables injasone2000-07-171-18/+17
| | | | | | | | | pthread_cond_signal(), pthread_cond_broadcast(), and pthread_cond_timedwait(). Do not dump core in pthread_cond_timedwait() (due to a NULL pointer dereference) if attempting to wait on an uninitialized condition variable. PR: bin/18099
* If multiple threads are blocked in sigwait() for the same signal that doesjasone2000-06-273-4/+37
| | | | | | | | | | | | | | | not have a user-supplied signal handler, when a signal is delivered, one thread will receive the signal, and then the code reverts to having no signal handler for the signal. This can leave the other sigwait()ing threads stranded permanently if the signal is later ignored, or can result in process termination when the process should have delivered the signal to one of the threads in sigwait(). To fix this problem, maintain a count of sigwait()ers for each signal that has no default signal handler. Use the count to correctly install/uninstall dummy signal handlers. Reviewed by: deischen
* pthread_mutex_lock(), pthread_cond_trywait(), and pthread_cond_wait() arejasone2000-06-146-36/+125
| | | | | | | | | | not allowed to return EINTR, but use of pthread_suspend_np() could cause EINTR to be returned. To fix this, restructure pthread_suspend_np() so that it does not interrupt a thread that is waiting on a mutex or condition, and keep enough state around that pthread_resume_np() can fix things up afterwards. Reviewed by: deischen
* Back out the previous change to the queue(3) interface.jake2000-05-261-20/+20
| | | | | | It was not discussed and should probably not happen. Requested by: msmith and others
* Change the way that the queue(3) structures are declared; don't assume thatjake2000-05-231-20/+20
| | | | | | | | the type argument to *_HEAD and *_ENTRY is a struct. Suggested by: phk Reviewed by: phk Approved by: mdodd
* Fix a memory leak. pthread_set_name_np() allocates space for a name, butjasone2000-05-161-2/+6
| | | | | | was not deallocating space for the previous name, if any. PR: misc/18504
* Fix a memory leak. pthread_set_name_np() allocates space for a name, butjasone2000-05-161-0/+4
| | | | | | _thread_gc() was not deallocating it. PR: misc/18504
* Fixed missing consts for function parameters, so that the code matchesbde2000-05-113-3/+6
| | | | | the man page and POSIX.1. Fixed nearby misformatting. Fixed a missing prototype.
* Add missing man pages. Fix various compliance bugs, mostly having to do withjasone2000-05-025-21/+34
| | | | | | error return values. Implement pthread_mutexattr_gettype(). PR: docs/16537, docs/17538
* Add a wrapper for the sendfile() system call.jasone2000-04-271-0/+1
| | | | PR: bin/17366
* Explicitly include sys/cdefs.h to get the definition of __strong_reference(),jasone2000-03-181-0/+1
| | | | rather than getting lucky due to header dependencies.
* Fix pthread_suspend_np/pthread_resume_np. For the record, suspending adeischen2000-03-159-31/+125
| | | | | | | | | | | | | | thread waiting on an event (I/O, condvar, etc) will, when resumed using pthread_resume_np, return with EINTR. For example, suspending and resuming a thread blocked on read() will not requeue the thread for the read, but will return -1 with errno = EINTR. If the suspended thread is in a critical region, the thread is suspended as soon as it leaves the critical region. Fix a bogon in pthread_kill() where a signal was being delivered twice to threads waiting in sigwait(). Reported by (suspend/resume bug): jdp Reviewed by: jasone
* For errors, return -1 and set errno to indicate the error type, rather thanjasone2000-02-161-16/+33
| | | | | | | | | returning the error directly. For sem_post(), make sure that the correct thread is woken up. This has unfortunate performance implications, but is necessary for POSIX compliance. Approved by: jkh
* Use __strong_reference() instead of __weak_reference() to assure that thejasone2000-01-2911-11/+11
| | | | weak symbols of the same name are not used.
* Use _fcntl() (not fcntl()) inside of fcntl().jasone2000-01-281-3/+3
| | | | Reported by: green
* Simplify sytem call renaming. Instead of _foo() <-- _libc_foo <-- foo(),jasone2000-01-2732-80/+570
| | | | | | | | | | | | | | | | | just use _foo() <-- foo(). In the case of a libpthread that doesn't do call conversion (such as linuxthreads and our upcoming libpthread), this is adequate. In the case of libc_r, we still need three names, which are now _thread_sys_foo() <-- _foo() <-- foo(). Convert all internal libc usage of: aio_suspend(), close(), fsync(), msync(), nanosleep(), open(), fcntl(), read(), and write() to _foo() instead of foo(). Remove all internal libc usage of: creat(), pause(), sleep(), system(), tcdrain(), wait(), and waitpid(). Make thread cancellation fully POSIX-compliant. Suggested by: deischen
* Fix millisecond to nanosecond conversion.jasone2000-01-221-1/+1
| | | | PR: misc/16245
* Minor *jmp() cleanups.jasone2000-01-201-2/+3
|
* Add sem_*() functions. Named semaphores and process-shared semaphoresjasone2000-01-203-0/+237
| | | | | | | are not supported by this implementation, and the error return values from sem_init(), sem_open(), sem_close(), and sem_unlink() reflect this. Approved by: jkh
* Do signal deferral for pthread_kill() as it was done in the old days.jasone2000-01-203-30/+6
| | | | Submitted by: deischen
* Implement continuations to correctly handle [sig|_]longjmp() inside of ajasone2000-01-1912-61/+374
| | | | | | | | | | | | | | | | | | | | | | signal handler. Explicitly check for jumps to anywhere other than the current stack, since such jumps are undefined according to POSIX. While we're at it, convert thread cancellation to use continuations, since it's cleaner than the original cancellation code. Avoid delivering a signal to a thread twice. This was a pre-existing bug, but was likely unexposed until these other changes were made. Defer signals generated by pthread_kill() so that they can be delivered on the appropriate stack. deischen claims that this is unnecessary, which is likely true, but without this change, pthread_kill() can cause undefined priority queue states and/or PANICs in [sig|_]longjmp(), so I'm leaving this in for now. To compile this code out and exercise the bug, define the _NO_UNDISPATCH cpp macro. Defining _PTHREADS_INVARIANTS as well will cause earlier crashes. PR: kern/14685 Collaboration with: deischen
* Properly initialize the last active time of the initial thread. This fixesdeischen2000-01-181-0/+6
| | | | | | | the case that a CPU hungry main thread is prevented from being preempted due to a negative calculation of its time slice. Reported by: Alexander Litvin <archer@lucky.net>
* Track libc's three-tier symbol naming. libc_r must currently implementjasone2000-01-1226-32/+75
| | | | | the _libc_*() entry points and add *() weak aliases. This will all change for the better when libc_r becomes libpthread.
* Make sched_param parameter a const to comply with POSIX and SUSv2 specs.deischen2000-01-101-1/+1
| | | | | | | This doesn't need to be applied to stable, because somehow -stable seems to have gotten it right. Reviewed by: jasone
* Don't explicitly mmap() red zones at the bottom of thread stacks (exceptjasone1999-12-293-16/+26
| | | | | | | | | | the initial thread). Instead, just leave an unmapped gap between thread stacks and make sure that the thread stacks won't grow into these gaps, simply by limiting the size of the stacks with the 'len' argument to mmap(). This (if I understand correctly) reduces VM overhead considerably. Reviewed by: deischen
* -Wall and minor style(9) cleanups.deischen1999-12-287-16/+14
|
* Change stack allocation algorithm to make better use of memorydeischen1999-12-282-22/+20
| | | | | (it was leaving an unused block). Also protect the global stack pointer from context changes while fiddling with it.
* Don't wakeup threads when there is a process signal and no installeddeischen1999-12-281-23/+37
| | | | | | | | handler. Thread-to-thread signals (pthread_signal) are treated differently than process signals; a pthread_signal can wakeup a blocked thread if a signal handler is not installed for that signal. Found by: ACE tests
* Fix some minor POSIX/SUSv2 compliance nits.jasone1999-12-181-7/+4
| | | | PR: kern/11982
* Fix problems with cancellation while in critical regions.deischen1999-12-176-8/+21
| | | | | | | | | | | o Cancellation flags were not getting properly set/cleared. o Loops waiting for internal locks were not being exited correctly by a cancelled thread. o Minor spelling (cancelation -> cancellation) and formatting corrections (missing tab). Found by: tg Reviewed by: jasone
* Fixes for signal handling:deischen1999-12-175-147/+208
| | | | | | | | | | | | | | o Don't call signal handlers with the signal handler access lock held. o Remove pending signals before calling signal handlers. If pending signals were not removed prior to handling them, invocation of the handler could cause the handler to be called more than once for the same signal. Found by: JB o When SIGCHLD arrives, wake up all threads in PS_WAIT_WAIT (wait4). PR: bin/15328 Reviewed by: jasone
* Avoid an infinite loop if the last element of the iov array passed tojasone1999-12-161-1/+13
| | | | | | writev() has an iov_len of 0. PR: bin/8281
* Change signal handling to conform to POSIX specified semantics.deischen1999-12-044-27/+79
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this change, a signal was delivered to each thread that didn't have the signal masked. Signals also improperly woke up threads waiting on I/O. With this change, signals are now handled in the following way: o If a thread is waiting in a sigwait for the signal, then the thread is woken up. o If no threads are sigwait'ing on the signal and a thread is in a sigsuspend waiting for the signal, then the thread is woken up. o In the case that no threads are waiting or suspended on the signal, then the signal is delivered to the first thread we find that has the signal unmasked. o If no threads are waiting or suspended on the signal, and no threads have the signal unmasked, then the signal is added to the process wide pending signal set. The signal will be delivered to the first thread that unmasks the signal. If there is an installed signal handler, it is only invoked if the chosen thread was not in a sigwait. In the case that multiple threads are waiting or suspended on a signal, or multiple threads have the signal unmasked, we wake up/deliver the signal to the first thread we find. The above rules still apply. Reported by: Scott Hess <scott@avantgo.com> Reviewed by: jb, jasone
* * Fix the stack allocation code so that it works for alpha. Change itdfr1999-11-282-6/+26
| | | | | | | | | to use mmap(..., MAP_STACK, ...) on alpha too since that should work now. * Add hooks to allow GDB to access the internals of pthreads without having to know the exact layout of struct pthread. Reviewed by: deischen
* add pthread_cancel, obtained from OpenBSD.alfred1999-11-2826-69/+501
| | | | | | | | | | | | | | eischen (Daniel Eischen) added wrappers to protect against cancled threads orphaning internal resources. the cancelability code is still a bit fuzzy but works for test programs of my own, OpenBSD's and some examples from ORA's books. add readdir_r to both libc and libc_r add some 'const' attributes to function parameters Reviewed by: eischen, jasone
OpenPOWER on IntegriCloud