Optimize thr_suspend, if timeout is zero, don't call msleep, just
return immediately.
This commit is contained in:
parent
6616b254f2
commit
22bc7d14ad
@ -430,15 +430,12 @@ int
|
||||
kern_thr_suspend(struct thread *td, struct timespec *tsp)
|
||||
{
|
||||
struct timeval tv;
|
||||
int error = 0, hz = 0;
|
||||
int error = 0;
|
||||
int timo = 0;
|
||||
|
||||
if (tsp != NULL) {
|
||||
if (tsp->tv_nsec < 0 || tsp->tv_nsec > 1000000000)
|
||||
return (EINVAL);
|
||||
if (tsp->tv_sec == 0 && tsp->tv_nsec == 0)
|
||||
return (ETIMEDOUT);
|
||||
TIMESPEC_TO_TIMEVAL(&tv, tsp);
|
||||
hz = tvtohz(&tv);
|
||||
}
|
||||
|
||||
if (td->td_pflags & TDP_WAKEUP) {
|
||||
@ -447,9 +444,17 @@ kern_thr_suspend(struct thread *td, struct timespec *tsp)
|
||||
}
|
||||
|
||||
PROC_LOCK(td->td_proc);
|
||||
if ((td->td_flags & TDF_THRWAKEUP) == 0)
|
||||
error = msleep((void *)td, &td->td_proc->p_mtx, PCATCH, "lthr",
|
||||
hz);
|
||||
if ((td->td_flags & TDF_THRWAKEUP) == 0) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (td->td_flags & TDF_THRWAKEUP) {
|
||||
thread_lock(td);
|
||||
td->td_flags &= ~TDF_THRWAKEUP;
|
||||
@ -461,7 +466,7 @@ kern_thr_suspend(struct thread *td, struct timespec *tsp)
|
||||
if (error == EWOULDBLOCK)
|
||||
error = ETIMEDOUT;
|
||||
else if (error == ERESTART) {
|
||||
if (hz != 0)
|
||||
if (timo != 0)
|
||||
error = EINTR;
|
||||
}
|
||||
return (error);
|
||||
|
Loading…
Reference in New Issue
Block a user