Skip to content

Commit 8d7df21

Browse files
committed
Support earlier minimum rust version
Remove checked_duration_since in favor of arithmetic and manual checks
1 parent 78f10b2 commit 8d7df21

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

crossbeam-utils/src/sync/parker.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -364,21 +364,22 @@ impl Inner {
364364
// Block the current thread on the conditional variable.
365365
m = match deadline {
366366
None => self.cvar.wait(m).unwrap(),
367-
Some(deadline) => match deadline.checked_duration_since(Instant::now()) {
368-
// We could check for a timeout here, in the return value of wait_timeout,
369-
// but in the case that a timeout and an unpark arrive simultaneously, we
370-
// prefer to report the former.
371-
Some(duration) if duration > Duration::from_secs(0) => {
372-
self.cvar.wait_timeout(m, duration).unwrap().0
367+
Some(deadline) => {
368+
let now = Instant::now();
369+
if now < deadline {
370+
// We could check for a timeout here, in the return value of wait_timeout,
371+
// but in the case that a timeout and an unpark arrive simultaneously, we
372+
// prefer to report the former.
373+
self.cvar.wait_timeout(m, deadline - now).unwrap().0
374+
} else {
375+
// We've timed out; swap out the state back to empty on our way out
376+
return match self.state.swap(EMPTY, SeqCst) {
377+
NOTIFIED => UnparkReason::Unparked, // got a notification
378+
PARKED => UnparkReason::Timeout, // no notification
379+
n => panic!("inconsistent park_timeout state: {}", n),
380+
};
373381
}
374-
375-
// We've timed out; swap out the state back to empty on our way out
376-
_ => match self.state.swap(EMPTY, SeqCst) {
377-
NOTIFIED => return UnparkReason::Unparked, // got a notification
378-
PARKED => return UnparkReason::Timeout, // no notification
379-
n => panic!("inconsistent park_timeout state: {}", n),
380-
},
381-
},
382+
}
382383
};
383384

384385
if self

0 commit comments

Comments
 (0)