diff options
| author | bors <bors@rust-lang.org> | 2018-12-14 09:10:35 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-12-14 09:10:35 +0000 |
| commit | f4b07e0713b2d82417968db08cd0575734cdac0d (patch) | |
| tree | 3d0e3c2bafe69d07c7cd3d1d85ef679da42d2797 /src/libstd/sys/cloudabi/thread.rs | |
| parent | 664ede88faf57b8fc09715fc66cd9e46490ce64d (diff) | |
| parent | 9e5e89a0d37b06e4f6915809b6a21409727acdc1 (diff) | |
| download | rust-f4b07e0713b2d82417968db08cd0575734cdac0d.tar.gz rust-f4b07e0713b2d82417968db08cd0575734cdac0d.zip | |
Auto merge of #56490 - faern:add-checked-add-to-instant, r=alexcrichton
Add checked_add method to Instant time type Appending functionality to the already opened topic of `checked_add` on time types over at #55940. Doing checked addition between an `Instant` and a `Duration` is important to reliably determine a future instant. We could use this in the `parking_lot` crate to compute an instant when in the future to wake a thread up without risking a panic.
Diffstat (limited to 'src/libstd/sys/cloudabi/thread.rs')
| -rw-r--r-- | src/libstd/sys/cloudabi/thread.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/libstd/sys/cloudabi/thread.rs b/src/libstd/sys/cloudabi/thread.rs index a76e1fa3345..177321439d8 100644 --- a/src/libstd/sys/cloudabi/thread.rs +++ b/src/libstd/sys/cloudabi/thread.rs @@ -16,7 +16,7 @@ use libc; use mem; use ptr; use sys::cloudabi::abi; -use sys::time::dur2intervals; +use sys::time::checked_dur2intervals; use sys_common::thread::*; use time::Duration; @@ -70,13 +70,15 @@ impl Thread { } pub fn sleep(dur: Duration) { + let timeout = checked_dur2intervals(&dur) + .expect("overflow converting duration to nanoseconds"); unsafe { let subscription = abi::subscription { type_: abi::eventtype::CLOCK, union: abi::subscription_union { clock: abi::subscription_clock { clock_id: abi::clockid::MONOTONIC, - timeout: dur2intervals(&dur), + timeout, ..mem::zeroed() }, }, |
