mirror of https://github.com/openzfs/zfs.git
Fix FreeBSD condvar semantics
We should return -1 instead of negative deltas, and 0 if signaled. Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Jorgen Lundman <lundman@lundman.net> Signed-off-by: Ryan Moeller <ryan@iXsystems.com> Closes #10460
This commit is contained in:
parent
883a40fff4
commit
c13facb9c4
|
@ -134,12 +134,17 @@ cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim, hrtime_t res,
|
||||||
tim += hrtime;
|
tim += hrtime;
|
||||||
|
|
||||||
if (hrtime >= tim)
|
if (hrtime >= tim)
|
||||||
return (tim - hrtime);
|
return (-1);
|
||||||
|
|
||||||
rc = cv_timedwait_sbt(cvp, mp, zfs_nstosbt(tim),
|
rc = cv_timedwait_sbt(cvp, mp, zfs_nstosbt(tim),
|
||||||
zfs_nstosbt(res), C_ABSOLUTE);
|
zfs_nstosbt(res), C_ABSOLUTE);
|
||||||
|
|
||||||
KASSERT(rc == EWOULDBLOCK || rc == 0, ("unexpected rc value %d", rc));
|
if (rc == EWOULDBLOCK)
|
||||||
return (tim - gethrtime());
|
return (-1);
|
||||||
|
|
||||||
|
KASSERT(rc == 0, ("unexpected rc value %d", rc));
|
||||||
|
hrtime = tim - gethrtime();
|
||||||
|
return ((hrtime > 0) ? hrtime : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline clock_t
|
static inline clock_t
|
||||||
|
@ -157,14 +162,22 @@ cv_timedwait_sig_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim,
|
||||||
tim += hrtime;
|
tim += hrtime;
|
||||||
|
|
||||||
if (hrtime >= tim)
|
if (hrtime >= tim)
|
||||||
return (tim - hrtime);
|
return (-1);
|
||||||
|
|
||||||
sbt = zfs_nstosbt(tim);
|
sbt = zfs_nstosbt(tim);
|
||||||
rc = cv_timedwait_sig_sbt(cvp, mp, sbt, zfs_nstosbt(res), C_ABSOLUTE);
|
rc = cv_timedwait_sig_sbt(cvp, mp, sbt, zfs_nstosbt(res), C_ABSOLUTE);
|
||||||
|
|
||||||
KASSERT(rc == EWOULDBLOCK || rc == EINTR || rc == ERESTART ||
|
switch (rc) {
|
||||||
rc == 0, ("unexpected rc value %d", rc));
|
case EWOULDBLOCK:
|
||||||
return (tim - gethrtime());
|
return (-1);
|
||||||
|
case EINTR:
|
||||||
|
case ERESTART:
|
||||||
|
return (0);
|
||||||
|
default:
|
||||||
|
KASSERT(rc == 0, ("unexpected rc value %d", rc));
|
||||||
|
hrtime = tim - gethrtime();
|
||||||
|
return ((hrtime > 0) ? hrtime : -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _OPENSOLARIS_SYS_CONDVAR_H_ */
|
#endif /* _OPENSOLARIS_SYS_CONDVAR_H_ */
|
||||||
|
|
Loading…
Reference in New Issue