diff options
| author | bors <bors@rust-lang.org> | 2015-01-17 03:51:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-01-17 03:51:34 +0000 |
| commit | 378fb5846d2d8dbc5ab24a5e92794c5c39d492dc (patch) | |
| tree | 5e01516c301e9534e68a8d929edfca1e6d75c3b5 /src/libstd/time | |
| parent | ed530d7a3b67989047e6fe61fe101b9d8158585f (diff) | |
| parent | 08f6380a9f0b866796080094f44fe25ea5636547 (diff) | |
| download | rust-378fb5846d2d8dbc5ab24a5e92794c5c39d492dc.tar.gz rust-378fb5846d2d8dbc5ab24a5e92794c5c39d492dc.zip | |
auto merge of #21132 : sfackler/rust/wait_timeout, r=alexcrichton
**The implementation is a direct adaptation of libcxx's condition_variable implementation.** I also added a wait_timeout_with method, which matches the second overload in C++'s condition_variable. The implementation right now is kind of dumb but it works. There is an outstanding issue with it: as is it doesn't support the use case where a user doesn't care about poisoning and wants to continue through poison. r? @alexcrichton @aturon
Diffstat (limited to 'src/libstd/time')
| -rw-r--r-- | src/libstd/time/mod.rs | 68 |
1 files changed, 2 insertions, 66 deletions
diff --git a/src/libstd/time/mod.rs b/src/libstd/time/mod.rs index d6c94f27a8b..f62571942a7 100644 --- a/src/libstd/time/mod.rs +++ b/src/libstd/time/mod.rs @@ -10,7 +10,7 @@ //! Temporal quantification. -use libc; +use sys::time::SteadyTime; pub use self::duration::Duration; @@ -20,69 +20,5 @@ pub mod duration; /// in nanoseconds since an unspecified epoch. // NB: this is intentionally not public, this is not ready to stabilize its api. fn precise_time_ns() -> u64 { - return os_precise_time_ns(); - - #[cfg(windows)] - fn os_precise_time_ns() -> u64 { - let mut ticks_per_s = 0; - assert_eq!(unsafe { - libc::QueryPerformanceFrequency(&mut ticks_per_s) - }, 1); - let ticks_per_s = if ticks_per_s == 0 {1} else {ticks_per_s}; - let mut ticks = 0; - assert_eq!(unsafe { - libc::QueryPerformanceCounter(&mut ticks) - }, 1); - - return (ticks as u64 * 1000000000) / (ticks_per_s as u64); - } - - #[cfg(any(target_os = "macos", target_os = "ios"))] - fn os_precise_time_ns() -> u64 { - use sync; - - static mut TIMEBASE: libc::mach_timebase_info = libc::mach_timebase_info { numer: 0, - denom: 0 }; - static ONCE: sync::Once = sync::ONCE_INIT; - unsafe { - ONCE.call_once(|| { - imp::mach_timebase_info(&mut TIMEBASE); - }); - let time = imp::mach_absolute_time(); - time * TIMEBASE.numer as u64 / TIMEBASE.denom as u64 - } - } - - #[cfg(not(any(windows, target_os = "macos", target_os = "ios")))] - fn os_precise_time_ns() -> u64 { - let mut ts = libc::timespec { tv_sec: 0, tv_nsec: 0 }; - unsafe { - imp::clock_gettime(libc::CLOCK_MONOTONIC, &mut ts); - } - return (ts.tv_sec as u64) * 1000000000 + (ts.tv_nsec as u64) - } -} - -#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios")))] -mod imp { - use libc::{c_int, timespec}; - - // Apparently android provides this in some other library? - #[cfg(not(target_os = "android"))] - #[link(name = "rt")] - extern {} - - extern { - pub fn clock_gettime(clk_id: c_int, tp: *mut timespec) -> c_int; - } - -} -#[cfg(any(target_os = "macos", target_os = "ios"))] -mod imp { - use libc::{c_int, mach_timebase_info}; - - extern { - pub fn mach_absolute_time() -> u64; - pub fn mach_timebase_info(info: *mut mach_timebase_info) -> c_int; - } + SteadyTime::now().ns() } |
