diff options
author | Brian Behlendorf <[email protected]> | 2016-08-25 20:24:01 +0000 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2016-08-29 10:54:14 -0700 |
commit | 67925abb5e12c003e959c87ddec19a3842fe5976 (patch) | |
tree | 53c80cfb46d716a2d9a3a934d064030b7269edad | |
parent | 9907cc1cc8c16fa2c7c03aa33264153ca2bdad6c (diff) |
Fix cv_timedwait_hires
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 206971d2.
Replace two magic values with their corresponding preprocessor macro.
Signed-off-by: Brian Behlendorf <[email protected]>
Signed-off-by: Richard Yao <[email protected]>
Closes #5024
-rw-r--r-- | lib/libzpool/kernel.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/libzpool/kernel.c b/lib/libzpool/kernel.c index 549dd4c5c..7ac505a64 100644 --- a/lib/libzpool/kernel.c +++ b/lib/libzpool/kernel.c @@ -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; @@ -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; @@ -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; |