From 6c353ec94ba476a0d550937c68ad99f9793a5dcb Mon Sep 17 00:00:00 2001 From: Demur Rumed Date: Tue, 19 Jul 2016 10:13:05 -0400 Subject: [PATCH 1/4] Remove time from Cargo.toml --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 70b1e92..beea67f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ homepage = "https://github.com/csherratt/pulse" [dependencies] atom = "0.3" -time = "0.1" [features] default = [] From e5f8b9311b02db3bbf8890a7d2825d32fee5afe3 Mon Sep 17 00:00:00 2001 From: Demur Rumed Date: Tue, 19 Jul 2016 10:16:22 -0400 Subject: [PATCH 2/4] Replace time with std::time --- src/lib.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f874e76..4038b72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,10 +13,10 @@ // limitations under the License. extern crate atom; -extern crate time; use std::sync::atomic::AtomicUsize; use std::thread; +use std::time::{Duration, Instant}; use std::mem; use std::fmt; use std::ops::Deref; @@ -24,7 +24,6 @@ use std::sync::atomic::Ordering; use std::cell::RefCell; use atom::*; -use time::precise_time_s; use fnbox::FnBox; pub use select::{Select, SelectMap}; @@ -517,17 +516,17 @@ impl Scheduler for ThreadScheduler { } fn wait_timeout_ms(&self, signal: Signal, ms: u32) -> Result<(), TimeoutError> { - let mut now = (precise_time_s() * 1000.) as u64; - let end = now + ms as u64; + let start = Instant::now(); + let ms = Duration::from_millis(ms as u64); loop { let id = signal.add_to_waitlist(Waiting::thread()); if signal.is_pending() { - now = (precise_time_s() * 1000.) as u64; - if now > end { + let elapsed = start.elapsed(); + if elapsed > end { return Err(TimeoutError::Timeout); } - thread::park_timeout_ms((end - now) as u32); + thread::park_timeout(elapsed); } signal.remove_from_waitlist(id); From d24ddb49c0ff44ffd27a5d83e2efa1b2ed5921a3 Mon Sep 17 00:00:00 2001 From: Demur Rumed Date: Tue, 19 Jul 2016 10:25:10 -0400 Subject: [PATCH 3/4] Fix typo --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4038b72..cb6f67e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -523,7 +523,7 @@ impl Scheduler for ThreadScheduler { let id = signal.add_to_waitlist(Waiting::thread()); if signal.is_pending() { let elapsed = start.elapsed(); - if elapsed > end { + if elapsed > ms { return Err(TimeoutError::Timeout); } thread::park_timeout(elapsed); From 7dfe649d4b9ffc29bb8647dafb950717342e150f Mon Sep 17 00:00:00 2001 From: Demur Rumed Date: Tue, 19 Jul 2016 10:39:15 -0400 Subject: [PATCH 4/4] Fix logic error in park_timeout being inversed --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index cb6f67e..f835b86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -526,7 +526,7 @@ impl Scheduler for ThreadScheduler { if elapsed > ms { return Err(TimeoutError::Timeout); } - thread::park_timeout(elapsed); + thread::park_timeout(ms - elapsed); } signal.remove_from_waitlist(id);