diff options
author | davidxu <davidxu@FreeBSD.org> | 2008-03-18 02:06:51 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2008-03-18 02:06:51 +0000 |
commit | 9dbfb036ab5c3c3ecedf1ba5ad7e5904492b6f49 (patch) | |
tree | 0f199def54ed0bbe7382f19b627a69e5a17b5e54 | |
parent | 965a19847a23893c3eed9b5702a142e657fc79b3 (diff) | |
download | FreeBSD-src-9dbfb036ab5c3c3ecedf1ba5ad7e5904492b6f49.zip FreeBSD-src-9dbfb036ab5c3c3ecedf1ba5ad7e5904492b6f49.tar.gz |
- Copy signal mask out before THR_UNLOCK(), because THR_UNLOCK() may call
_thr_suspend_check() which messes sigmask saved in thread structure.
- Don't suspend a thread has force_exit set.
- In pthread_exit(), if there is a suspension flag set, wake up waiting-
thread after setting PS_DEAD, this causes waiting-thread to break loop
in suspend_common().
-rw-r--r-- | lib/libthr/thread/thr_create.c | 14 | ||||
-rw-r--r-- | lib/libthr/thread/thr_exit.c | 4 | ||||
-rw-r--r-- | lib/libthr/thread/thr_sig.c | 3 |
3 files changed, 17 insertions, 4 deletions
diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c index 6eb3693..c7953c6 100644 --- a/lib/libthr/thread/thr_create.c +++ b/lib/libthr/thread/thr_create.c @@ -247,6 +247,11 @@ create_stack(struct pthread_attr *pattr) static void thread_start(struct pthread *curthread) { + sigset_t set; + + if (curthread->attr.suspend == THR_CREATE_SUSPENDED) + set = curthread->sigmask; + /* * This is used as a serialization point to allow parent * to report 'new thread' event to debugger or tweak new thread's @@ -263,19 +268,20 @@ thread_start(struct pthread *curthread) SIGEMPTYSET(set); SIGADDSET(set, SIGCANCEL); - sigprocmask(SIG_UNBLOCK, &set, NULL); + __sys_sigprocmask(SIG_UNBLOCK, &set, NULL); } if (curthread->attr.suspend == THR_CREATE_SUSPENDED) { - sigset_t set = curthread->sigmask; - +#if 0 + /* Done in THR_UNLOCK() */ _thr_ast(curthread); +#endif /* * Parent thread have stored signal mask for us, * we should restore it now. */ - sigprocmask(SIG_SETMASK, &set, NULL); + __sys_sigprocmask(SIG_SETMASK, &set, NULL); } /* Run the current thread's start routine with argument: */ diff --git a/lib/libthr/thread/thr_exit.c b/lib/libthr/thread/thr_exit.c index 7d902ca..c636693 100644 --- a/lib/libthr/thread/thr_exit.c +++ b/lib/libthr/thread/thr_exit.c @@ -121,6 +121,10 @@ _pthread_exit(void *status) } THR_LOCK(curthread); curthread->state = PS_DEAD; + if (curthread->flags & THR_FLAGS_NEED_SUSPEND) { + curthread->cycle++; + _thr_umtx_wake(&curthread->cycle, INT_MAX); + } THR_UNLOCK(curthread); /* * Thread was created with initial refcount 1, we drop the diff --git a/lib/libthr/thread/thr_sig.c b/lib/libthr/thread/thr_sig.c index 5d89d7f..fe1555a 100644 --- a/lib/libthr/thread/thr_sig.c +++ b/lib/libthr/thread/thr_sig.c @@ -92,6 +92,9 @@ _thr_suspend_check(struct pthread *curthread) long cycle; int err; + if (curthread->force_exit) + return; + err = errno; /* * Blocks SIGCANCEL which other threads must send. |