diff options
author | deischen <deischen@FreeBSD.org> | 2003-04-29 21:03:33 +0000 |
---|---|---|
committer | deischen <deischen@FreeBSD.org> | 2003-04-29 21:03:33 +0000 |
commit | 6bd4376dc86f246ff07451d32eeeab0742747649 (patch) | |
tree | 91af310836f600ff861fcc771d66919156ee5215 /lib/libkse/thread | |
parent | eeceed0838e543d6948276df87b878354ca10adb (diff) | |
download | FreeBSD-src-6bd4376dc86f246ff07451d32eeeab0742747649.zip FreeBSD-src-6bd4376dc86f246ff07451d32eeeab0742747649.tar.gz |
Create the thread signal lock as a KSE lock (as opposed to
a thread lock).
Better protect access to thread state while searching for
threads to handle a signal.
Better protect access to process pending signals while processing
a thread in sigwait().
Submitted by: davidxu
Diffstat (limited to 'lib/libkse/thread')
-rw-r--r-- | lib/libkse/thread/thr_init.c | 2 | ||||
-rw-r--r-- | lib/libkse/thread/thr_sig.c | 6 | ||||
-rw-r--r-- | lib/libkse/thread/thr_sigwait.c | 37 |
3 files changed, 23 insertions, 22 deletions
diff --git a/lib/libkse/thread/thr_init.c b/lib/libkse/thread/thr_init.c index 804462c..d43adf5 100644 --- a/lib/libkse/thread/thr_init.c +++ b/lib/libkse/thread/thr_init.c @@ -499,7 +499,7 @@ init_private(void) * process signal mask and pending signal sets. */ if (_lock_init(&_thread_signal_lock, LCK_ADAPTIVE, - _thr_lock_wait, _thr_lock_wakeup) != 0) + _kse_lock_wait, _kse_lock_wakeup) != 0) PANIC("Cannot initialize _thread_signal_lock"); if (_lock_init(&_mutex_static_lock, LCK_ADAPTIVE, _thr_lock_wait, _thr_lock_wakeup) != 0) diff --git a/lib/libkse/thread/thr_sig.c b/lib/libkse/thread/thr_sig.c index 5ac4998..cd699db 100644 --- a/lib/libkse/thread/thr_sig.c +++ b/lib/libkse/thread/thr_sig.c @@ -286,11 +286,10 @@ thr_sig_find(struct kse *curkse, int sig, siginfo_t *info) KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock); TAILQ_FOREACH(pthread, &_thread_list, tle) { + /* Take the scheduling lock. */ + KSE_SCHED_LOCK(curkse, pthread->kseg); if ((pthread->state == PS_SIGWAIT) && sigismember(pthread->data.sigwait, sig)) { - /* Take the scheduling lock. */ - KSE_SCHED_LOCK(curkse, pthread->kseg); - /* * Return the signal number and make the * thread runnable. @@ -328,6 +327,7 @@ thr_sig_find(struct kse *curkse, int sig, siginfo_t *info) } else if (signaled_thread == NULL) signaled_thread = pthread; } + KSE_SCHED_UNLOCK(curkse, pthread->kseg); } KSE_LOCK_RELEASE(curkse, &_thread_list_lock); diff --git a/lib/libkse/thread/thr_sigwait.c b/lib/libkse/thread/thr_sigwait.c index 7b5a31f..9bb4285 100644 --- a/lib/libkse/thread/thr_sigwait.c +++ b/lib/libkse/thread/thr_sigwait.c @@ -49,7 +49,8 @@ _sigwait(const sigset_t *set, int *sig) int i; sigset_t tempset, waitset; struct sigaction act; - + kse_critical_t crit; + _thr_enter_cancellation_point(curthread); /* @@ -71,8 +72,11 @@ _sigwait(const sigset_t *set, int *sig) /* * Check to see if a pending signal is in the wait mask. - * This has to be atomic. */ + * This has to be atomic. + */ tempset = curthread->sigpend; + crit = _kse_critical_enter(); + KSE_LOCK_ACQUIRE(curthread->kse, &_thread_signal_lock); SIGSETOR(tempset, _thr_proc_sigpending); SIGSETAND(tempset, waitset); if (SIGNOTEMPTY(tempset)) { @@ -83,24 +87,20 @@ _sigwait(const sigset_t *set, int *sig) } /* Clear the pending signal: */ - if (sigismember(&curthread->sigpend,i)) - sigdelset(&curthread->sigpend,i); + if (sigismember(&curthread->sigpend, i)) + sigdelset(&curthread->sigpend, i); else - sigdelset(&_thr_proc_sigpending,i); + sigdelset(&_thr_proc_sigpending, i); + KSE_LOCK_RELEASE(curthread->kse, &_thread_signal_lock); + _kse_critical_leave(crit); + _thr_leave_cancellation_point(curthread); /* Return the signal number to the caller: */ *sig = i; - - _thr_leave_cancellation_point(curthread); return (0); } /* - * Lock the array of SIG_DFL wait counts. - */ - THR_LOCK_ACQUIRE(curthread, &_thread_signal_lock); - - /* * Enter a loop to find the signals that are SIG_DFL. For * these signals we must install a dummy signal handler in * order for the kernel to pass them in to us. POSIX says @@ -123,8 +123,8 @@ _sigwait(const sigset_t *set, int *sig) } } /* Done accessing _thread_dfl_count for now. */ - THR_LOCK_RELEASE(curthread, &_thread_signal_lock); - + KSE_LOCK_RELEASE(curthread->kse, &_thread_signal_lock); + _kse_critical_leave(crit); if (ret == 0) { /* * Save the wait signal mask. The wait signal @@ -151,7 +151,8 @@ _sigwait(const sigset_t *set, int *sig) /* * Relock the array of SIG_DFL wait counts. */ - THR_LOCK_ACQUIRE(curthread, &_thread_signal_lock); + crit = _kse_critical_enter(); + KSE_LOCK_ACQUIRE(curthread->kse, &_thread_signal_lock); /* Restore the sigactions: */ act.sa_handler = SIG_DFL; @@ -166,10 +167,10 @@ _sigwait(const sigset_t *set, int *sig) } } /* Done accessing _thread_dfl_count. */ - THR_LOCK_RELEASE(curthread, &_thread_signal_lock); - + KSE_LOCK_RELEASE(curthread->kse, &_thread_signal_lock); + _kse_critical_leave(crit); _thr_leave_cancellation_point(curthread); - + /* Return the completion status: */ return (ret); } |