Swap return value of pipes::init Fixes #4501
This commit is contained in:
parent
24e85ac82d
commit
ecd08b989a
@ -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 {
|
||||
@ -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))
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
@ -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)
|
||||
@ -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
|
||||
@ -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)
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
@ -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);
|
||||
@ -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),
|
||||
|
@ -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();
|
||||
@ -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 || {
|
||||
|
@ -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.
|
||||
@ -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.
|
||||
|
@ -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]);
|
||||
|
@ -15,7 +15,7 @@ proto! stream (
|
||||
)
|
||||
|
||||
pub fn main() {
|
||||
let (bc, _bp) = stream::init();
|
||||
let (_bp, bc) = stream::init();
|
||||
|
||||
stream::client::send(bc, ~"abc");
|
||||
}
|
||||
|
@ -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()) {
|
||||
@ -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!();
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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 {
|
||||
@ -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 {
|
||||
|
@ -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_);
|
||||
|
||||
|
@ -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.
|
||||
@ -83,8 +83,8 @@ 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));
|
||||
|
||||
@ -92,8 +92,8 @@ pub fn main() {
|
||||
|
||||
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));
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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");
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user