Skip to content

Commit

Permalink
auto merge of #6896 : nickdesaulniers/rust/issue4501, r=brson
Browse files Browse the repository at this point in the history
review? @brson
  • Loading branch information
bors committed Jun 2, 2013
2 parents 14c3310 + ecd08b9 commit c354a0c
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 64 deletions.
12 changes: 6 additions & 6 deletions src/libstd/comm.rs
Expand Up @@ -376,7 +376,7 @@ mod pipesy {
priv use core::kinds::Owned;
use ptr::to_mut_unsafe_ptr;

pub fn init<T: Owned>() -> (client::Oneshot<T>, server::Oneshot<T>) {
pub fn init<T: Owned>() -> (server::Oneshot<T>, client::Oneshot<T>) {
pub use core::pipes::HasBuffer;

let buffer = ~::core::pipes::Buffer {
Expand Down Expand Up @@ -466,7 +466,7 @@ mod pipesy {

/// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair.
pub fn oneshot<T: Owned>() -> (PortOne<T>, ChanOne<T>) {
let (chan, port) = oneshot::init();
let (port, chan) = oneshot::init();
(PortOne::new(port), ChanOne::new(chan))
}

Expand Down Expand Up @@ -550,7 +550,7 @@ mod pipesy {
pub mod streamp {
priv use core::kinds::Owned;

pub fn init<T: Owned>() -> (client::Open<T>, server::Open<T>) {
pub fn init<T: Owned>() -> (server::Open<T>, client::Open<T>) {
pub use core::pipes::HasBuffer;
::core::pipes::entangle()
}
Expand All @@ -567,7 +567,7 @@ mod pipesy {
::core::option::Option<Open<T>> {
{
use super::data;
let (c, s) = ::core::pipes::entangle();
let (s, c) = ::core::pipes::entangle();
let message = data(x_0, s);
if ::core::pipes::send(pipe, message) {
::core::pipes::rt::make_some(c)
Expand All @@ -579,7 +579,7 @@ mod pipesy {
pub fn data<T: Owned>(pipe: Open<T>, x_0: T) -> Open<T> {
{
use super::data;
let (c, s) = ::core::pipes::entangle();
let (s, c) = ::core::pipes::entangle();
let message = data(x_0, s);
::core::pipes::send(pipe, message);
c
Expand Down Expand Up @@ -615,7 +615,7 @@ mod pipesy {
*/
pub fn stream<T:Owned>() -> (Port<T>, Chan<T>) {
let (c, s) = streamp::init();
let (s, c) = streamp::init();

(Port {
endp: Some(s)
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/pipes.rs
Expand Up @@ -237,11 +237,11 @@ pub fn packet<T>() -> *mut Packet<T> {
pub fn entangle_buffer<T:Owned,Tstart:Owned>(
mut buffer: ~Buffer<T>,
init: &fn(*libc::c_void, x: &mut T) -> *mut Packet<Tstart>)
-> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>) {
-> (RecvPacketBuffered<Tstart, T>, SendPacketBuffered<Tstart, T>) {
unsafe {
let p = init(transmute_copy(&buffer), &mut buffer.data);
forget(buffer);
(SendPacketBuffered(p), RecvPacketBuffered(p))
(RecvPacketBuffered(p), SendPacketBuffered(p))
}
}

Expand Down Expand Up @@ -775,9 +775,9 @@ pub fn RecvPacketBuffered<T,Tbuffer>(p: *mut Packet<T>)
}
}

pub fn entangle<T>() -> (SendPacket<T>, RecvPacket<T>) {
pub fn entangle<T>() -> (RecvPacket<T>, SendPacket<T>) {
let p = packet();
(SendPacket(p), RecvPacket(p))
(RecvPacket(p), SendPacket(p))
}

/** Receives a message from one of two endpoints.
Expand Down
31 changes: 7 additions & 24 deletions src/libsyntax/ext/pipes/pipec.rs
Expand Up @@ -89,10 +89,10 @@ impl gen_send for message {
}
else {
let pat = match (this.dir, next.dir) {
(send, send) => "(c, s)",
(send, recv) => "(s, c)",
(recv, send) => "(s, c)",
(recv, recv) => "(c, s)"
(send, send) => "(s, c)",
(send, recv) => "(c, s)",
(recv, send) => "(c, s)",
(recv, recv) => "(s, c)"
};

body += fmt!("let %s = ::std::pipes::entangle();\n", pat);
Expand Down Expand Up @@ -317,30 +317,13 @@ impl gen_init for protocol {
let start_state = self.states[0];

let body = if !self.is_bounded() {
match start_state.dir {
send => quote_expr!( ::std::pipes::entangle() ),
recv => {
quote_expr!({
let (s, c) = ::std::pipes::entangle();
(c, s)
})
}
}
quote_expr!( ::std::pipes::entangle() )
}
else {
let body = self.gen_init_bounded(ext_cx);
match start_state.dir {
send => body,
recv => {
quote_expr!({
let (s, c) = $body;
(c, s)
})
}
}
self.gen_init_bounded(ext_cx)
};

cx.parse_item(fmt!("pub fn init%s() -> (client::%s, server::%s)\
cx.parse_item(fmt!("pub fn init%s() -> (server::%s, client::%s)\
{ pub use std::pipes::HasBuffer; %s }",
start_state.generics.to_source(cx),
start_state.to_ty(cx).to_source(cx),
Expand Down
4 changes: 2 additions & 2 deletions src/test/bench/msgsend-ring-pipes.rs
Expand Up @@ -73,7 +73,7 @@ fn main() {
let num_tasks = uint::from_str(args[1]).get();
let msg_per_task = uint::from_str(args[2]).get();

let (num_chan, num_port) = ring::init();
let (num_port, num_chan) = ring::init();
let mut num_chan = Cell(num_chan);

let start = time::precise_time_s();
Expand All @@ -83,7 +83,7 @@ fn main() {

for uint::range(1u, num_tasks) |i| {
//error!("spawning %?", i);
let (new_chan, num_port) = ring::init();
let (num_port, new_chan) = ring::init();
let num_chan2 = Cell(num_chan.take());
let num_port = Cell(num_port);
let new_future = do future::spawn || {
Expand Down
12 changes: 6 additions & 6 deletions src/test/bench/pingpong.rs
Expand Up @@ -83,11 +83,11 @@ endpoint is passed to the new task.
*/
pub fn spawn_service<T:Owned,Tb:Owned>(
init: extern fn() -> (SendPacketBuffered<T, Tb>,
RecvPacketBuffered<T, Tb>),
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
SendPacketBuffered<T, Tb>),
service: ~fn(v: RecvPacketBuffered<T, Tb>))
-> SendPacketBuffered<T, Tb> {
let (client, server) = init();
let (server, client) = init();

// This is some nasty gymnastics required to safely move the pipe
// into a new task.
Expand All @@ -104,11 +104,11 @@ receive state.
*/
pub fn spawn_service_recv<T:Owned,Tb:Owned>(
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
SendPacketBuffered<T, Tb>),
init: extern fn() -> (SendPacketBuffered<T, Tb>,
RecvPacketBuffered<T, Tb>),
service: ~fn(v: SendPacketBuffered<T, Tb>))
-> RecvPacketBuffered<T, Tb> {
let (client, server) = init();
let (server, client) = init();

// This is some nasty gymnastics required to safely move the pipe
// into a new task.
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-2834.rs
Expand Up @@ -18,7 +18,7 @@ proto! streamp (
)

fn rendezvous() {
let (c, s) = streamp::init();
let (s, c) = streamp::init();
let streams: ~[streamp::client::open<int>] = ~[c];

error!("%?", streams[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-2930.rs
Expand Up @@ -15,7 +15,7 @@ proto! stream (
)

pub fn main() {
let (bc, _bp) = stream::init();
let (_bp, bc) = stream::init();

stream::client::send(bc, ~"abc");
}
4 changes: 2 additions & 2 deletions src/test/run-pass/pipe-detect-term.rs
Expand Up @@ -31,7 +31,7 @@ proto! oneshot (
pub fn main() {
let iotask = &uv::global_loop::get();

let (chan, port) = oneshot::init();
let (port, chan) = oneshot::init();
let port = Cell(port);
do spawn {
match try_recv(port.take()) {
Expand All @@ -47,7 +47,7 @@ pub fn main() {

// Make sure the right thing happens during failure.
fn failtest() {
let (c, p) = oneshot::init();
let (p, c) = oneshot::init();

do task::spawn_with(c) |_c| {
fail!();
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/pipe-peek.rs
Expand Up @@ -22,7 +22,7 @@ proto! oneshot (
)

pub fn main() {
let mut (c, p) = oneshot::init();
let mut (p, c) = oneshot::init();

assert!(!pipes::peek(&mut p));

Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/pipe-pingpong-bounded.rs
Expand Up @@ -30,7 +30,7 @@ mod pingpong {
pong: Packet<pong>,
}

pub fn init() -> (client::ping, server::ping) {
pub fn init() -> (server::ping, client::ping) {
let buffer = ~Buffer {
header: BufferHeader(),
data: Packets {
Expand Down Expand Up @@ -112,7 +112,7 @@ mod test {
}

pub fn main() {
let (client_, server_) = ::pingpong::init();
let (server_, client_) = ::pingpong::init();
let client_ = Cell(client_);
let server_ = Cell(server_);
do task::spawn {
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/pipe-pingpong-proto.rs
Expand Up @@ -50,7 +50,7 @@ mod test {
}

pub fn main() {
let (client_, server_) = pingpong::init();
let (server_, client_) = pingpong::init();
let client_ = Cell(client_);
let server_ = Cell(server_);

Expand Down
22 changes: 11 additions & 11 deletions src/test/run-pass/pipe-select.rs
Expand Up @@ -35,11 +35,11 @@ proto! stream (
)

pub fn spawn_service<T:Owned,Tb:Owned>(
init: extern fn() -> (SendPacketBuffered<T, Tb>,
RecvPacketBuffered<T, Tb>),
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
SendPacketBuffered<T, Tb>),
service: ~fn(v: RecvPacketBuffered<T, Tb>))
-> SendPacketBuffered<T, Tb> {
let (client, server) = init();
let (server, client) = init();

// This is some nasty gymnastics required to safely move the pipe
// into a new task.
Expand Down Expand Up @@ -83,17 +83,17 @@ pub fn main() {
}
});

let (c1, p1) = oneshot::init();
let (_c2, p2) = oneshot::init();
let (p1, c1) = oneshot::init();
let (p2, _c2) = oneshot::init();

let c = send(c, (p1, p2));

sleep(iotask, 100);

signal(c1);

let (_c1, p1) = oneshot::init();
let (c2, p2) = oneshot::init();
let (p1, _c1) = oneshot::init();
let (p2, c2) = oneshot::init();

send(c, (p1, p2));

Expand All @@ -105,8 +105,8 @@ pub fn main() {
}

fn test_select2() {
let (ac, ap) = stream::init();
let (bc, bp) = stream::init();
let (ap, ac) = stream::init();
let (bp, bc) = stream::init();

stream::client::send(ac, 42);

Expand All @@ -119,8 +119,8 @@ fn test_select2() {

error!("done with first select2");

let (ac, ap) = stream::init();
let (bc, bp) = stream::init();
let (ap, ac) = stream::init();
let (bp, bc) = stream::init();

stream::client::send(bc, ~"abc");

Expand Down
6 changes: 3 additions & 3 deletions src/test/run-pass/pipe-sleep.rs
Expand Up @@ -34,11 +34,11 @@ endpoint is passed to the new task.
*/
pub fn spawn_service<T:Owned,Tb:Owned>(
init: extern fn() -> (SendPacketBuffered<T, Tb>,
RecvPacketBuffered<T, Tb>),
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
SendPacketBuffered<T, Tb>),
service: ~fn(v: RecvPacketBuffered<T, Tb>))
-> SendPacketBuffered<T, Tb> {
let (client, server) = init();
let (server, client) = init();

// This is some nasty gymnastics required to safely move the pipe
// into a new task.
Expand Down

0 comments on commit c354a0c

Please sign in to comment.