Added peek for pipes.

This commit is contained in:
Eric Holk
2012-07-09 15:29:23 -07:00
parent 69cd8b5fcb
commit 1c1b3a3339
2 changed files with 46 additions and 0 deletions

View File

@@ -144,6 +144,15 @@ fn recv<T: send>(-p: recv_packet<T>) -> option<T> {
}
}
/// Returns true if messages are available.
fn peek<T: send>(p: recv_packet<T>) -> bool {
alt p.header().state {
empty { false }
blocked { fail "peeking on blocked packet" }
full | terminated { true }
}
}
fn sender_terminate<T: send>(p: *packet<T>) {
let p = unsafe { uniquify(p) };
alt swap_state_rel(p.header.state, terminated) {
@@ -337,6 +346,20 @@ class recv_packet<T: send> {
p <-> self.p;
option::unwrap(p)
}
fn header() -> &self.packet_header {
alt self.p {
some(packet) {
unsafe {
let packet = uniquify(packet);
let header = reinterpret_cast(&packet.header);
forget(packet);
header
}
}
none { fail "packet already consumed" }
}
}
}
fn entangle<T: send>() -> (send_packet<T>, recv_packet<T>) {