Skip to content

Commit

Permalink
Fix dur2intervals import on cloudabi
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Dec 13, 2018
1 parent 9511fc7 commit 9e5e89a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/libstd/sys/cloudabi/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use mem;
use sync::atomic::{AtomicU32, Ordering};
use sys::cloudabi::abi;
use sys::mutex::{self, Mutex};
use sys::time::dur2intervals;
use sys::time::checked_dur2intervals;
use time::Duration;

extern "C" {
Expand Down Expand Up @@ -114,6 +114,8 @@ impl Condvar {

// Call into the kernel to wait on the condition variable.
let condvar = self.condvar.get();
let timeout = checked_dur2intervals(&dur)
.expect("overflow converting duration to nanoseconds");
let subscriptions = [
abi::subscription {
type_: abi::eventtype::CONDVAR,
Expand All @@ -132,7 +134,7 @@ impl Condvar {
union: abi::subscription_union {
clock: abi::subscription_clock {
clock_id: abi::clockid::MONOTONIC,
timeout: dur2intervals(&dur),
timeout,
..mem::zeroed()
},
},
Expand Down
6 changes: 4 additions & 2 deletions src/libstd/sys/cloudabi/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/cloudabi/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Instant {
t: abi::timestamp,
}

fn checked_dur2intervals(dur: &Duration) -> Option<abi::timestamp> {
pub fn checked_dur2intervals(dur: &Duration) -> Option<abi::timestamp> {
dur.as_secs()
.checked_mul(NSEC_PER_SEC)?
.checked_add(dur.subsec_nanos() as abi::timestamp)
Expand Down

0 comments on commit 9e5e89a

Please sign in to comment.