Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[package]
name = "pulse"
version = "0.5.3"
version = "0.5.4"
authors = ["Colin Sherratt <[email protected]>"]
license = "Apache-2.0"
description = "A library for async wake signals"
homepage = "https://github.com/csherratt/pulse"

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

[features]
default = []
Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

extern crate atom;
extern crate time;

use std::sync::atomic::AtomicUsize;
use std::thread;
Expand All @@ -24,9 +23,10 @@ use std::sync::atomic::Ordering;
use std::cell::RefCell;

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

use std::time::{Duration,Instant};

pub use select::{Select, SelectMap};
pub use barrier::Barrier;
mod select;
Expand Down Expand Up @@ -517,17 +517,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 now = Instant::now();
let total = Duration::from_millis(ms as _);

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 = now.elapsed();
if elapsed > total {
return Err(TimeoutError::Timeout);
}
thread::park_timeout_ms((end - now) as u32);
thread::park_timeout(total - elapsed);
}
signal.remove_from_waitlist(id);

Expand Down