Fix dur2intervals import on cloudabi
This commit is contained in:
parent
9511fc7845
commit
9e5e89a0d3
3 changed files with 9 additions and 5 deletions
|
@ -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" {
|
||||
|
@ -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,
|
||||
|
@ -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()
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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()
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue