summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_thr.c
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2010-10-20 00:41:38 +0000
committerdavidxu <davidxu@FreeBSD.org>2010-10-20 00:41:38 +0000
commit520d21ea78ad909c12b58c25403192af742c855c (patch)
treec680fed46b84c58e620bf3807761f1fbf7560eb3 /sys/kern/kern_thr.c
parent5c504190d03b82f0ff94fefd4fb37133c34d0f25 (diff)
downloadFreeBSD-src-520d21ea78ad909c12b58c25403192af742c855c.zip
FreeBSD-src-520d21ea78ad909c12b58c25403192af742c855c.tar.gz
- Don't include sx.h, it is not needed.
- Check NULL pointer, move timeout calculation code outside of process lock.
Diffstat (limited to 'sys/kern/kern_thr.c')
-rw-r--r--sys/kern/kern_thr.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/sys/kern/kern_thr.c b/sys/kern/kern_thr.c
index 7627027..3a9c721 100644
--- a/sys/kern/kern_thr.c
+++ b/sys/kern/kern_thr.c
@@ -45,7 +45,6 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/sysproto.h>
#include <sys/signalvar.h>
-#include <sys/sx.h>
#include <sys/ucontext.h>
#include <sys/thr.h>
#include <sys/rtprio.h>
@@ -431,40 +430,40 @@ thr_suspend(struct thread *td, struct thr_suspend_args *uap)
int
kern_thr_suspend(struct thread *td, struct timespec *tsp)
{
+ struct proc *p = td->td_proc;
struct timeval tv;
int error = 0;
int timo = 0;
- if (tsp != NULL) {
- if (tsp->tv_nsec < 0 || tsp->tv_nsec > 1000000000)
- return (EINVAL);
- }
-
if (td->td_pflags & TDP_WAKEUP) {
td->td_pflags &= ~TDP_WAKEUP;
return (0);
}
- PROC_LOCK(td->td_proc);
- if ((td->td_flags & TDF_THRWAKEUP) == 0) {
+ if (tsp != NULL) {
+ if (tsp->tv_nsec < 0 || tsp->tv_nsec > 1000000000)
+ return (EINVAL);
if (tsp->tv_sec == 0 && tsp->tv_nsec == 0)
error = EWOULDBLOCK;
else {
TIMESPEC_TO_TIMEVAL(&tv, tsp);
timo = tvtohz(&tv);
- error = msleep((void *)td, &td->td_proc->p_mtx,
- PCATCH, "lthr", timo);
}
}
+ PROC_LOCK(p);
+ if (error == 0 && (td->td_flags & TDF_THRWAKEUP) == 0)
+ error = msleep((void *)td, &p->p_mtx,
+ PCATCH, "lthr", timo);
+
if (td->td_flags & TDF_THRWAKEUP) {
thread_lock(td);
td->td_flags &= ~TDF_THRWAKEUP;
thread_unlock(td);
- PROC_UNLOCK(td->td_proc);
+ PROC_UNLOCK(p);
return (0);
}
- PROC_UNLOCK(td->td_proc);
+ PROC_UNLOCK(p);
if (error == EWOULDBLOCK)
error = ETIMEDOUT;
else if (error == ERESTART) {
OpenPOWER on IntegriCloud