Skip to content

Commit

Permalink
De-mode comm::Chan
Browse files Browse the repository at this point in the history
  • Loading branch information
catamorphism committed Oct 4, 2012
1 parent 777baeb commit fe12da0
Show file tree
Hide file tree
Showing 63 changed files with 173 additions and 173 deletions.
6 changes: 3 additions & 3 deletions doc/rust.md
Expand Up @@ -2952,7 +2952,7 @@ An example of a `spawn` call:


~~~~ ~~~~
let po = comm::Port(); let po = comm::Port();
let ch = comm::Chan(po); let ch = comm::Chan(&po);
do task::spawn { do task::spawn {
// let task run, do other things // let task run, do other things
Expand All @@ -2974,7 +2974,7 @@ An example of a send:


~~~~ ~~~~
let po = comm::Port(); let po = comm::Port();
let ch = comm::Chan(po); let ch = comm::Chan(&po);
comm::send(ch, ~"hello, world"); comm::send(ch, ~"hello, world");
~~~~ ~~~~


Expand All @@ -2990,7 +2990,7 @@ An example of a *receive*:


~~~~~~~~ ~~~~~~~~
# let po = comm::Port(); # let po = comm::Port();
# let ch = comm::Chan(po); # let ch = comm::Chan(&po);
# comm::send(ch, ~""); # comm::send(ch, ~"");
let s = comm::recv(po); let s = comm::recv(po);
~~~~~~~~ ~~~~~~~~
Expand Down
44 changes: 22 additions & 22 deletions src/libcore/comm.rs
Expand Up @@ -32,8 +32,8 @@ will once again be the preferred module for intertask communication.
*/ */


// NB: transitionary, de-mode-ing // NB: transitionary, de-mode-ing.
// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)]; #[forbid(deprecated_pattern)];


use either::Either; use either::Either;
Expand Down Expand Up @@ -74,7 +74,7 @@ pub fn Port<T: Send>() -> Port<T> {


impl<T: Send> Port<T> { impl<T: Send> Port<T> {


fn chan() -> Chan<T> { Chan(self) } fn chan() -> Chan<T> { Chan(&self) }
fn send(v: T) { self.chan().send(move v) } fn send(v: T) { self.chan().send(move v) }
fn recv() -> T { recv(self) } fn recv() -> T { recv(self) }
fn peek() -> bool { peek(self) } fn peek() -> bool { peek(self) }
Expand Down Expand Up @@ -166,7 +166,7 @@ fn as_raw_port<T: Send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
* Constructs a channel. The channel is bound to the port used to * Constructs a channel. The channel is bound to the port used to
* construct it. * construct it.
*/ */
pub fn Chan<T: Send>(&&p: Port<T>) -> Chan<T> { pub fn Chan<T: Send>(p: &Port<T>) -> Chan<T> {
Chan_(rustrt::get_port_id((**p).po)) Chan_(rustrt::get_port_id((**p).po))
} }


Expand Down Expand Up @@ -304,51 +304,51 @@ extern mod rusti {




#[test] #[test]
fn create_port_and_chan() { let p = Port::<int>(); Chan(p); } fn create_port_and_chan() { let p = Port::<int>(); Chan(&p); }


#[test] #[test]
fn send_int() { fn send_int() {
let p = Port::<int>(); let p = Port::<int>();
let c = Chan(p); let c = Chan(&p);
send(c, 22); send(c, 22);
} }


#[test] #[test]
fn send_recv_fn() { fn send_recv_fn() {
let p = Port::<int>(); let p = Port::<int>();
let c = Chan::<int>(p); let c = Chan::<int>(&p);
send(c, 42); send(c, 42);
assert (recv(p) == 42); assert (recv(p) == 42);
} }


#[test] #[test]
fn send_recv_fn_infer() { fn send_recv_fn_infer() {
let p = Port(); let p = Port();
let c = Chan(p); let c = Chan(&p);
send(c, 42); send(c, 42);
assert (recv(p) == 42); assert (recv(p) == 42);
} }


#[test] #[test]
fn chan_chan_infer() { fn chan_chan_infer() {
let p = Port(), p2 = Port::<int>(); let p = Port(), p2 = Port::<int>();
let c = Chan(p); let c = Chan(&p);
send(c, Chan(p2)); send(c, Chan(&p2));
recv(p); recv(p);
} }


#[test] #[test]
fn chan_chan() { fn chan_chan() {
let p = Port::<Chan<int>>(), p2 = Port::<int>(); let p = Port::<Chan<int>>(), p2 = Port::<int>();
let c = Chan(p); let c = Chan(&p);
send(c, Chan(p2)); send(c, Chan(&p2));
recv(p); recv(p);
} }


#[test] #[test]
fn test_peek() { fn test_peek() {
let po = Port(); let po = Port();
let ch = Chan(po); let ch = Chan(&po);
assert !peek(po); assert !peek(po);
send(ch, ()); send(ch, ());
assert peek(po); assert peek(po);
Expand All @@ -360,8 +360,8 @@ fn test_peek() {
fn test_select2_available() { fn test_select2_available() {
let po_a = Port(); let po_a = Port();
let po_b = Port(); let po_b = Port();
let ch_a = Chan(po_a); let ch_a = Chan(&po_a);
let ch_b = Chan(po_b); let ch_b = Chan(&po_b);


send(ch_a, ~"a"); send(ch_a, ~"a");


Expand All @@ -376,8 +376,8 @@ fn test_select2_available() {
fn test_select2_rendezvous() { fn test_select2_rendezvous() {
let po_a = Port(); let po_a = Port();
let po_b = Port(); let po_b = Port();
let ch_a = Chan(po_a); let ch_a = Chan(&po_a);
let ch_b = Chan(po_b); let ch_b = Chan(&po_b);
for iter::repeat(10) { for iter::repeat(10) {
do task::spawn { do task::spawn {
Expand All @@ -400,8 +400,8 @@ fn test_select2_rendezvous() {
fn test_select2_stress() { fn test_select2_stress() {
let po_a = Port(); let po_a = Port();
let po_b = Port(); let po_b = Port();
let ch_a = Chan(po_a); let ch_a = Chan(&po_a);
let ch_b = Chan(po_b); let ch_b = Chan(&po_b);
let msgs = 100; let msgs = 100;
let times = 4u; let times = 4u;
Expand Down Expand Up @@ -436,7 +436,7 @@ fn test_select2_stress() {
#[test] #[test]
fn test_recv_chan() { fn test_recv_chan() {
let po = Port(); let po = Port();
let ch = Chan(po); let ch = Chan(&po);
send(ch, ~"flower"); send(ch, ~"flower");
assert recv_chan(ch) == ~"flower"; assert recv_chan(ch) == ~"flower";
} }
Expand All @@ -445,7 +445,7 @@ fn test_recv_chan() {
#[should_fail] #[should_fail]
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
fn test_recv_chan_dead() { fn test_recv_chan_dead() {
let ch = Chan(Port()); let ch = Chan(&Port());
send(ch, ~"flower"); send(ch, ~"flower");
recv_chan(ch); recv_chan(ch);
} }
Expand All @@ -454,7 +454,7 @@ fn test_recv_chan_dead() {
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
fn test_recv_chan_wrong_task() { fn test_recv_chan_wrong_task() {
let po = Port(); let po = Port();
let ch = Chan(po); let ch = Chan(&po);
send(ch, ~"flower"); send(ch, ~"flower");
assert result::is_err(&task::try(|| assert result::is_err(&task::try(||
recv_chan(ch) recv_chan(ch)
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/option.rs
Expand Up @@ -326,10 +326,10 @@ impl<T: Eq> Option<T> : Eq {
#[test] #[test]
fn test_unwrap_ptr() { fn test_unwrap_ptr() {
let x = ~0; let x = ~0;
let addr_x = ptr::p2::addr_of(&(*x)); let addr_x = ptr::addr_of(&(*x));
let opt = Some(x); let opt = Some(x);
let y = unwrap(opt); let y = unwrap(opt);
let addr_y = ptr::p2::addr_of(&(*y)); let addr_y = ptr::addr_of(&(*y));
assert addr_x == addr_y; assert addr_x == addr_y;
} }


Expand Down
6 changes: 3 additions & 3 deletions src/libcore/os.rs
Expand Up @@ -132,7 +132,7 @@ mod global_env {
let env_ch = get_global_env_chan(); let env_ch = get_global_env_chan();
let po = comm::Port(); let po = comm::Port();
comm::send(env_ch, MsgGetEnv(str::from_slice(n), comm::send(env_ch, MsgGetEnv(str::from_slice(n),
comm::Chan(po))); comm::Chan(&po)));
comm::recv(po) comm::recv(po)
} }


Expand All @@ -141,14 +141,14 @@ mod global_env {
let po = comm::Port(); let po = comm::Port();
comm::send(env_ch, MsgSetEnv(str::from_slice(n), comm::send(env_ch, MsgSetEnv(str::from_slice(n),
str::from_slice(v), str::from_slice(v),
comm::Chan(po))); comm::Chan(&po)));
comm::recv(po) comm::recv(po)
} }


pub fn env() -> ~[(~str,~str)] { pub fn env() -> ~[(~str,~str)] {
let env_ch = get_global_env_chan(); let env_ch = get_global_env_chan();
let po = comm::Port(); let po = comm::Port();
comm::send(env_ch, MsgEnv(comm::Chan(po))); comm::send(env_ch, MsgEnv(comm::Chan(&po)));
comm::recv(po) comm::recv(po)
} }


Expand Down
16 changes: 8 additions & 8 deletions src/libcore/private.rs
Expand Up @@ -63,7 +63,7 @@ pub unsafe fn chan_from_global_ptr<T: Send>(
let (setup_po, setup_ch) = do task_fn().spawn_conversation let (setup_po, setup_ch) = do task_fn().spawn_conversation
|move f, setup_po, setup_ch| { |move f, setup_po, setup_ch| {
let po = comm::Port::<T>(); let po = comm::Port::<T>();
let ch = comm::Chan(po); let ch = comm::Chan(&po);
comm::send(setup_ch, ch); comm::send(setup_ch, ch);
// Wait to hear if we are the official instance of // Wait to hear if we are the official instance of
Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn test_from_global_chan1() {


// The global channel // The global channel
let globchan = 0; let globchan = 0;
let globchanp = ptr::p2::addr_of(&globchan); let globchanp = ptr::addr_of(&globchan);


// Create the global channel, attached to a new task // Create the global channel, attached to a new task
let ch = unsafe { let ch = unsafe {
Expand All @@ -122,7 +122,7 @@ pub fn test_from_global_chan1() {
}; };
// Talk to it // Talk to it
let po = comm::Port(); let po = comm::Port();
comm::send(ch, comm::Chan(po)); comm::send(ch, comm::Chan(&po));
assert comm::recv(po) == true; assert comm::recv(po) == true;


// This one just reuses the previous channel // This one just reuses the previous channel
Expand All @@ -135,7 +135,7 @@ pub fn test_from_global_chan1() {


// Talk to the original global task // Talk to the original global task
let po = comm::Port(); let po = comm::Port();
comm::send(ch, comm::Chan(po)); comm::send(ch, comm::Chan(&po));
assert comm::recv(po) == true; assert comm::recv(po) == true;
} }


Expand All @@ -145,10 +145,10 @@ pub fn test_from_global_chan2() {
for iter::repeat(100) { for iter::repeat(100) {
// The global channel // The global channel
let globchan = 0; let globchan = 0;
let globchanp = ptr::p2::addr_of(&globchan); let globchanp = ptr::addr_of(&globchan);


let resultpo = comm::Port(); let resultpo = comm::Port();
let resultch = comm::Chan(resultpo); let resultch = comm::Chan(&resultpo);


// Spawn a bunch of tasks that all want to compete to // Spawn a bunch of tasks that all want to compete to
// create the global channel // create the global channel
Expand All @@ -165,7 +165,7 @@ pub fn test_from_global_chan2() {
} }
}; };
let po = comm::Port(); let po = comm::Port();
comm::send(ch, comm::Chan(po)); comm::send(ch, comm::Chan(&po));
// We are The winner if our version of the // We are The winner if our version of the
// task was installed // task was installed
let winner = comm::recv(po); let winner = comm::recv(po);
Expand Down Expand Up @@ -203,7 +203,7 @@ pub fn test_from_global_chan2() {
*/ */
pub unsafe fn weaken_task(f: fn(comm::Port<()>)) { pub unsafe fn weaken_task(f: fn(comm::Port<()>)) {
let po = comm::Port(); let po = comm::Port();
let ch = comm::Chan(po); let ch = comm::Chan(&po);
unsafe { unsafe {
rustrt::rust_task_weaken(cast::reinterpret_cast(&ch)); rustrt::rust_task_weaken(cast::reinterpret_cast(&ch));
} }
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/run.rs
Expand Up @@ -296,7 +296,7 @@ pub fn program_output(prog: &str, args: &[~str]) ->
// or the other. FIXME (#2625): Surely there's a much more // or the other. FIXME (#2625): Surely there's a much more
// clever way to do this. // clever way to do this.
let p = comm::Port(); let p = comm::Port();
let ch = comm::Chan(p); let ch = comm::Chan(&p);
do task::spawn_sched(task::SingleThreaded) { do task::spawn_sched(task::SingleThreaded) {
let errput = readclose(pipe_err.in); let errput = readclose(pipe_err.in);
comm::send(ch, (2, move errput)); comm::send(ch, (2, move errput));
Expand Down

0 comments on commit fe12da0

Please sign in to comment.