summaryrefslogtreecommitdiff
path: root/lib/libthr/thread/thr_fork.c
diff options
context:
space:
mode:
authorDavid Xu <davidxu@FreeBSD.org>2006-01-16 05:36:30 +0000
committerDavid Xu <davidxu@FreeBSD.org>2006-01-16 05:36:30 +0000
commitaea0220d8f0ff2bbc914a58f79a2c9051dd110d6 (patch)
tree0ca1bc721cb2b3021e8c9b39c334f56145c84592 /lib/libthr/thread/thr_fork.c
parentf270dd260b022d3f4a5e44548c69a374a86e1cb5 (diff)
Notes
Diffstat (limited to 'lib/libthr/thread/thr_fork.c')
-rw-r--r--lib/libthr/thread/thr_fork.c38
1 files changed, 8 insertions, 30 deletions
diff --git a/lib/libthr/thread/thr_fork.c b/lib/libthr/thread/thr_fork.c
index 8b311cb81e61..4c222d9fdffd 100644
--- a/lib/libthr/thread/thr_fork.c
+++ b/lib/libthr/thread/thr_fork.c
@@ -105,10 +105,6 @@ __weak_reference(_fork, fork);
pid_t
_fork(void)
{
- static umtx_t inprogress;
- static int waiters;
- umtx_t tmp;
-
struct pthread *curthread;
struct pthread_atfork *af;
pid_t ret;
@@ -120,25 +116,7 @@ _fork(void)
curthread = _get_curthread();
- /*
- * Block all signals until we reach a safe point.
- */
- _thr_signal_block(curthread);
-
THR_UMTX_LOCK(curthread, &_thr_atfork_lock);
- tmp = inprogress;
- while (tmp) {
- waiters++;
- THR_UMTX_UNLOCK(curthread, &_thr_atfork_lock);
- _thr_umtx_wait(&inprogress, tmp, NULL);
- THR_UMTX_LOCK(curthread, &_thr_atfork_lock);
- waiters--;
- tmp = inprogress;
- }
- inprogress = 1;
-
- /* Unlock mutex, allow new hook to be added during executing hooks. */
- THR_UMTX_UNLOCK(curthread, &_thr_atfork_lock);
/* Run down atfork prepare handlers. */
TAILQ_FOREACH_REVERSE(af, &_thr_atfork_list, atfork_head, qe) {
@@ -158,11 +136,15 @@ _fork(void)
unlock_malloc = 0;
}
+ /*
+ * Block all signals until we reach a safe point.
+ */
+ _thr_signal_block(curthread);
+
/* Fork a new process: */
if ((ret = __sys_fork()) == 0) {
/* Child process */
errsave = errno;
- inprogress = 0;
curthread->cancelflags &= ~THR_CANCEL_NEEDED;
/*
* Thread list will be reinitialized, and later we call
@@ -197,22 +179,18 @@ _fork(void)
/* Parent process */
errsave = errno;
- if (unlock_malloc)
- _spinunlock(__malloc_lock);
-
/* Ready to continue, unblock signals. */
_thr_signal_unblock(curthread);
+ if (unlock_malloc)
+ _spinunlock(__malloc_lock);
+
/* Run down atfork parent handlers. */
TAILQ_FOREACH(af, &_thr_atfork_list, qe) {
if (af->parent != NULL)
af->parent();
}
- THR_UMTX_LOCK(curthread, &_thr_atfork_lock);
- inprogress = 0;
- if (waiters)
- _thr_umtx_wake(&inprogress, waiters);
THR_UMTX_UNLOCK(curthread, &_thr_atfork_lock);
}
errno = errsave;