summaryrefslogtreecommitdiffstats
path: root/lib/libthr/thread/thr_syscalls.c
diff options
context:
space:
mode:
authormtm <mtm@FreeBSD.org>2004-05-20 12:06:16 +0000
committermtm <mtm@FreeBSD.org>2004-05-20 12:06:16 +0000
commitd835c0621f34028252fad957e6061920d493021d (patch)
tree191973c93de49160bb4144ea98ee350f5906d883 /lib/libthr/thread/thr_syscalls.c
parent2b949599bf280f4ce2bc5250ba241e9ee64bed2b (diff)
downloadFreeBSD-src-d835c0621f34028252fad957e6061920d493021d.zip
FreeBSD-src-d835c0621f34028252fad957e6061920d493021d.tar.gz
Make libthr async-signal-safe without costly signal masking. The guidlines I
followed are: Only 3 functions (pthread_cancel, pthread_setcancelstate, pthread_setcanceltype) are required to be async-signal-safe by POSIX. None of the rest of the pthread api is required to be async-signal-safe. This means that only the three mentioned functions are safe to use from inside signal handlers. However, there are certain system/libc calls that are cancellation points that a caller may call from within a signal handler, and since they are cancellation points calls have to be made into libthr to test for cancellation and exit the thread if necessary. So, the cancellation test and thread exit code paths must be async-signal-safe as well. A summary of the changes follows: o Almost all of the code paths that masked signals, as well as locking the pthread structure now lock only the pthread structure. o Signals are masked (and left that way) as soon as a thread enters pthread_exit(). o The active and dead threads locks now explicitly require that signals are masked. o Access to the isdead field of the pthread structure is protected by both the active and dead list locks for writing. Either one is sufficient for reading. o The thread state and type fields have been combined into one three-state switch to make it easier to read without requiring a lock. It doesn't need a lock for writing (and therefore for reading either) because only the current thread can write to it and it is an integer value. o The thread state field of the pthread structure has been eliminated. It was an unnecessary field that mostly duplicated the flags field, but required additional locking that would make a lot more code paths require signal masking. Any truly unique values (such as PS_DEAD) have been reborn as separate members of the pthread structure. o Since the mutex and condvar pthread functions are not async-signal-safe there is no need to muck about with the wait queues when handling a signal ... o ... which also removes the need for wrapping signal handlers and sigaction(2). o The condvar and mutex async-cancellation code had to be revised as a result of some of these changes, which resulted in semi-unrelated changes which would have been difficult to work on as a separate commit, so they are included as well. The only part of the changes I am worried about is related to locking for the pthread joining fields. But, I will take a closer look at them once this mega-patch is committed.
Diffstat (limited to 'lib/libthr/thread/thr_syscalls.c')
-rw-r--r--lib/libthr/thread/thr_syscalls.c55
1 files changed, 0 insertions, 55 deletions
diff --git a/lib/libthr/thread/thr_syscalls.c b/lib/libthr/thread/thr_syscalls.c
index 2d83ab5..f0867d1 100644
--- a/lib/libthr/thread/thr_syscalls.c
+++ b/lib/libthr/thread/thr_syscalls.c
@@ -330,61 +330,6 @@ _select(int numfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
return ret;
}
-__weak_reference(_sigaction, sigaction);
-
-int
-_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
-{
- struct sigaction *tmpact;
- struct sigaction oldact, wrapperact;
- int error;
-
- /* Detect invalid signals. */
- if (sig < 1 || sig > NSIG) {
- errno = EINVAL;
- return (-1);
- }
-
- /*
- * If act is not NULL the library's signal wrapper is passed into the
- * kernel only if the action is not SIG_DFL or SIG_IGN.
- * On the other hand if act is NULL the caller only wants
- * the old value so there is no need to call into the kernel.
- */
- error = 0;
- tmpact = NULL;
- proc_sigact_copyout(sig, &oldact);
- if (act != NULL) {
- proc_sigact_copyin(sig, act);
- tmpact = proc_sigact_sigaction(sig);
- if (tmpact->sa_handler != SIG_DFL &&
- tmpact->sa_handler != SIG_IGN) {
- bcopy((const void *)tmpact, (void *)&wrapperact,
- sizeof(struct sigaction));
- wrapperact.sa_flags |= SA_SIGINFO;
- wrapperact.sa_sigaction = &_thread_sig_wrapper;
- tmpact = &wrapperact;
- }
- error = __sys_sigaction(sig, tmpact, NULL);
- }
- if (error == 0) {
-
- /* If successful, return the old sigaction to the user */
- if (oact != NULL )
- bcopy((const void *)&oldact, (void *)oact,
- sizeof(struct sigaction));
- } else {
-
- /*
- * The only time error is non-zero is if the syscall failed,
- * which means the sigaction in the process global list
- * was altered before the syscall. Return it to it's old value.
- */
- proc_sigact_copyin(sig, &oldact);
- }
- return (error);
-}
-
__weak_reference(_sleep, sleep);
unsigned int
OpenPOWER on IntegriCloud