tvtohz will print out an error message if a negative value is given

to it, avoid this problem by detecting timeout earlier.

Reported by: pho
This commit is contained in:
David Xu 2012-08-11 00:06:56 +00:00
parent 579895df01
commit e8afbca2bc
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=239187

View File

@ -587,11 +587,10 @@ abs_timeout_init2(struct abs_timeout *timo, const struct _umtx_time *umtxtime)
&umtxtime->_timeout); &umtxtime->_timeout);
} }
static int static void
abs_timeout_update(struct abs_timeout *timo) abs_timeout_update(struct abs_timeout *timo)
{ {
kern_clock_gettime(curthread, timo->clockid, &timo->cur); kern_clock_gettime(curthread, timo->clockid, &timo->cur);
return (timespeccmp(&timo->cur, &timo->end, >=));
} }
static int static int
@ -601,6 +600,8 @@ abs_timeout_gethz(struct abs_timeout *timo)
tts = timo->end; tts = timo->end;
timespecsub(&tts, &timo->cur); timespecsub(&tts, &timo->cur);
if (tts.tv_sec < 0 || (tts.tv_sec == 0 && tts.tv_nsec == 0))
return (-1);
return (tstohz(&tts)); return (tstohz(&tts));
} }
@ -613,22 +614,25 @@ umtxq_sleep(struct umtx_q *uq, const char *wmesg, struct abs_timeout *timo)
{ {
struct umtxq_chain *uc; struct umtxq_chain *uc;
int error; int error;
int pulse;
uc = umtxq_getchain(&uq->uq_key); uc = umtxq_getchain(&uq->uq_key);
UMTXQ_LOCKED_ASSERT(uc); UMTXQ_LOCKED_ASSERT(uc);
for (;;) { for (;;) {
if (!(uq->uq_flags & UQF_UMTXQ)) if (!(uq->uq_flags & UQF_UMTXQ))
return (0); return (0);
error = msleep(uq, &uc->uc_lock, PCATCH, wmesg, if (timo != NULL) {
timo == NULL ? 0 : abs_timeout_gethz(timo)); pulse = abs_timeout_gethz(timo);
if (error != EWOULDBLOCK) if (pulse < 0)
break; return (ETIMEDOUT);
umtxq_unlock(&uq->uq_key); } else
if (abs_timeout_update(timo)) { pulse = 0;
error = ETIMEDOUT; error = msleep(uq, &uc->uc_lock, PCATCH|PDROP, wmesg, pulse);
if (error != EWOULDBLOCK) {
umtxq_lock(&uq->uq_key); umtxq_lock(&uq->uq_key);
break; break;
} }
abs_timeout_update(timo);
umtxq_lock(&uq->uq_key); umtxq_lock(&uq->uq_key);
} }
return (error); return (error);