Skip to content

Commit

Permalink
std: sync: Implement recv_timeout()
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Jun 22, 2016
1 parent e41cdab commit b94b158
Show file tree
Hide file tree
Showing 6 changed files with 396 additions and 42 deletions.
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

0 comments on commit b94b158

Please sign in to comment.