Skip to content

Commit 9e5e89a

Browse files
committed
Fix dur2intervals import on cloudabi
1 parent 9511fc7 commit 9e5e89a

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/libstd/sys/cloudabi/condvar.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use mem;
1313
use sync::atomic::{AtomicU32, Ordering};
1414
use sys::cloudabi::abi;
1515
use sys::mutex::{self, Mutex};
16-
use sys::time::dur2intervals;
16+
use sys::time::checked_dur2intervals;
1717
use time::Duration;
1818

1919
extern "C" {
@@ -114,6 +114,8 @@ impl Condvar {
114114

115115
// Call into the kernel to wait on the condition variable.
116116
let condvar = self.condvar.get();
117+
let timeout = checked_dur2intervals(&dur)
118+
.expect("overflow converting duration to nanoseconds");
117119
let subscriptions = [
118120
abi::subscription {
119121
type_: abi::eventtype::CONDVAR,
@@ -132,7 +134,7 @@ impl Condvar {
132134
union: abi::subscription_union {
133135
clock: abi::subscription_clock {
134136
clock_id: abi::clockid::MONOTONIC,
135-
timeout: dur2intervals(&dur),
137+
timeout,
136138
..mem::zeroed()
137139
},
138140
},

src/libstd/sys/cloudabi/thread.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use libc;
1616
use mem;
1717
use ptr;
1818
use sys::cloudabi::abi;
19-
use sys::time::dur2intervals;
19+
use sys::time::checked_dur2intervals;
2020
use sys_common::thread::*;
2121
use time::Duration;
2222

@@ -70,13 +70,15 @@ impl Thread {
7070
}
7171

7272
pub fn sleep(dur: Duration) {
73+
let timeout = checked_dur2intervals(&dur)
74+
.expect("overflow converting duration to nanoseconds");
7375
unsafe {
7476
let subscription = abi::subscription {
7577
type_: abi::eventtype::CLOCK,
7678
union: abi::subscription_union {
7779
clock: abi::subscription_clock {
7880
clock_id: abi::clockid::MONOTONIC,
79-
timeout: dur2intervals(&dur),
81+
timeout,
8082
..mem::zeroed()
8183
},
8284
},

src/libstd/sys/cloudabi/time.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct Instant {
1919
t: abi::timestamp,
2020
}
2121

22-
fn checked_dur2intervals(dur: &Duration) -> Option<abi::timestamp> {
22+
pub fn checked_dur2intervals(dur: &Duration) -> Option<abi::timestamp> {
2323
dur.as_secs()
2424
.checked_mul(NSEC_PER_SEC)?
2525
.checked_add(dur.subsec_nanos() as abi::timestamp)

0 commit comments

Comments
 (0)