diff options
| author | bors <bors@rust-lang.org> | 2015-11-19 23:57:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-11-19 23:57:07 +0000 |
| commit | b289892b5d4acd52237fb88ab12f825e7602280c (patch) | |
| tree | 82332c0640871d8d6d3df3c9e58d11c904fa2cd4 /src/libstd/sync | |
| parent | 6861c51453963317849b4488ddc6a110e4f3470a (diff) | |
| parent | c6eb8527e09bed702f30ffdc8d6e54acf9b867ca (diff) | |
| download | rust-b289892b5d4acd52237fb88ab12f825e7602280c.tar.gz rust-b289892b5d4acd52237fb88ab12f825e7602280c.zip | |
Auto merge of #29894 - alexcrichton:stdtime, r=brson
This commit is an implementation of [RFC 1288][rfc] which adds two new unstable types to the `std::time` module. The `Instant` type is used to represent measurements of a monotonically increasing clock suitable for measuring time withing a process for operations such as benchmarks or just the elapsed time to do something. An `Instant` favors panicking when bugs are found as the bugs are programmer errors rather than typical errors that can be encountered. [rfc]: https://github.com/rust-lang/rfcs/pull/1288 The `SystemTime` type is used to represent a system timestamp and is not monotonic. Very few guarantees are provided about this measurement of the system clock, but a fixed point in time (`UNIX_EPOCH`) is provided to learn about the relative distance from this point for any particular time stamp. This PR takes the same implementation strategy as the `time` crate on crates.io, namely: | Platform | Instant | SystemTime | |------------|--------------------------|--------------------------| | Windows | QueryPerformanceCounter | GetSystemTimeAsFileTime | | OSX | mach_absolute_time | gettimeofday | | Unix | CLOCK_MONOTONIC | CLOCK_REALTIME | These implementations can perhaps be refined over time, but they currently satisfy the requirements of the `Instant` and `SystemTime` types while also being portable across implementations and revisions of each platform. cc #29866
Diffstat (limited to 'src/libstd/sync')
| -rw-r--r-- | src/libstd/sync/condvar.rs | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index a18370dc68e..389c9c4a066 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -12,11 +12,10 @@ use prelude::v1::*; use sync::atomic::{AtomicUsize, Ordering}; use sync::{mutex, MutexGuard, PoisonError}; -use sys::time::SteadyTime; use sys_common::condvar as sys; use sys_common::mutex as sys_mutex; use sys_common::poison::{self, LockResult}; -use time::Duration; +use time::{Instant, Duration}; /// A type indicating whether a timed wait on a condition variable returned /// due to a time out or not. @@ -345,14 +344,13 @@ impl StaticCondvar { where F: FnMut(LockResult<&mut T>) -> bool { // This could be made more efficient by pushing the implementation into // sys::condvar - let start = SteadyTime::now(); + let start = Instant::now(); let mut guard_result: LockResult<MutexGuard<'a, T>> = Ok(guard); while !f(guard_result .as_mut() .map(|g| &mut **g) .map_err(|e| PoisonError::new(&mut **e.get_mut()))) { - let now = SteadyTime::now(); - let consumed = &now - &start; + let consumed = start.elapsed(); let guard = guard_result.unwrap_or_else(|e| e.into_inner()); let (new_guard_result, timed_out) = if consumed > dur { (Ok(guard), WaitTimeoutResult(true)) |
