Skip to content

Commit

Permalink
Merge pull request #15 from serprex/master
Browse files Browse the repository at this point in the history
Replace time with std::time
  • Loading branch information
csherratt authored Jul 28, 2016
2 parents 9d37926 + 7dfe649 commit 8cbe16c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ homepage = "https://github.com/csherratt/pulse"

[dependencies]
atom = "0.3"
time = "0.1"

[features]
default = []
Expand Down
13 changes: 6 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@
// 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;
use std::sync::atomic::Ordering;
use std::cell::RefCell;

use atom::*;
use time::precise_time_s;
use fnbox::FnBox;

pub use select::{Select, SelectMap};
Expand Down Expand Up @@ -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 > ms {
return Err(TimeoutError::Timeout);
}
thread::park_timeout_ms((end - now) as u32);
thread::park_timeout(ms - elapsed);
}
signal.remove_from_waitlist(id);

Expand Down

0 comments on commit 8cbe16c

Please sign in to comment.