Skip to content
Merged
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
14 changes: 13 additions & 1 deletion src/libstd/sync/mpsc/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use sync::Arc;
use marker::{Sync, Send};
use mem;
use clone::Clone;
use time::Instant;

struct Inner {
thread: Thread,
Expand Down Expand Up @@ -74,7 +75,6 @@ impl SignalToken {
pub unsafe fn cast_from_usize(signal_ptr: usize) -> SignalToken {
SignalToken { inner: mem::transmute(signal_ptr) }
}

}

impl WaitToken {
Expand All @@ -83,4 +83,16 @@ impl WaitToken {
thread::park()
}
}

/// Returns true if we wake up normally, false otherwise.
pub fn wait_max_until(self, end: Instant) -> bool {
while !self.inner.woken.load(Ordering::SeqCst) {
let now = Instant::now();
if now >= end {
return false;
}
thread::park_timeout(end - now)
}
true
}
}
Loading