From c1df5a1a5ded7e33b710ea58f9e0c116821249d5 Mon Sep 17 00:00:00 2001 From: David Xu Date: Wed, 1 Dec 2004 13:50:04 +0000 Subject: [PATCH] If a thread is resumed by thr_wake, it should return 0, especially it should not return ERESTART after it caught a signal, otherwise thr_wake() call will be lost, also a timeout wait should not be restarted. Final, using wakeup not wakeup_one to be safeness. --- sys/kern/kern_thr.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_thr.c b/sys/kern/kern_thr.c index baa922458378..7b16c946cb58 100644 --- a/sys/kern/kern_thr.c +++ b/sys/kern/kern_thr.c @@ -264,11 +264,21 @@ thr_suspend(struct thread *td, struct thr_suspend_args *uap) if ((td->td_flags & TDF_THRWAKEUP) == 0) error = msleep((void *)td, &td->td_proc->p_mtx, td->td_priority | PCATCH, "lthr", hz); - mtx_lock_spin(&sched_lock); - td->td_flags &= ~TDF_THRWAKEUP; - mtx_unlock_spin(&sched_lock); + if (td->td_flags & TDF_THRWAKEUP) { + mtx_lock_spin(&sched_lock); + td->td_flags &= ~TDF_THRWAKEUP; + mtx_unlock_spin(&sched_lock); + PROC_UNLOCK(td->td_proc); + return (0); + } PROC_UNLOCK(td->td_proc); - return (error == EWOULDBLOCK ? ETIMEDOUT : error); + if (error == EWOULDBLOCK) + error = ETIMEDOUT; + else if (error == ERESTART) { + if (hz != 0) + error = EINTR; + } + return (error); } int @@ -289,7 +299,7 @@ thr_wake(struct thread *td, struct thr_wake_args *uap) mtx_lock_spin(&sched_lock); ttd->td_flags |= TDF_THRWAKEUP; mtx_unlock_spin(&sched_lock); - wakeup_one((void *)ttd); + wakeup((void *)ttd); PROC_UNLOCK(td->td_proc); return (0); }