Skip to content

Commit

Permalink
Fix cv_timedwait_hires
Browse files Browse the repository at this point in the history
The user space implementation of cv_timedwait_hires() was always passing
a relative time to pthread_cond_timedwait() when an absolute time is
expected.  This was accidentally introduced in commit 206971d.

Peplace two magic values with their corresponding preprocessor macro.

Signed-off-by: Brian Behlendorf <[email protected]>
  • Loading branch information
behlendorf committed Aug 25, 2016
1 parent 9907cc1 commit 9444ad3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/libzpool/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime)
VERIFY(gettimeofday(&tv, NULL) == 0);

ts.tv_sec = tv.tv_sec + delta / hz;
ts.tv_nsec = tv.tv_usec * 1000 + (delta % hz) * (NANOSEC / hz);
ts.tv_nsec = tv.tv_usec * NSEC_PER_USEC + (delta % hz) * (NANOSEC / hz);
if (ts.tv_nsec >= NANOSEC) {
ts.tv_sec++;
ts.tv_nsec -= NANOSEC;
Expand All @@ -534,6 +534,7 @@ cv_timedwait_hires(kcondvar_t *cv, kmutex_t *mp, hrtime_t tim, hrtime_t res,
int flag)
{
int error;
struct timeval tv;
timestruc_t ts;
hrtime_t delta;

Expand All @@ -546,11 +547,17 @@ cv_timedwait_hires(kcondvar_t *cv, kmutex_t *mp, hrtime_t tim, hrtime_t res,
if (delta <= 0)
return (-1);

ts.tv_sec = delta / NANOSEC;
ts.tv_nsec = delta % NANOSEC;
VERIFY(gettimeofday(&tv, NULL) == 0);

ts.tv_sec = tv.tv_sec + delta / NANOSEC;
ts.tv_nsec = tv.tv_usec * NSEC_PER_USEC + (delta % NANOSEC);
if (ts.tv_nsec >= NANOSEC) {
ts.tv_sec++;
ts.tv_nsec -= NANOSEC;
}

ASSERT(mutex_owner(mp) == curthread);
mp->m_owner = NULL;
mp->m_owner = MTX_INIT;
error = pthread_cond_timedwait(&cv->cv, &mp->m_lock, &ts);
mp->m_owner = curthread;

Expand Down

0 comments on commit 9444ad3

Please sign in to comment.