-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit deprecates the entire libtime library in favor of the externally-provided libtime in the rust-lang organization. Users of the `libtime` crate as-is today should add this to their Cargo manifests: [dependencies.time] git = "https://github.com/rust-lang/time" To implement this transition, a new function `Duration::span` was added to the `std::time::Duration` time. This function takes a closure and then returns the duration of time it took that closure to execute. This interface will likely improve with `FnOnce` unboxed closures as moving in and out will be a little easier. Due to the deprecation of the in-tree crate, this is a: [breaking-change] cc #18855, some of the conversions in the `src/test/bench` area may have been a little nicer with that implemented
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,79 @@ | |
|
||
//! Temporal quantification. | ||
use libc; | ||
|
||
pub use self::duration::Duration; | ||
|
||
pub mod duration; | ||
|
||
/// Returns the current value of a high-resolution performance counter | ||
/// 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); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pnkfelix
Member
|
||
} | ||
|
||
#[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.doit(|| { | ||
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; | ||
} | ||
} |
5 comments
on commit fcd05ed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from jakub
at alexcrichton@fcd05ed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging alexcrichton/rust/remove-time = fcd05ed into auto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/2235
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/2233
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/2226
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/2233
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/2227
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/2226
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/2226
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/2230
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/2223
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/2222
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/2226
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/1885
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/1882
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/1889
success: http://buildbot.rust-lang.org/builders/auto-win-64-opt/builds/726
success: http://buildbot.rust-lang.org/builders/auto-win-64-nopt-t/builds/719
success: http://buildbot.rust-lang.org/builders/auto-win-64-nopt-c/builds/713
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = 5745e41
fyi @alexcrichton i think this multiply is overflowing. In all branches; its just that the arithmetic-overflow branch is now catching it happening.
Obviously the multiply does not live here anymore; it has AFAICT been migrated to std::sys::windows::time
The only evidence I have currently of the overflow is here: try build log
(scroll to the bottom, you'll see at the end the following message:)