- Don't include sx.h, it is not needed.
- Check NULL pointer, move timeout calculation code outside of process lock.
This commit is contained in:
parent
69b5727f16
commit
cfca8a1862
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=214091
@ -45,7 +45,6 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/systm.h>
|
#include <sys/systm.h>
|
||||||
#include <sys/sysproto.h>
|
#include <sys/sysproto.h>
|
||||||
#include <sys/signalvar.h>
|
#include <sys/signalvar.h>
|
||||||
#include <sys/sx.h>
|
|
||||||
#include <sys/ucontext.h>
|
#include <sys/ucontext.h>
|
||||||
#include <sys/thr.h>
|
#include <sys/thr.h>
|
||||||
#include <sys/rtprio.h>
|
#include <sys/rtprio.h>
|
||||||
@ -431,40 +430,40 @@ thr_suspend(struct thread *td, struct thr_suspend_args *uap)
|
|||||||
int
|
int
|
||||||
kern_thr_suspend(struct thread *td, struct timespec *tsp)
|
kern_thr_suspend(struct thread *td, struct timespec *tsp)
|
||||||
{
|
{
|
||||||
|
struct proc *p = td->td_proc;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
int timo = 0;
|
int timo = 0;
|
||||||
|
|
||||||
if (tsp != NULL) {
|
|
||||||
if (tsp->tv_nsec < 0 || tsp->tv_nsec > 1000000000)
|
|
||||||
return (EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (td->td_pflags & TDP_WAKEUP) {
|
if (td->td_pflags & TDP_WAKEUP) {
|
||||||
td->td_pflags &= ~TDP_WAKEUP;
|
td->td_pflags &= ~TDP_WAKEUP;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PROC_LOCK(td->td_proc);
|
if (tsp != NULL) {
|
||||||
if ((td->td_flags & TDF_THRWAKEUP) == 0) {
|
if (tsp->tv_nsec < 0 || tsp->tv_nsec > 1000000000)
|
||||||
|
return (EINVAL);
|
||||||
if (tsp->tv_sec == 0 && tsp->tv_nsec == 0)
|
if (tsp->tv_sec == 0 && tsp->tv_nsec == 0)
|
||||||
error = EWOULDBLOCK;
|
error = EWOULDBLOCK;
|
||||||
else {
|
else {
|
||||||
TIMESPEC_TO_TIMEVAL(&tv, tsp);
|
TIMESPEC_TO_TIMEVAL(&tv, tsp);
|
||||||
timo = tvtohz(&tv);
|
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) {
|
if (td->td_flags & TDF_THRWAKEUP) {
|
||||||
thread_lock(td);
|
thread_lock(td);
|
||||||
td->td_flags &= ~TDF_THRWAKEUP;
|
td->td_flags &= ~TDF_THRWAKEUP;
|
||||||
thread_unlock(td);
|
thread_unlock(td);
|
||||||
PROC_UNLOCK(td->td_proc);
|
PROC_UNLOCK(p);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
PROC_UNLOCK(td->td_proc);
|
PROC_UNLOCK(p);
|
||||||
if (error == EWOULDBLOCK)
|
if (error == EWOULDBLOCK)
|
||||||
error = ETIMEDOUT;
|
error = ETIMEDOUT;
|
||||||
else if (error == ERESTART) {
|
else if (error == ERESTART) {
|
||||||
|
Loading…
Reference in New Issue
Block a user