Skip to content

Commit

Permalink
Fix FreeBSD condvar semantics
Browse files Browse the repository at this point in the history
We should return -1 instead of negative deltas, and 0 if signaled.

Signed-off-by: Ryan Moeller <[email protected]>
  • Loading branch information
Ryan Moeller authored and Ryan Moeller committed Jun 15, 2020
1 parent 883a40f commit 5d8449d
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions include/os/freebsd/spl/sys/condvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,16 @@ cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim, hrtime_t res,
tim += hrtime;

if (hrtime >= tim)
return (tim - hrtime);
return (-1);

rc = cv_timedwait_sbt(cvp, mp, zfs_nstosbt(tim),
zfs_nstosbt(res), C_ABSOLUTE);

KASSERT(rc == EWOULDBLOCK || rc == 0, ("unexpected rc value %d", rc));
return (tim - gethrtime());
if (rc == EWOULDBLOCK)
return (-1);

KASSERT(rc == 0, ("unexpected rc value %d", rc));
return (MAX(1, tim - gethrtime()));
}

static inline clock_t
Expand All @@ -157,14 +161,21 @@ cv_timedwait_sig_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim,
tim += hrtime;

if (hrtime >= tim)
return (tim - hrtime);
return (-1);

sbt = zfs_nstosbt(tim);
rc = cv_timedwait_sig_sbt(cvp, mp, sbt, zfs_nstosbt(res), C_ABSOLUTE);

KASSERT(rc == EWOULDBLOCK || rc == EINTR || rc == ERESTART ||
rc == 0, ("unexpected rc value %d", rc));
return (tim - gethrtime());
switch (rc) {
case EWOULDBLOCK:
return (-1);
case EINTR:
case ERESTART:
return (0);
default:
KASSERT(rc == 0, ("unexpected rc value %d", rc));
return (MAX(1, tim - gethrtime()));
}
}

#endif /* _OPENSOLARIS_SYS_CONDVAR_H_ */

0 comments on commit 5d8449d

Please sign in to comment.