diff options
| author | David Xu <davidxu@FreeBSD.org> | 2003-08-10 22:20:41 +0000 |
|---|---|---|
| committer | David Xu <davidxu@FreeBSD.org> | 2003-08-10 22:20:41 +0000 |
| commit | 7292e8d1744d0d074d96ac83085dbaec3871e311 (patch) | |
| tree | de14605af1cfd189b4903e40961ad3e87a33c31e | |
| parent | 3fceb84efd0590af034c265e94e26da0e076b090 (diff) | |
Notes
| -rw-r--r-- | lib/libkse/thread/thr_fork.c | 23 | ||||
| -rw-r--r-- | lib/libpthread/thread/thr_fork.c | 23 |
2 files changed, 44 insertions, 2 deletions
diff --git a/lib/libkse/thread/thr_fork.c b/lib/libkse/thread/thr_fork.c index a2796214e748..6408fef6b28b 100644 --- a/lib/libkse/thread/thr_fork.c +++ b/lib/libkse/thread/thr_fork.c @@ -37,6 +37,7 @@ #include <unistd.h> #include <fcntl.h> #include <pthread.h> +#include <sys/signalvar.h> #include "thr_private.h" __weak_reference(_fork, fork); @@ -44,15 +45,35 @@ __weak_reference(_fork, fork); pid_t _fork(void) { + sigset_t sigset, oldset; struct pthread *curthread; pid_t ret; + if (!_kse_isthreaded()) + return (__sys_fork()); + curthread = _get_curthread(); + /* + * Masks all signals until we reach a safe point in + * _kse_single_thread, and the signal masks will be + * restored in that function, for M:N thread, all + * signals were already masked in kernel atomically, + * we only need to do this for bound thread. + */ + if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) { + SIGFILLSET(sigset); + __sys_sigprocmask(SIG_SETMASK, &sigset, &oldset); + } /* Fork a new process: */ - if ((ret = __sys_fork()) == 0) + if ((ret = __sys_fork()) == 0) { /* Child process */ _kse_single_thread(curthread); + /* Kernel signal mask is restored in _kse_single_thread */ + } else { + if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) + __sys_sigprocmask(SIG_SETMASK, &oldset, NULL); + } /* Return the process ID: */ return (ret); diff --git a/lib/libpthread/thread/thr_fork.c b/lib/libpthread/thread/thr_fork.c index a2796214e748..6408fef6b28b 100644 --- a/lib/libpthread/thread/thr_fork.c +++ b/lib/libpthread/thread/thr_fork.c @@ -37,6 +37,7 @@ #include <unistd.h> #include <fcntl.h> #include <pthread.h> +#include <sys/signalvar.h> #include "thr_private.h" __weak_reference(_fork, fork); @@ -44,15 +45,35 @@ __weak_reference(_fork, fork); pid_t _fork(void) { + sigset_t sigset, oldset; struct pthread *curthread; pid_t ret; + if (!_kse_isthreaded()) + return (__sys_fork()); + curthread = _get_curthread(); + /* + * Masks all signals until we reach a safe point in + * _kse_single_thread, and the signal masks will be + * restored in that function, for M:N thread, all + * signals were already masked in kernel atomically, + * we only need to do this for bound thread. + */ + if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) { + SIGFILLSET(sigset); + __sys_sigprocmask(SIG_SETMASK, &sigset, &oldset); + } /* Fork a new process: */ - if ((ret = __sys_fork()) == 0) + if ((ret = __sys_fork()) == 0) { /* Child process */ _kse_single_thread(curthread); + /* Kernel signal mask is restored in _kse_single_thread */ + } else { + if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) + __sys_sigprocmask(SIG_SETMASK, &oldset, NULL); + } /* Return the process ID: */ return (ret); |
