Merge pull request #4190 from brson/oldcomm

Work on removing comm
This commit is contained in:
Brian Anderson 2012-12-14 15:03:20 -08:00
commit 3eb15b80d7
83 changed files with 746 additions and 962 deletions

View File

@ -461,7 +461,7 @@ and child both need to exchange messages with each other. The
function `std::comm::DuplexStream()` supports this pattern. We'll
look briefly at how to use it.
To see how `spawn_conversation()` works, we will create a child task
To see how `DuplexStream()` works, we will create a child task
that repeatedly receives a `uint` message, converts it to a string, and sends
the string in response. The child terminates when it receives `0`.
Here is the function that implements the child task:

View File

@ -139,7 +139,7 @@ pub mod send_map;
/* Tasks and communication */
pub mod comm;
pub mod oldcomm;
#[path = "task/mod.rs"]
pub mod task;
pub mod pipes;

View File

@ -144,7 +144,7 @@ fn PortPtr<T: Owned>(po: *rust_port) -> PortPtr<T> {
* Fails if the port is detached or dead. Fails if the port
* is owned by a different task.
*/
fn as_raw_port<T: Owned, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
fn as_raw_port<T: Owned, U>(ch: Chan<T>, f: fn(*rust_port) -> U) -> U {
struct PortRef {
p: *rust_port,
@ -205,11 +205,11 @@ pub fn recv<T: Owned>(p: Port<T>) -> T { recv_((**p).po) }
pub fn peek<T: Owned>(p: Port<T>) -> bool { peek_((**p).po) }
#[doc(hidden)]
pub fn recv_chan<T: Owned>(ch: comm::Chan<T>) -> T {
pub fn recv_chan<T: Owned>(ch: Chan<T>) -> T {
as_raw_port(ch, |x|recv_(x))
}
fn peek_chan<T: Owned>(ch: comm::Chan<T>) -> bool {
fn peek_chan<T: Owned>(ch: Chan<T>) -> bool {
as_raw_port(ch, |x|peek_(x))
}

View File

@ -133,36 +133,36 @@ mod global_env {
}
enum Msg {
MsgGetEnv(~str, comm::Chan<Option<~str>>),
MsgSetEnv(~str, ~str, comm::Chan<()>),
MsgEnv(comm::Chan<~[(~str,~str)]>)
MsgGetEnv(~str, oldcomm::Chan<Option<~str>>),
MsgSetEnv(~str, ~str, oldcomm::Chan<()>),
MsgEnv(oldcomm::Chan<~[(~str,~str)]>)
}
pub fn getenv(n: &str) -> Option<~str> {
let env_ch = get_global_env_chan();
let po = comm::Port();
comm::send(env_ch, MsgGetEnv(str::from_slice(n),
comm::Chan(&po)));
comm::recv(po)
let po = oldcomm::Port();
oldcomm::send(env_ch, MsgGetEnv(str::from_slice(n),
oldcomm::Chan(&po)));
oldcomm::recv(po)
}
pub fn setenv(n: &str, v: &str) {
let env_ch = get_global_env_chan();
let po = comm::Port();
comm::send(env_ch, MsgSetEnv(str::from_slice(n),
let po = oldcomm::Port();
oldcomm::send(env_ch, MsgSetEnv(str::from_slice(n),
str::from_slice(v),
comm::Chan(&po)));
comm::recv(po)
oldcomm::Chan(&po)));
oldcomm::recv(po)
}
pub fn env() -> ~[(~str,~str)] {
let env_ch = get_global_env_chan();
let po = comm::Port();
comm::send(env_ch, MsgEnv(comm::Chan(&po)));
comm::recv(po)
let po = oldcomm::Port();
oldcomm::send(env_ch, MsgEnv(oldcomm::Chan(&po)));
oldcomm::recv(po)
}
fn get_global_env_chan() -> comm::Chan<Msg> {
fn get_global_env_chan() -> oldcomm::Chan<Msg> {
let global_ptr = rustrt::rust_global_env_chan_ptr();
unsafe {
private::chan_from_global_ptr(global_ptr, || {
@ -173,19 +173,19 @@ mod global_env {
}
}
fn global_env_task(msg_po: comm::Port<Msg>) {
fn global_env_task(msg_po: oldcomm::Port<Msg>) {
unsafe {
do private::weaken_task |weak_po| {
loop {
match comm::select2(msg_po, weak_po) {
match oldcomm::select2(msg_po, weak_po) {
either::Left(MsgGetEnv(ref n, resp_ch)) => {
comm::send(resp_ch, impl_::getenv(*n))
oldcomm::send(resp_ch, impl_::getenv(*n))
}
either::Left(MsgSetEnv(ref n, ref v, resp_ch)) => {
comm::send(resp_ch, impl_::setenv(*n, *v))
oldcomm::send(resp_ch, impl_::setenv(*n, *v))
}
either::Left(MsgEnv(resp_ch)) => {
comm::send(resp_ch, impl_::env())
oldcomm::send(resp_ch, impl_::env())
}
either::Right(_) => break
}

View File

@ -55,8 +55,8 @@ fn compare_and_swap(address: &mut int, oldval: int, newval: int) -> bool {
pub unsafe fn chan_from_global_ptr<T: Owned>(
global: GlobalPtr,
task_fn: fn() -> task::TaskBuilder,
f: fn~(comm::Port<T>)
) -> comm::Chan<T> {
f: fn~(oldcomm::Port<T>)
) -> oldcomm::Chan<T> {
enum Msg {
Proceed,
@ -70,15 +70,21 @@ pub unsafe fn chan_from_global_ptr<T: Owned>(
log(debug,~"is probably zero...");
// There's no global channel. We must make it
let (setup_po, setup_ch) = do task_fn().spawn_conversation
|move f, setup_po, setup_ch| {
let po = comm::Port::<T>();
let ch = comm::Chan(&po);
comm::send(setup_ch, ch);
let (setup1_po, setup1_ch) = pipes::stream();
let (setup2_po, setup2_ch) = pipes::stream();
// XXX: Ugly type inference hints
let setup1_po: pipes::Port<oldcomm::Chan<T>> = setup1_po;
let setup2_po: pipes::Port<Msg> = setup2_po;
do task_fn().spawn |move f, move setup1_ch, move setup2_po| {
let po = oldcomm::Port::<T>();
let ch = oldcomm::Chan(&po);
setup1_ch.send(ch);
// Wait to hear if we are the official instance of
// this global task
match comm::recv::<Msg>(setup_po) {
match setup2_po.recv() {
Proceed => f(move po),
Abort => ()
}
@ -86,7 +92,7 @@ pub unsafe fn chan_from_global_ptr<T: Owned>(
log(debug,~"before setup recv..");
// This is the proposed global channel
let ch = comm::recv(setup_po);
let ch = setup1_po.recv();
// 0 is our sentinal value. It is not a valid channel
assert *ch != 0;
@ -99,11 +105,11 @@ pub unsafe fn chan_from_global_ptr<T: Owned>(
if swapped {
// Success!
comm::send(setup_ch, Proceed);
setup2_ch.send(Proceed);
ch
} else {
// Somebody else got in before we did
comm::send(setup_ch, Abort);
setup2_ch.send(Abort);
cast::reinterpret_cast(&*global)
}
} else {
@ -124,29 +130,29 @@ pub fn test_from_global_chan1() {
// Create the global channel, attached to a new task
let ch = unsafe {
do chan_from_global_ptr(globchanp, task::task) |po| {
let ch = comm::recv(po);
comm::send(ch, true);
let ch = comm::recv(po);
comm::send(ch, true);
let ch = oldcomm::recv(po);
oldcomm::send(ch, true);
let ch = oldcomm::recv(po);
oldcomm::send(ch, true);
}
};
// Talk to it
let po = comm::Port();
comm::send(ch, comm::Chan(&po));
assert comm::recv(po) == true;
let po = oldcomm::Port();
oldcomm::send(ch, oldcomm::Chan(&po));
assert oldcomm::recv(po) == true;
// This one just reuses the previous channel
let ch = unsafe {
do chan_from_global_ptr(globchanp, task::task) |po| {
let ch = comm::recv(po);
comm::send(ch, false);
let ch = oldcomm::recv(po);
oldcomm::send(ch, false);
}
};
// Talk to the original global task
let po = comm::Port();
comm::send(ch, comm::Chan(&po));
assert comm::recv(po) == true;
let po = oldcomm::Port();
oldcomm::send(ch, oldcomm::Chan(&po));
assert oldcomm::recv(po) == true;
}
#[test]
@ -157,8 +163,8 @@ pub fn test_from_global_chan2() {
let globchan = 0;
let globchanp = ptr::addr_of(&globchan);
let resultpo = comm::Port();
let resultch = comm::Chan(&resultpo);
let resultpo = oldcomm::Port();
let resultch = oldcomm::Chan(&resultpo);
// Spawn a bunch of tasks that all want to compete to
// create the global channel
@ -169,23 +175,23 @@ pub fn test_from_global_chan2() {
globchanp, task::task) |po| {
for uint::range(0, 10) |_j| {
let ch = comm::recv(po);
comm::send(ch, {i});
let ch = oldcomm::recv(po);
oldcomm::send(ch, {i});
}
}
};
let po = comm::Port();
comm::send(ch, comm::Chan(&po));
let po = oldcomm::Port();
oldcomm::send(ch, oldcomm::Chan(&po));
// We are The winner if our version of the
// task was installed
let winner = comm::recv(po);
comm::send(resultch, winner == i);
let winner = oldcomm::recv(po);
oldcomm::send(resultch, winner == i);
}
}
// There should be only one winner
let mut winners = 0u;
for uint::range(0u, 10u) |_i| {
let res = comm::recv(resultpo);
let res = oldcomm::recv(resultpo);
if res { winners += 1u };
}
assert winners == 1u;
@ -211,9 +217,9 @@ pub fn test_from_global_chan2() {
* * Weak tasks must not be supervised. A supervised task keeps
* a reference to its parent, so the parent will not die.
*/
pub unsafe fn weaken_task(f: fn(comm::Port<()>)) {
let po = comm::Port();
let ch = comm::Chan(&po);
pub unsafe fn weaken_task(f: fn(oldcomm::Port<()>)) {
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
unsafe {
rustrt::rust_task_weaken(cast::reinterpret_cast(&ch));
}
@ -221,13 +227,13 @@ pub unsafe fn weaken_task(f: fn(comm::Port<()>)) {
f(po);
struct Unweaken {
ch: comm::Chan<()>,
ch: oldcomm::Chan<()>,
drop unsafe {
rustrt::rust_task_unweaken(cast::reinterpret_cast(&self.ch));
}
}
fn Unweaken(ch: comm::Chan<()>) -> Unweaken {
fn Unweaken(ch: oldcomm::Chan<()>) -> Unweaken {
Unweaken {
ch: ch
}
@ -249,7 +255,7 @@ pub fn test_weaken_task_wait() {
do task::spawn_unlinked {
unsafe {
do weaken_task |po| {
comm::recv(po);
oldcomm::recv(po);
}
}
}
@ -269,7 +275,7 @@ pub fn test_weaken_task_stress() {
unsafe {
do weaken_task |po| {
// Wait for it to tell us to die
comm::recv(po);
oldcomm::recv(po);
}
}
}

View File

@ -307,22 +307,22 @@ pub fn program_output(prog: &str, args: &[~str]) ->
// in parallel so we don't deadlock while blocking on one
// or the other. FIXME (#2625): Surely there's a much more
// clever way to do this.
let p = comm::Port();
let ch = comm::Chan(&p);
let p = oldcomm::Port();
let ch = oldcomm::Chan(&p);
do task::spawn_sched(task::SingleThreaded) {
let errput = readclose(pipe_err.in);
comm::send(ch, (2, move errput));
oldcomm::send(ch, (2, move errput));
};
do task::spawn_sched(task::SingleThreaded) {
let output = readclose(pipe_out.in);
comm::send(ch, (1, move output));
oldcomm::send(ch, (1, move output));
};
let status = run::waitpid(pid);
let mut errs = ~"";
let mut outs = ~"";
let mut count = 2;
while count > 0 {
let stream = comm::recv(p);
let stream = oldcomm::recv(p);
match stream {
(1, copy s) => {
outs = move s;

View File

@ -433,43 +433,6 @@ impl TaskBuilder {
}
}
/**
* Runs a new task while providing a channel from the parent to the child
*
* Sets up a communication channel from the current task to the new
* child task, passes the port to child's body, and returns a channel
* linked to the port to the parent.
*
* This encapsulates some boilerplate handshaking logic that would
* otherwise be required to establish communication from the parent
* to the child.
*/
fn spawn_listener<A: Owned>(f: fn~(comm::Port<A>)) -> comm::Chan<A> {
let setup_po = comm::Port();
let setup_ch = comm::Chan(&setup_po);
do self.spawn |move f| {
let po = comm::Port();
let ch = comm::Chan(&po);
comm::send(setup_ch, ch);
f(move po);
}
comm::recv(setup_po)
}
/**
* Runs a new task, setting up communication in both directions
*/
fn spawn_conversation<A: Owned, B: Owned>
(f: fn~(comm::Port<A>, comm::Chan<B>))
-> (comm::Port<B>, comm::Chan<A>) {
let from_child = comm::Port();
let to_parent = comm::Chan(&from_child);
let to_child = do self.spawn_listener |move f, from_parent| {
f(from_parent, to_parent)
};
(from_child, to_child)
}
/**
* Execute a function in another task and return either the return value
* of the function or result::err.
@ -484,18 +447,18 @@ impl TaskBuilder {
* Fails if a future_result was already set for this task.
*/
fn try<T: Owned>(f: fn~() -> T) -> Result<T,()> {
let po = comm::Port();
let ch = comm::Chan(&po);
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
let mut result = None;
let fr_task_builder = self.future_result(|+r| {
result = Some(move r);
});
do fr_task_builder.spawn |move f| {
comm::send(ch, f());
oldcomm::send(ch, f());
}
match option::unwrap(move result).recv() {
Success => result::Ok(comm::recv(po)),
Success => result::Ok(oldcomm::recv(po)),
Failure => result::Err(())
}
}
@ -567,28 +530,6 @@ pub fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
task().spawn_with(move arg, move f)
}
pub fn spawn_listener<A:Owned>(f: fn~(comm::Port<A>)) -> comm::Chan<A> {
/*!
* Runs a new task while providing a channel from the parent to the child
*
* This function is equivalent to `task().spawn_listener(f)`.
*/
task().spawn_listener(move f)
}
pub fn spawn_conversation<A: Owned, B: Owned>
(f: fn~(comm::Port<A>, comm::Chan<B>))
-> (comm::Port<B>, comm::Chan<A>) {
/*!
* Runs a new task, setting up communication in both directions
*
* This function is equivalent to `task().spawn_conversation(f)`.
*/
task().spawn_conversation(move f)
}
pub fn spawn_sched(mode: SchedMode, f: fn~()) {
/*!
* Creates a new scheduler and executes a task on it
@ -738,17 +679,17 @@ fn test_cant_dup_task_builder() {
#[test] #[ignore(cfg(windows))]
fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port
let po = comm::Port();
let ch = comm::Chan(&po);
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
do spawn_unlinked {
do spawn_unlinked {
// Give middle task a chance to fail-but-not-kill-us.
for iter::repeat(16) { task::yield(); }
comm::send(ch, ()); // If killed first, grandparent hangs.
oldcomm::send(ch, ()); // If killed first, grandparent hangs.
}
fail; // Shouldn't kill either (grand)parent or (grand)child.
}
comm::recv(po);
oldcomm::recv(po);
}
#[test] #[ignore(cfg(windows))]
fn test_spawn_unlinked_unsup_no_fail_up() { // child unlinked fails
@ -768,8 +709,8 @@ fn test_spawn_unlinked_sup_fail_down() {
#[test] #[should_fail] #[ignore(cfg(windows))]
fn test_spawn_linked_sup_fail_up() { // child fails; parent fails
let po = comm::Port::<()>();
let _ch = comm::Chan(&po);
let po = oldcomm::Port::<()>();
let _ch = oldcomm::Chan(&po);
// Unidirectional "parenting" shouldn't override bidirectional linked.
// We have to cheat with opts - the interface doesn't support them because
// they don't make sense (redundant with task().supervised()).
@ -787,7 +728,7 @@ fn test_spawn_linked_sup_fail_up() { // child fails; parent fails
.. b0
};
do b1.spawn { fail; }
comm::recv(po); // We should get punted awake
oldcomm::recv(po); // We should get punted awake
}
#[test] #[should_fail] #[ignore(cfg(windows))]
fn test_spawn_linked_sup_fail_down() { // parent fails; child fails
@ -811,11 +752,11 @@ fn test_spawn_linked_sup_fail_down() { // parent fails; child fails
}
#[test] #[should_fail] #[ignore(cfg(windows))]
fn test_spawn_linked_unsup_fail_up() { // child fails; parent fails
let po = comm::Port::<()>();
let _ch = comm::Chan(&po);
let po = oldcomm::Port::<()>();
let _ch = oldcomm::Chan(&po);
// Default options are to spawn linked & unsupervised.
do spawn { fail; }
comm::recv(po); // We should get punted awake
oldcomm::recv(po); // We should get punted awake
}
#[test] #[should_fail] #[ignore(cfg(windows))]
fn test_spawn_linked_unsup_fail_down() { // parent fails; child fails
@ -883,27 +824,27 @@ fn test_spawn_linked_sup_propagate_sibling() {
#[test]
fn test_run_basic() {
let po = comm::Port();
let ch = comm::Chan(&po);
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
do task().spawn {
comm::send(ch, ());
oldcomm::send(ch, ());
}
comm::recv(po);
oldcomm::recv(po);
}
#[test]
fn test_add_wrapper() {
let po = comm::Port();
let ch = comm::Chan(&po);
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
let b0 = task();
let b1 = do b0.add_wrapper |body| {
fn~(move body) {
body();
comm::send(ch, ());
oldcomm::send(ch, ());
}
};
do b1.spawn { }
comm::recv(po);
oldcomm::recv(po);
}
#[test]
@ -926,34 +867,6 @@ fn test_back_to_the_future_result() {
let _ = task().future_result(util::ignore).future_result(util::ignore);
}
#[test]
fn test_spawn_listiner_bidi() {
let po = comm::Port();
let ch = comm::Chan(&po);
let ch = do spawn_listener |po| {
// Now the child has a port called 'po' to read from and
// an environment-captured channel called 'ch'.
let res: ~str = comm::recv(po);
assert res == ~"ping";
comm::send(ch, ~"pong");
};
// Likewise, the parent has both a 'po' and 'ch'
comm::send(ch, ~"ping");
let res: ~str = comm::recv(po);
assert res == ~"pong";
}
#[test]
fn test_spawn_conversation() {
let (recv_str, send_int) = do spawn_conversation |recv_int, send_str| {
let input = comm::recv(recv_int);
let output = int::str(input);
comm::send(send_str, move output);
};
comm::send(send_int, 1);
assert comm::recv(recv_str) == ~"1";
}
#[test]
fn test_try_success() {
match do try {
@ -984,10 +897,10 @@ fn test_spawn_sched_no_threads() {
#[test]
fn test_spawn_sched() {
let po = comm::Port();
let ch = comm::Chan(&po);
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
fn f(i: int, ch: comm::Chan<()>) {
fn f(i: int, ch: oldcomm::Chan<()>) {
let parent_sched_id = rt::rust_get_sched_id();
do spawn_sched(SingleThreaded) {
@ -995,7 +908,7 @@ fn test_spawn_sched() {
assert parent_sched_id != child_sched_id;
if (i == 0) {
comm::send(ch, ());
oldcomm::send(ch, ());
} else {
f(i - 1, ch);
}
@ -1003,13 +916,13 @@ fn test_spawn_sched() {
}
f(10, ch);
comm::recv(po);
oldcomm::recv(po);
}
#[test]
fn test_spawn_sched_childs_on_same_sched() {
let po = comm::Port();
let ch = comm::Chan(&po);
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
do spawn_sched(SingleThreaded) {
let parent_sched_id = rt::rust_get_sched_id();
@ -1017,11 +930,11 @@ fn test_spawn_sched_childs_on_same_sched() {
let child_sched_id = rt::rust_get_sched_id();
// This should be on the same scheduler
assert parent_sched_id == child_sched_id;
comm::send(ch, ());
oldcomm::send(ch, ());
};
};
comm::recv(po);
oldcomm::recv(po);
}
#[nolink]
@ -1042,71 +955,71 @@ fn test_spawn_sched_blocking() {
// without affecting other schedulers
for iter::repeat(20u) {
let start_po = comm::Port();
let start_ch = comm::Chan(&start_po);
let fin_po = comm::Port();
let fin_ch = comm::Chan(&fin_po);
let start_po = oldcomm::Port();
let start_ch = oldcomm::Chan(&start_po);
let fin_po = oldcomm::Port();
let fin_ch = oldcomm::Chan(&fin_po);
let lock = testrt::rust_dbg_lock_create();
do spawn_sched(SingleThreaded) {
testrt::rust_dbg_lock_lock(lock);
comm::send(start_ch, ());
oldcomm::send(start_ch, ());
// Block the scheduler thread
testrt::rust_dbg_lock_wait(lock);
testrt::rust_dbg_lock_unlock(lock);
comm::send(fin_ch, ());
oldcomm::send(fin_ch, ());
};
// Wait until the other task has its lock
comm::recv(start_po);
oldcomm::recv(start_po);
fn pingpong(po: comm::Port<int>, ch: comm::Chan<int>) {
fn pingpong(po: oldcomm::Port<int>, ch: oldcomm::Chan<int>) {
let mut val = 20;
while val > 0 {
val = comm::recv(po);
comm::send(ch, val - 1);
val = oldcomm::recv(po);
oldcomm::send(ch, val - 1);
}
}
let setup_po = comm::Port();
let setup_ch = comm::Chan(&setup_po);
let parent_po = comm::Port();
let parent_ch = comm::Chan(&parent_po);
let setup_po = oldcomm::Port();
let setup_ch = oldcomm::Chan(&setup_po);
let parent_po = oldcomm::Port();
let parent_ch = oldcomm::Chan(&parent_po);
do spawn {
let child_po = comm::Port();
comm::send(setup_ch, comm::Chan(&child_po));
let child_po = oldcomm::Port();
oldcomm::send(setup_ch, oldcomm::Chan(&child_po));
pingpong(child_po, parent_ch);
};
let child_ch = comm::recv(setup_po);
comm::send(child_ch, 20);
let child_ch = oldcomm::recv(setup_po);
oldcomm::send(child_ch, 20);
pingpong(parent_po, child_ch);
testrt::rust_dbg_lock_lock(lock);
testrt::rust_dbg_lock_signal(lock);
testrt::rust_dbg_lock_unlock(lock);
comm::recv(fin_po);
oldcomm::recv(fin_po);
testrt::rust_dbg_lock_destroy(lock);
}
}
#[cfg(test)]
fn avoid_copying_the_body(spawnfn: fn(v: fn~())) {
let p = comm::Port::<uint>();
let ch = comm::Chan(&p);
let p = oldcomm::Port::<uint>();
let ch = oldcomm::Chan(&p);
let x = ~1;
let x_in_parent = ptr::addr_of(&(*x)) as uint;
do spawnfn |move x| {
let x_in_child = ptr::addr_of(&(*x)) as uint;
comm::send(ch, x_in_child);
oldcomm::send(ch, x_in_child);
}
let x_in_child = comm::recv(p);
let x_in_child = oldcomm::recv(p);
assert x_in_parent == x_in_child;
}
@ -1115,15 +1028,6 @@ fn test_avoid_copying_the_body_spawn() {
avoid_copying_the_body(spawn);
}
#[test]
fn test_avoid_copying_the_body_spawn_listener() {
do avoid_copying_the_body |f| {
spawn_listener(fn~(move f, _po: comm::Port<int>) {
f();
});
}
}
#[test]
fn test_avoid_copying_the_body_task_spawn() {
do avoid_copying_the_body |f| {
@ -1133,15 +1037,6 @@ fn test_avoid_copying_the_body_task_spawn() {
}
}
#[test]
fn test_avoid_copying_the_body_spawn_listener_1() {
do avoid_copying_the_body |f| {
task().spawn_listener(fn~(move f, _po: comm::Port<int>) {
f();
});
}
}
#[test]
fn test_avoid_copying_the_body_try() {
do avoid_copying_the_body |f| {
@ -1162,19 +1057,19 @@ fn test_avoid_copying_the_body_unlinked() {
#[test]
fn test_platform_thread() {
let po = comm::Port();
let ch = comm::Chan(&po);
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
do task().sched_mode(PlatformThread).spawn {
comm::send(ch, ());
oldcomm::send(ch, ());
}
comm::recv(po);
oldcomm::recv(po);
}
#[test]
#[ignore(cfg(windows))]
#[should_fail]
fn test_unkillable() {
let po = comm::Port();
let po = oldcomm::Port();
let ch = po.chan();
// We want to do this after failing

View File

@ -646,12 +646,12 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
#[test]
fn test_spawn_raw_simple() {
let po = comm::Port();
let ch = comm::Chan(&po);
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
do spawn_raw(default_task_opts()) {
comm::send(ch, ());
oldcomm::send(ch, ());
}
comm::recv(po);
oldcomm::recv(po);
}
#[test]

View File

@ -434,8 +434,8 @@ fails without recording a fatal error then we've encountered a compiler
bug and need to present an error.
*/
fn monitor(+f: fn~(diagnostic::emitter)) {
let p = comm::Port();
let ch = comm::Chan(&p);
let p = oldcomm::Port();
let ch = oldcomm::Chan(&p);
match do task::try |move f| {
@ -444,14 +444,14 @@ fn monitor(+f: fn~(diagnostic::emitter)) {
let demitter = fn@(cmsp: Option<(@codemap::CodeMap, codemap::span)>,
msg: &str, lvl: diagnostic::level) {
if lvl == diagnostic::fatal {
comm::send(ch, fatal);
oldcomm::send(ch, fatal);
}
diagnostic::emit(cmsp, msg, lvl);
};
struct finally {
ch: comm::Chan<monitor_msg>,
drop { comm::send(self.ch, done); }
ch: oldcomm::Chan<monitor_msg>,
drop { oldcomm::send(self.ch, done); }
}
let _finally = finally { ch: ch };
@ -461,7 +461,7 @@ fn monitor(+f: fn~(diagnostic::emitter)) {
result::Ok(_) => { /* fallthrough */ }
result::Err(_) => {
// Task failed without emitting a fatal diagnostic
if comm::recv(p) == done {
if oldcomm::recv(p) == done {
diagnostic::emit(
None,
diagnostic::ice_msg(~"unexpected failure"),

View File

@ -46,7 +46,7 @@ enum Msg {
}
pub enum Srv = {
ch: comm::Chan<Msg>
ch: oldcomm::Chan<Msg>
};
impl Srv: Clone {
@ -64,17 +64,17 @@ pub fn from_file<T>(file: ~str, owner: SrvOwner<T>) -> T {
fn run<T>(owner: SrvOwner<T>, source: ~str, +parse: Parser) -> T {
let srv_ = Srv({
ch: do task::spawn_listener |move parse, po| {
ch: do util::spawn_listener |move parse, po| {
act(po, source, parse);
}
});
let res = owner(srv_);
comm::send(srv_.ch, Exit);
oldcomm::send(srv_.ch, Exit);
move res
}
fn act(po: comm::Port<Msg>, source: ~str, parse: Parser) {
fn act(po: oldcomm::Port<Msg>, source: ~str, parse: Parser) {
let sess = build_session();
let ctxt = build_ctxt(
@ -84,7 +84,7 @@ fn act(po: comm::Port<Msg>, source: ~str, parse: Parser) {
let mut keep_going = true;
while keep_going {
match comm::recv(po) {
match oldcomm::recv(po) {
HandleRequest(f) => {
f(ctxt);
}
@ -99,13 +99,13 @@ pub fn exec<T:Owned>(
srv: Srv,
+f: fn~(ctxt: Ctxt) -> T
) -> T {
let po = comm::Port();
let ch = comm::Chan(&po);
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
let msg = HandleRequest(fn~(move f, ctxt: Ctxt) {
comm::send(ch, f(ctxt))
oldcomm::send(ch, f(ctxt))
});
comm::send(srv.ch, move msg);
comm::recv(po)
oldcomm::send(srv.ch, move msg);
oldcomm::recv(po)
}
fn build_ctxt(sess: Session,

View File

@ -129,7 +129,7 @@ fn should_request_new_writer_for_each_page() {
write_markdown(doc, move writer_factory);
// We expect two pages to have been written
for iter::repeat(2) {
comm::recv(po);
oldcomm::recv(po);
}
}
@ -160,7 +160,7 @@ fn should_write_title_for_each_page() {
let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
write_markdown(doc, move writer_factory);
for iter::repeat(2) {
let (page, markdown) = comm::recv(po);
let (page, markdown) = oldcomm::recv(po);
match page {
doc::CratePage(_) => {
assert str::contains(markdown, ~"% Crate core");
@ -304,7 +304,7 @@ fn should_write_full_path_to_mod() {
assert str::contains(markdown, ~"# Module `a::b::c`");
}
fn write_common(
fn write_oldcommon(
ctxt: &Ctxt,
+desc: Option<~str>,
sections: &[doc::Section]
@ -353,7 +353,7 @@ fn write_mod_contents(
ctxt: &Ctxt,
+doc: doc::ModDoc
) {
write_common(ctxt, doc.desc(), doc.sections());
write_oldcommon(ctxt, doc.desc(), doc.sections());
if doc.index.is_some() {
write_index(ctxt, doc.index.get());
}
@ -456,7 +456,7 @@ fn should_write_index_for_foreign_mods() {
}
fn write_nmod(ctxt: &Ctxt, +doc: doc::NmodDoc) {
write_common(ctxt, doc.desc(), doc.sections());
write_oldcommon(ctxt, doc.desc(), doc.sections());
if doc.index.is_some() {
write_index(ctxt, doc.index.get());
}
@ -507,7 +507,7 @@ fn write_fnlike(
sections: &[doc::Section]
) {
write_sig(ctxt, sig);
write_common(ctxt, desc, sections);
write_oldcommon(ctxt, desc, sections);
}
fn write_sig(ctxt: &Ctxt, +sig: Option<~str>) {
@ -576,7 +576,7 @@ fn write_const(
+doc: doc::ConstDoc
) {
write_sig(ctxt, doc.sig);
write_common(ctxt, doc.desc(), doc.sections());
write_oldcommon(ctxt, doc.desc(), doc.sections());
}
#[test]
@ -597,7 +597,7 @@ fn write_enum(
ctxt: &Ctxt,
+doc: doc::EnumDoc
) {
write_common(ctxt, doc.desc(), doc.sections());
write_oldcommon(ctxt, doc.desc(), doc.sections());
write_variants(ctxt, doc.variants);
}
@ -678,7 +678,7 @@ fn should_write_variant_list_with_signatures() {
}
fn write_trait(ctxt: &Ctxt, +doc: doc::TraitDoc) {
write_common(ctxt, doc.desc(), doc.sections());
write_oldcommon(ctxt, doc.desc(), doc.sections());
write_methods(ctxt, doc.methods);
}
@ -726,7 +726,7 @@ fn should_write_trait_method_signature() {
}
fn write_impl(ctxt: &Ctxt, +doc: doc::ImplDoc) {
write_common(ctxt, doc.desc(), doc.sections());
write_oldcommon(ctxt, doc.desc(), doc.sections());
write_methods(ctxt, doc.methods);
}
@ -768,7 +768,7 @@ fn write_type(
+doc: doc::TyDoc
) {
write_sig(ctxt, doc.sig);
write_common(ctxt, doc.desc(), doc.sections());
write_oldcommon(ctxt, doc.desc(), doc.sections());
}
#[test]
@ -795,7 +795,7 @@ fn write_struct(
+doc: doc::StructDoc
) {
write_sig(ctxt, doc.sig);
write_common(ctxt, doc.desc(), doc.sections());
write_oldcommon(ctxt, doc.desc(), doc.sections());
}
#[test]
@ -854,7 +854,7 @@ mod test {
) -> ~str {
let (writer_factory, po) = markdown_writer::future_writer_factory();
write_markdown(doc, move writer_factory);
return comm::recv(po).second();
return oldcomm::recv(po).second();
}
fn write_markdown_str_srv(
@ -864,7 +864,7 @@ mod test {
let (writer_factory, po) = markdown_writer::future_writer_factory();
let pass = mk_pass(move writer_factory);
(pass.f)(srv, doc);
return comm::recv(po).second();
return oldcomm::recv(po).second();
}
#[test]

View File

@ -151,8 +151,8 @@ fn readclose(fd: libc::c_int) -> ~str {
fn generic_writer(+process: fn~(+markdown: ~str)) -> Writer {
let (setup_po, setup_ch) = pipes::stream();
do task::spawn |move process, move setup_ch| {
let po: comm::Port<WriteInstr> = comm::Port();
let ch = comm::Chan(&po);
let po: oldcomm::Port<WriteInstr> = oldcomm::Port();
let ch = oldcomm::Chan(&po);
setup_ch.send(ch);
let mut markdown = ~"";
@ -168,7 +168,7 @@ fn generic_writer(+process: fn~(+markdown: ~str)) -> Writer {
let ch = setup_po.recv();
fn~(+instr: WriteInstr) {
comm::send(ch, instr);
oldcomm::send(ch, instr);
}
}
@ -275,16 +275,16 @@ fn write_file(path: &Path, +s: ~str) {
}
pub fn future_writer_factory(
) -> (WriterFactory, comm::Port<(doc::Page, ~str)>) {
let markdown_po = comm::Port();
let markdown_ch = comm::Chan(&markdown_po);
) -> (WriterFactory, oldcomm::Port<(doc::Page, ~str)>) {
let markdown_po = oldcomm::Port();
let markdown_ch = oldcomm::Chan(&markdown_po);
let writer_factory = fn~(+page: doc::Page) -> Writer {
let (writer_po, writer_ch) = pipes::stream();
do task::spawn |move writer_ch| {
let (writer, future) = future_writer();
writer_ch.send(move writer);
let s = future.get();
comm::send(markdown_ch, (page, s));
oldcomm::send(markdown_ch, (page, s));
}
writer_po.recv()
};

View File

@ -39,24 +39,24 @@ fn run(
return doc;
}
let (result_port, page_chan) = do task::spawn_conversation
let (result_port, page_chan) = do util::spawn_conversation
|page_port, result_chan| {
comm::send(result_chan, make_doc_from_pages(page_port));
oldcomm::send(result_chan, make_doc_from_pages(page_port));
};
find_pages(doc, page_chan);
comm::recv(result_port)
oldcomm::recv(result_port)
}
type PagePort = comm::Port<Option<doc::Page>>;
type PageChan = comm::Chan<Option<doc::Page>>;
type PagePort = oldcomm::Port<Option<doc::Page>>;
type PageChan = oldcomm::Chan<Option<doc::Page>>;
type NominalPageChan = NominalOp<PageChan>;
fn make_doc_from_pages(page_port: PagePort) -> doc::Doc {
let mut pages = ~[];
loop {
let val = comm::recv(page_port);
let val = oldcomm::recv(page_port);
if val.is_some() {
pages += ~[option::unwrap(move val)];
} else {
@ -77,7 +77,7 @@ fn find_pages(doc: doc::Doc, page_chan: PageChan) {
};
(fold.fold_doc)(&fold, doc);
comm::send(page_chan, None);
oldcomm::send(page_chan, None);
}
fn fold_crate(
@ -92,7 +92,7 @@ fn fold_crate(
.. doc
});
comm::send(fold.ctxt.op, Some(page));
oldcomm::send(fold.ctxt.op, Some(page));
doc
}
@ -108,7 +108,7 @@ fn fold_mod(
let doc = strip_mod(doc);
let page = doc::ItemPage(doc::ModTag(doc));
comm::send(fold.ctxt.op, Some(page));
oldcomm::send(fold.ctxt.op, Some(page));
}
doc
@ -133,7 +133,7 @@ fn fold_nmod(
) -> doc::NmodDoc {
let doc = fold::default_seq_fold_nmod(fold, doc);
let page = doc::ItemPage(doc::NmodTag(doc));
comm::send(fold.ctxt.op, Some(page));
oldcomm::send(fold.ctxt.op, Some(page));
return doc;
}

View File

@ -17,3 +17,26 @@ impl<T: Copy> NominalOp<T>: Clone {
fn clone(&self) -> NominalOp<T> { copy *self }
}
pub fn spawn_listener<A: Owned>(
+f: fn~(oldcomm::Port<A>)) -> oldcomm::Chan<A> {
let setup_po = oldcomm::Port();
let setup_ch = oldcomm::Chan(&setup_po);
do task::spawn |move f| {
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
oldcomm::send(setup_ch, ch);
f(move po);
}
oldcomm::recv(setup_po)
}
pub fn spawn_conversation<A: Owned, B: Owned>
(+f: fn~(oldcomm::Port<A>, oldcomm::Chan<B>))
-> (oldcomm::Port<B>, oldcomm::Chan<A>) {
let from_child = oldcomm::Port();
let to_parent = oldcomm::Chan(&from_child);
let to_child = do spawn_listener |move f, from_parent| {
f(from_parent, to_parent)
};
(from_child, to_child)
}

View File

@ -30,7 +30,6 @@ use create_uv_getaddrinfo_t = uv::ll::getaddrinfo_t;
use set_data_for_req = uv::ll::set_data_for_req;
use get_data_for_req = uv::ll::get_data_for_req;
use ll = uv::ll;
use comm = core::comm;
/// An IP address
pub enum IpAddr {
@ -108,7 +107,7 @@ enum IpGetAddrErr {
*/
pub fn get_addr(node: &str, iotask: iotask)
-> result::Result<~[IpAddr], IpGetAddrErr> {
do core::comm::listen |output_ch| {
do oldcomm::listen |output_ch| {
do str::as_buf(node) |node_ptr, len| unsafe {
log(debug, fmt!("slice len %?", len));
let handle = create_uv_getaddrinfo_t();
@ -268,7 +267,7 @@ pub mod v6 {
}
type GetAddrData = {
output_ch: comm::Chan<result::Result<~[IpAddr],IpGetAddrErr>>
output_ch: oldcomm::Chan<result::Result<~[IpAddr],IpGetAddrErr>>
};
extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,

View File

@ -19,7 +19,6 @@ use future_spawn = future::spawn;
use result::{Result};
use libc::size_t;
use io::{Reader, ReaderUtil, Writer};
use comm = core::comm;
#[nolink]
extern mod rustrt {
@ -133,19 +132,19 @@ pub enum TcpConnectErrData {
pub fn connect(input_ip: ip::IpAddr, port: uint,
iotask: IoTask)
-> result::Result<TcpSocket, TcpConnectErrData> unsafe {
let result_po = core::comm::Port::<ConnAttempt>();
let closed_signal_po = core::comm::Port::<()>();
let result_po = oldcomm::Port::<ConnAttempt>();
let closed_signal_po = oldcomm::Port::<()>();
let conn_data = {
result_ch: core::comm::Chan(&result_po),
closed_signal_ch: core::comm::Chan(&closed_signal_po)
result_ch: oldcomm::Chan(&result_po),
closed_signal_ch: oldcomm::Chan(&closed_signal_po)
};
let conn_data_ptr = ptr::addr_of(&conn_data);
let reader_po = core::comm::Port::<result::Result<~[u8], TcpErrData>>();
let reader_po = oldcomm::Port::<result::Result<~[u8], TcpErrData>>();
let stream_handle_ptr = malloc_uv_tcp_t();
*(stream_handle_ptr as *mut uv::ll::uv_tcp_t) = uv::ll::tcp_t();
let socket_data = @{
reader_po: reader_po,
reader_ch: core::comm::Chan(&reader_po),
reader_ch: oldcomm::Chan(&reader_po),
stream_handle_ptr: stream_handle_ptr,
connect_req: uv::ll::connect_t(),
write_req: uv::ll::write_t(),
@ -217,7 +216,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
// immediate connect failure.. probably a garbage
// ip or somesuch
let err_data = uv::ll::get_last_err_data(loop_ptr);
core::comm::send((*conn_data_ptr).result_ch,
oldcomm::send((*conn_data_ptr).result_ch,
ConnFailure(err_data.to_tcp_err()));
uv::ll::set_data_for_uv_handle(stream_handle_ptr,
conn_data_ptr);
@ -228,18 +227,18 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
_ => {
// failure to create a tcp handle
let err_data = uv::ll::get_last_err_data(loop_ptr);
core::comm::send((*conn_data_ptr).result_ch,
oldcomm::send((*conn_data_ptr).result_ch,
ConnFailure(err_data.to_tcp_err()));
}
}
};
match core::comm::recv(result_po) {
match oldcomm::recv(result_po) {
ConnSuccess => {
log(debug, ~"tcp::connect - received success on result_po");
result::Ok(TcpSocket(socket_data))
}
ConnFailure(ref err_data) => {
core::comm::recv(closed_signal_po);
oldcomm::recv(closed_signal_po);
log(debug, ~"tcp::connect - received failure on result_po");
// still have to free the malloc'd stream handle..
rustrt::rust_uv_current_kernel_free(stream_handle_ptr
@ -329,7 +328,7 @@ pub fn write_future(sock: &TcpSocket, raw_write_data: ~[u8])
* `tcp_err_data` record
*/
pub fn read_start(sock: &TcpSocket)
-> result::Result<comm::Port<
-> result::Result<oldcomm::Port<
result::Result<~[u8], TcpErrData>>, TcpErrData> unsafe {
let socket_data = ptr::addr_of(&(*(sock.socket_data)));
read_start_common_impl(socket_data)
@ -343,7 +342,7 @@ pub fn read_start(sock: &TcpSocket)
* * `sock` - a `net::tcp::tcp_socket` that you wish to stop reading on
*/
pub fn read_stop(sock: &TcpSocket,
read_port: comm::Port<result::Result<~[u8], TcpErrData>>) ->
read_port: oldcomm::Port<result::Result<~[u8], TcpErrData>>) ->
result::Result<(), TcpErrData> unsafe {
log(debug, fmt!("taking the read_port out of commission %?", read_port));
let socket_data = ptr::addr_of(&(*sock.socket_data));
@ -484,13 +483,13 @@ pub fn accept(new_conn: TcpNewConnection)
NewTcpConn(server_handle_ptr) => {
let server_data_ptr = uv::ll::get_data_for_uv_handle(
server_handle_ptr) as *TcpListenFcData;
let reader_po = core::comm::Port();
let reader_po = oldcomm::Port();
let iotask = (*server_data_ptr).iotask;
let stream_handle_ptr = malloc_uv_tcp_t();
*(stream_handle_ptr as *mut uv::ll::uv_tcp_t) = uv::ll::tcp_t();
let client_socket_data = @{
reader_po: reader_po,
reader_ch: core::comm::Chan(&reader_po),
reader_ch: oldcomm::Chan(&reader_po),
stream_handle_ptr : stream_handle_ptr,
connect_req : uv::ll::connect_t(),
write_req : uv::ll::write_t(),
@ -501,8 +500,8 @@ pub fn accept(new_conn: TcpNewConnection)
let client_stream_handle_ptr =
(*client_socket_data_ptr).stream_handle_ptr;
let result_po = core::comm::Port::<Option<TcpErrData>>();
let result_ch = core::comm::Chan(&result_po);
let result_po = oldcomm::Port::<Option<TcpErrData>>();
let result_ch = oldcomm::Chan(&result_po);
// UNSAFE LIBUV INTERACTION BEGIN
// .. normally this happens within the context of
@ -524,23 +523,23 @@ pub fn accept(new_conn: TcpNewConnection)
uv::ll::set_data_for_uv_handle(client_stream_handle_ptr,
client_socket_data_ptr
as *libc::c_void);
core::comm::send(result_ch, None);
oldcomm::send(result_ch, None);
}
_ => {
log(debug, ~"failed to accept client conn");
core::comm::send(result_ch, Some(
oldcomm::send(result_ch, Some(
uv::ll::get_last_err_data(loop_ptr).to_tcp_err()));
}
}
}
_ => {
log(debug, ~"failed to init client stream");
core::comm::send(result_ch, Some(
oldcomm::send(result_ch, Some(
uv::ll::get_last_err_data(loop_ptr).to_tcp_err()));
}
}
// UNSAFE LIBUV INTERACTION END
match core::comm::recv(result_po) {
match oldcomm::recv(result_po) {
Some(copy err_data) => result::Err(err_data),
None => result::Ok(TcpSocket(client_socket_data))
}
@ -578,9 +577,9 @@ pub fn accept(new_conn: TcpNewConnection)
*/
pub fn listen(host_ip: ip::IpAddr, port: uint, backlog: uint,
iotask: IoTask,
on_establish_cb: fn~(comm::Chan<Option<TcpErrData>>),
on_establish_cb: fn~(oldcomm::Chan<Option<TcpErrData>>),
new_connect_cb: fn~(TcpNewConnection,
comm::Chan<Option<TcpErrData>>))
oldcomm::Chan<Option<TcpErrData>>))
-> result::Result<(), TcpListenErrData> unsafe {
do listen_common(move host_ip, port, backlog, iotask,
move on_establish_cb)
@ -596,17 +595,17 @@ pub fn listen(host_ip: ip::IpAddr, port: uint, backlog: uint,
fn listen_common(host_ip: ip::IpAddr, port: uint, backlog: uint,
iotask: IoTask,
on_establish_cb: fn~(comm::Chan<Option<TcpErrData>>),
on_establish_cb: fn~(oldcomm::Chan<Option<TcpErrData>>),
on_connect_cb: fn~(*uv::ll::uv_tcp_t))
-> result::Result<(), TcpListenErrData> unsafe {
let stream_closed_po = core::comm::Port::<()>();
let kill_po = core::comm::Port::<Option<TcpErrData>>();
let kill_ch = core::comm::Chan(&kill_po);
let stream_closed_po = oldcomm::Port::<()>();
let kill_po = oldcomm::Port::<Option<TcpErrData>>();
let kill_ch = oldcomm::Chan(&kill_po);
let server_stream = uv::ll::tcp_t();
let server_stream_ptr = ptr::addr_of(&server_stream);
let server_data = {
server_stream_ptr: server_stream_ptr,
stream_closed_ch: core::comm::Chan(&stream_closed_po),
stream_closed_ch: oldcomm::Chan(&stream_closed_po),
kill_ch: kill_ch,
on_connect_cb: move on_connect_cb,
iotask: iotask,
@ -618,7 +617,7 @@ fn listen_common(host_ip: ip::IpAddr, port: uint, backlog: uint,
};
let server_data_ptr = ptr::addr_of(&server_data);
let setup_result = do core::comm::listen |setup_ch| {
let setup_result = do oldcomm::listen |setup_ch| {
// this is to address a compiler warning about
// an implicit copy.. it seems that double nested
// will defeat a move sigil, as is done to the host_ip
@ -652,25 +651,25 @@ fn listen_common(host_ip: ip::IpAddr, port: uint, backlog: uint,
match uv::ll::listen(server_stream_ptr,
backlog as libc::c_int,
tcp_lfc_on_connection_cb) {
0i32 => core::comm::send(setup_ch, None),
0i32 => oldcomm::send(setup_ch, None),
_ => {
log(debug, ~"failure to uv_listen()");
let err_data = uv::ll::get_last_err_data(loop_ptr);
core::comm::send(setup_ch, Some(err_data));
oldcomm::send(setup_ch, Some(err_data));
}
}
}
_ => {
log(debug, ~"failure to uv_tcp_bind");
let err_data = uv::ll::get_last_err_data(loop_ptr);
core::comm::send(setup_ch, Some(err_data));
oldcomm::send(setup_ch, Some(err_data));
}
}
}
_ => {
log(debug, ~"failure to uv_tcp_init");
let err_data = uv::ll::get_last_err_data(loop_ptr);
core::comm::send(setup_ch, Some(err_data));
oldcomm::send(setup_ch, Some(err_data));
}
}
};
@ -704,7 +703,7 @@ fn listen_common(host_ip: ip::IpAddr, port: uint, backlog: uint,
}
None => {
on_establish_cb(kill_ch);
let kill_result = core::comm::recv(kill_po);
let kill_result = oldcomm::recv(kill_po);
do iotask::interact(iotask) |loop_ptr| unsafe {
log(debug, fmt!("tcp::listen post-kill recv hl interact %?",
loop_ptr));
@ -745,12 +744,12 @@ pub fn socket_buf(sock: TcpSocket) -> TcpSocketBuf {
/// Convenience methods extending `net::tcp::tcp_socket`
impl TcpSocket {
pub fn read_start() -> result::Result<comm::Port<
pub fn read_start() -> result::Result<oldcomm::Port<
result::Result<~[u8], TcpErrData>>, TcpErrData> {
read_start(&self)
}
pub fn read_stop(read_port:
comm::Port<result::Result<~[u8], TcpErrData>>) ->
oldcomm::Port<result::Result<~[u8], TcpErrData>>) ->
result::Result<(), TcpErrData> {
read_stop(&self, move read_port)
}
@ -877,8 +876,8 @@ impl TcpSocketBuf: io::Writer {
// INTERNAL API
fn tear_down_socket_data(socket_data: @TcpSocketData) unsafe {
let closed_po = core::comm::Port::<()>();
let closed_ch = core::comm::Chan(&closed_po);
let closed_po = oldcomm::Port::<()>();
let closed_ch = oldcomm::Chan(&closed_po);
let close_data = {
closed_ch: closed_ch
};
@ -891,7 +890,7 @@ fn tear_down_socket_data(socket_data: @TcpSocketData) unsafe {
close_data_ptr);
uv::ll::close(stream_handle_ptr, tcp_socket_dtor_close_cb);
};
core::comm::recv(closed_po);
oldcomm::recv(closed_po);
//the line below will most likely crash
//log(debug, fmt!("about to free socket_data at %?", socket_data));
rustrt::rust_uv_current_kernel_free(stream_handle_ptr
@ -915,7 +914,7 @@ fn read_common_impl(socket_data: *TcpSocketData, timeout_msecs: uint)
timer::recv_timeout(
iotask, timeout_msecs, result::get(&rs_result))
} else {
Some(core::comm::recv(result::get(&rs_result)))
Some(oldcomm::recv(result::get(&rs_result)))
};
log(debug, ~"tcp::read after recv_timeout");
match move read_result {
@ -941,23 +940,23 @@ fn read_common_impl(socket_data: *TcpSocketData, timeout_msecs: uint)
fn read_stop_common_impl(socket_data: *TcpSocketData) ->
result::Result<(), TcpErrData> unsafe {
let stream_handle_ptr = (*socket_data).stream_handle_ptr;
let stop_po = core::comm::Port::<Option<TcpErrData>>();
let stop_ch = core::comm::Chan(&stop_po);
let stop_po = oldcomm::Port::<Option<TcpErrData>>();
let stop_ch = oldcomm::Chan(&stop_po);
do iotask::interact((*socket_data).iotask) |loop_ptr| unsafe {
log(debug, ~"in interact cb for tcp::read_stop");
match uv::ll::read_stop(stream_handle_ptr as *uv::ll::uv_stream_t) {
0i32 => {
log(debug, ~"successfully called uv_read_stop");
core::comm::send(stop_ch, None);
oldcomm::send(stop_ch, None);
}
_ => {
log(debug, ~"failure in calling uv_read_stop");
let err_data = uv::ll::get_last_err_data(loop_ptr);
core::comm::send(stop_ch, Some(err_data.to_tcp_err()));
oldcomm::send(stop_ch, Some(err_data.to_tcp_err()));
}
}
};
match core::comm::recv(stop_po) {
match oldcomm::recv(stop_po) {
Some(ref err_data) => result::Err(err_data.to_tcp_err()),
None => result::Ok(())
}
@ -965,11 +964,11 @@ fn read_stop_common_impl(socket_data: *TcpSocketData) ->
// shared impl for read_start
fn read_start_common_impl(socket_data: *TcpSocketData)
-> result::Result<comm::Port<
-> result::Result<oldcomm::Port<
result::Result<~[u8], TcpErrData>>, TcpErrData> unsafe {
let stream_handle_ptr = (*socket_data).stream_handle_ptr;
let start_po = core::comm::Port::<Option<uv::ll::uv_err_data>>();
let start_ch = core::comm::Chan(&start_po);
let start_po = oldcomm::Port::<Option<uv::ll::uv_err_data>>();
let start_ch = oldcomm::Chan(&start_po);
log(debug, ~"in tcp::read_start before interact loop");
do iotask::interact((*socket_data).iotask) |loop_ptr| unsafe {
log(debug, fmt!("in tcp::read_start interact cb %?", loop_ptr));
@ -978,16 +977,16 @@ fn read_start_common_impl(socket_data: *TcpSocketData)
on_tcp_read_cb) {
0i32 => {
log(debug, ~"success doing uv_read_start");
core::comm::send(start_ch, None);
oldcomm::send(start_ch, None);
}
_ => {
log(debug, ~"error attempting uv_read_start");
let err_data = uv::ll::get_last_err_data(loop_ptr);
core::comm::send(start_ch, Some(err_data));
oldcomm::send(start_ch, Some(err_data));
}
}
};
match core::comm::recv(start_po) {
match oldcomm::recv(start_po) {
Some(ref err_data) => result::Err(err_data.to_tcp_err()),
None => result::Ok((*socket_data).reader_po)
}
@ -1006,9 +1005,9 @@ fn write_common_impl(socket_data_ptr: *TcpSocketData,
vec::raw::to_ptr(raw_write_data),
vec::len(raw_write_data)) ];
let write_buf_vec_ptr = ptr::addr_of(&write_buf_vec);
let result_po = core::comm::Port::<TcpWriteResult>();
let result_po = oldcomm::Port::<TcpWriteResult>();
let write_data = {
result_ch: core::comm::Chan(&result_po)
result_ch: oldcomm::Chan(&result_po)
};
let write_data_ptr = ptr::addr_of(&write_data);
do iotask::interact((*socket_data_ptr).iotask) |loop_ptr| unsafe {
@ -1024,7 +1023,7 @@ fn write_common_impl(socket_data_ptr: *TcpSocketData,
_ => {
log(debug, ~"error invoking uv_write()");
let err_data = uv::ll::get_last_err_data(loop_ptr);
core::comm::send((*write_data_ptr).result_ch,
oldcomm::send((*write_data_ptr).result_ch,
TcpWriteError(err_data.to_tcp_err()));
}
}
@ -1033,7 +1032,7 @@ fn write_common_impl(socket_data_ptr: *TcpSocketData,
// and waiting here for the write to complete, we should transfer
// ownership of everything to the I/O task and let it deal with the
// aftermath, so we don't have to sit here blocking.
match core::comm::recv(result_po) {
match oldcomm::recv(result_po) {
TcpWriteSuccess => result::Ok(()),
TcpWriteError(ref err_data) => result::Err(err_data.to_tcp_err())
}
@ -1045,8 +1044,8 @@ enum TcpNewConnection {
type TcpListenFcData = {
server_stream_ptr: *uv::ll::uv_tcp_t,
stream_closed_ch: comm::Chan<()>,
kill_ch: comm::Chan<Option<TcpErrData>>,
stream_closed_ch: oldcomm::Chan<()>,
kill_ch: oldcomm::Chan<Option<TcpErrData>>,
on_connect_cb: fn~(*uv::ll::uv_tcp_t),
iotask: IoTask,
ipv6: bool,
@ -1056,7 +1055,7 @@ type TcpListenFcData = {
extern fn tcp_lfc_close_cb(handle: *uv::ll::uv_tcp_t) unsafe {
let server_data_ptr = uv::ll::get_data_for_uv_handle(
handle) as *TcpListenFcData;
core::comm::send((*server_data_ptr).stream_closed_ch, ());
oldcomm::send((*server_data_ptr).stream_closed_ch, ());
}
extern fn tcp_lfc_on_connection_cb(handle: *uv::ll::uv_tcp_t,
@ -1069,7 +1068,7 @@ extern fn tcp_lfc_on_connection_cb(handle: *uv::ll::uv_tcp_t,
0i32 => ((*server_data_ptr).on_connect_cb)(handle),
_ => {
let loop_ptr = uv::ll::get_loop_for_uv_handle(handle);
core::comm::send(kill_ch,
oldcomm::send(kill_ch,
Some(uv::ll::get_last_err_data(loop_ptr)
.to_tcp_err()));
(*server_data_ptr).active = false;
@ -1094,7 +1093,7 @@ enum TcpWriteResult {
}
enum TcpReadStartResult {
TcpReadStartSuccess(comm::Port<TcpReadResult>),
TcpReadStartSuccess(oldcomm::Port<TcpReadResult>),
TcpReadStartError(TcpErrData)
}
@ -1129,7 +1128,7 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t,
log(debug, fmt!("on_tcp_read_cb: incoming err.. name %? msg %?",
err_data.err_name, err_data.err_msg));
let reader_ch = (*socket_data_ptr).reader_ch;
core::comm::send(reader_ch, result::Err(err_data));
oldcomm::send(reader_ch, result::Err(err_data));
}
// do nothing .. unneeded buf
0 => (),
@ -1140,7 +1139,7 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t,
let reader_ch = (*socket_data_ptr).reader_ch;
let buf_base = uv::ll::get_base_from_buf(buf);
let new_bytes = vec::from_buf(buf_base, nread as uint);
core::comm::send(reader_ch, result::Ok(new_bytes));
oldcomm::send(reader_ch, result::Ok(new_bytes));
}
}
uv::ll::free_base_of_buf(buf);
@ -1160,14 +1159,14 @@ extern fn on_alloc_cb(handle: *libc::c_void,
}
type TcpSocketCloseData = {
closed_ch: comm::Chan<()>
closed_ch: oldcomm::Chan<()>
};
extern fn tcp_socket_dtor_close_cb(handle: *uv::ll::uv_tcp_t) unsafe {
let data = uv::ll::get_data_for_uv_handle(handle)
as *TcpSocketCloseData;
let closed_ch = (*data).closed_ch;
core::comm::send(closed_ch, ());
oldcomm::send(closed_ch, ());
log(debug, ~"tcp_socket_dtor_close_cb exiting..");
}
@ -1177,31 +1176,31 @@ extern fn tcp_write_complete_cb(write_req: *uv::ll::uv_write_t,
as *WriteReqData;
if status == 0i32 {
log(debug, ~"successful write complete");
core::comm::send((*write_data_ptr).result_ch, TcpWriteSuccess);
oldcomm::send((*write_data_ptr).result_ch, TcpWriteSuccess);
} else {
let stream_handle_ptr = uv::ll::get_stream_handle_from_write_req(
write_req);
let loop_ptr = uv::ll::get_loop_for_uv_handle(stream_handle_ptr);
let err_data = uv::ll::get_last_err_data(loop_ptr);
log(debug, ~"failure to write");
core::comm::send((*write_data_ptr).result_ch,
oldcomm::send((*write_data_ptr).result_ch,
TcpWriteError(err_data));
}
}
type WriteReqData = {
result_ch: comm::Chan<TcpWriteResult>
result_ch: oldcomm::Chan<TcpWriteResult>
};
type ConnectReqData = {
result_ch: comm::Chan<ConnAttempt>,
closed_signal_ch: comm::Chan<()>
result_ch: oldcomm::Chan<ConnAttempt>,
closed_signal_ch: oldcomm::Chan<()>
};
extern fn stream_error_close_cb(handle: *uv::ll::uv_tcp_t) unsafe {
let data = uv::ll::get_data_for_uv_handle(handle) as
*ConnectReqData;
core::comm::send((*data).closed_signal_ch, ());
oldcomm::send((*data).closed_signal_ch, ());
log(debug, fmt!("exiting steam_error_close_cb for %?", handle));
}
@ -1220,7 +1219,7 @@ extern fn tcp_connect_on_connect_cb(connect_req_ptr: *uv::ll::uv_connect_t,
match status {
0i32 => {
log(debug, ~"successful tcp connection!");
core::comm::send(result_ch, ConnSuccess);
oldcomm::send(result_ch, ConnSuccess);
}
_ => {
log(debug, ~"error in tcp_connect_on_connect_cb");
@ -1228,7 +1227,7 @@ extern fn tcp_connect_on_connect_cb(connect_req_ptr: *uv::ll::uv_connect_t,
let err_data = uv::ll::get_last_err_data(loop_ptr);
log(debug, fmt!("err_data %? %?", err_data.err_name,
err_data.err_msg));
core::comm::send(result_ch, ConnFailure(err_data));
oldcomm::send(result_ch, ConnFailure(err_data));
uv::ll::set_data_for_uv_handle(tcp_stream_ptr,
conn_data_ptr);
uv::ll::close(tcp_stream_ptr, stream_error_close_cb);
@ -1243,8 +1242,8 @@ enum ConnAttempt {
}
type TcpSocketData = {
reader_po: comm::Port<result::Result<~[u8], TcpErrData>>,
reader_ch: comm::Chan<result::Result<~[u8], TcpErrData>>,
reader_po: oldcomm::Port<result::Result<~[u8], TcpErrData>>,
reader_ch: oldcomm::Chan<result::Result<~[u8], TcpErrData>>,
stream_handle_ptr: *uv::ll::uv_tcp_t,
connect_req: uv::ll::uv_connect_t,
write_req: uv::ll::uv_write_t,
@ -1337,14 +1336,14 @@ mod test {
let expected_req = ~"ping";
let expected_resp = ~"pong";
let server_result_po = core::comm::Port::<~str>();
let server_result_ch = core::comm::Chan(&server_result_po);
let server_result_po = oldcomm::Port::<~str>();
let server_result_ch = oldcomm::Chan(&server_result_po);
let cont_po = core::comm::Port::<()>();
let cont_ch = core::comm::Chan(&cont_po);
let cont_po = oldcomm::Port::<()>();
let cont_ch = oldcomm::Chan(&cont_po);
// server
do task::spawn_sched(task::ManualThreads(1u)) {
let actual_req = do comm::listen |server_ch| {
let actual_req = do oldcomm::listen |server_ch| {
run_tcp_test_server(
server_ip,
server_port,
@ -1355,10 +1354,10 @@ mod test {
};
server_result_ch.send(actual_req);
};
core::comm::recv(cont_po);
oldcomm::recv(cont_po);
// client
log(debug, ~"server started, firing up client..");
let actual_resp_result = do core::comm::listen |client_ch| {
let actual_resp_result = do oldcomm::listen |client_ch| {
run_tcp_test_client(
server_ip,
server_port,
@ -1368,7 +1367,7 @@ mod test {
};
assert actual_resp_result.is_ok();
let actual_resp = actual_resp_result.get();
let actual_req = core::comm::recv(server_result_po);
let actual_req = oldcomm::recv(server_result_po);
log(debug, fmt!("REQ: expected: '%s' actual: '%s'",
expected_req, actual_req));
log(debug, fmt!("RESP: expected: '%s' actual: '%s'",
@ -1382,14 +1381,14 @@ mod test {
let server_port = 8887u;
let expected_resp = ~"pong";
let server_result_po = core::comm::Port::<~str>();
let server_result_ch = core::comm::Chan(&server_result_po);
let server_result_po = oldcomm::Port::<~str>();
let server_result_ch = oldcomm::Chan(&server_result_po);
let cont_po = core::comm::Port::<()>();
let cont_ch = core::comm::Chan(&cont_po);
let cont_po = oldcomm::Port::<()>();
let cont_ch = oldcomm::Chan(&cont_po);
// server
do task::spawn_sched(task::ManualThreads(1u)) {
let actual_req = do comm::listen |server_ch| {
let actual_req = do oldcomm::listen |server_ch| {
run_tcp_test_server(
server_ip,
server_port,
@ -1400,10 +1399,10 @@ mod test {
};
server_result_ch.send(actual_req);
};
core::comm::recv(cont_po);
oldcomm::recv(cont_po);
// client
log(debug, ~"server started, firing up client..");
do core::comm::listen |client_ch| {
do oldcomm::listen |client_ch| {
let server_ip_addr = ip::v4::parse_addr(server_ip);
let iotask = uv::global_loop::get();
let connect_result = connect(move server_ip_addr, server_port,
@ -1430,7 +1429,7 @@ mod test {
let expected_req = ~"ping";
// client
log(debug, ~"firing up client..");
let actual_resp_result = do core::comm::listen |client_ch| {
let actual_resp_result = do oldcomm::listen |client_ch| {
run_tcp_test_client(
server_ip,
server_port,
@ -1450,14 +1449,14 @@ mod test {
let expected_req = ~"ping";
let expected_resp = ~"pong";
let server_result_po = core::comm::Port::<~str>();
let server_result_ch = core::comm::Chan(&server_result_po);
let server_result_po = oldcomm::Port::<~str>();
let server_result_ch = oldcomm::Chan(&server_result_po);
let cont_po = core::comm::Port::<()>();
let cont_ch = core::comm::Chan(&cont_po);
let cont_po = oldcomm::Port::<()>();
let cont_ch = oldcomm::Chan(&cont_po);
// server
do task::spawn_sched(task::ManualThreads(1u)) {
let actual_req = do comm::listen |server_ch| {
let actual_req = do oldcomm::listen |server_ch| {
run_tcp_test_server(
server_ip,
server_port,
@ -1468,7 +1467,7 @@ mod test {
};
server_result_ch.send(actual_req);
};
core::comm::recv(cont_po);
oldcomm::recv(cont_po);
// this one should fail..
let listen_err = run_tcp_test_server_fail(
server_ip,
@ -1476,7 +1475,7 @@ mod test {
hl_loop);
// client.. just doing this so that the first server tears down
log(debug, ~"server started, firing up client..");
do core::comm::listen |client_ch| {
do oldcomm::listen |client_ch| {
run_tcp_test_client(
server_ip,
server_port,
@ -1574,14 +1573,14 @@ mod test {
let expected_req = ~"GET /";
let expected_resp = ~"A string\nwith multiple lines\n";
let server_result_po = core::comm::Port::<~str>();
let server_result_ch = core::comm::Chan(&server_result_po);
let server_result_po = oldcomm::Port::<~str>();
let server_result_ch = oldcomm::Chan(&server_result_po);
let cont_po = core::comm::Port::<()>();
let cont_ch = core::comm::Chan(&cont_po);
let cont_po = oldcomm::Port::<()>();
let cont_ch = oldcomm::Chan(&cont_po);
// server
do task::spawn_sched(task::ManualThreads(1u)) {
let actual_req = do comm::listen |server_ch| {
let actual_req = do oldcomm::listen |server_ch| {
run_tcp_test_server(
server_ip,
server_port,
@ -1592,7 +1591,7 @@ mod test {
};
server_result_ch.send(actual_req);
};
core::comm::recv(cont_po);
oldcomm::recv(cont_po);
// client
log(debug, ~"server started, firing up client..");
let server_addr = ip::v4::parse_addr(server_ip);
@ -1626,8 +1625,8 @@ mod test {
}
fn run_tcp_test_server(server_ip: &str, server_port: uint, resp: ~str,
server_ch: comm::Chan<~str>,
cont_ch: comm::Chan<()>,
server_ch: oldcomm::Chan<~str>,
cont_ch: oldcomm::Chan<()>,
iotask: IoTask) -> ~str {
let server_ip_addr = ip::v4::parse_addr(server_ip);
let listen_result = listen(move server_ip_addr, server_port, 128,
@ -1636,13 +1635,13 @@ mod test {
|kill_ch| {
log(debug, fmt!("establish_cb %?",
kill_ch));
core::comm::send(cont_ch, ());
oldcomm::send(cont_ch, ());
},
// risky to run this on the loop, but some users
// will want the POWER
|new_conn, kill_ch| {
log(debug, ~"SERVER: new connection!");
do comm::listen |cont_ch| {
do oldcomm::listen |cont_ch| {
do task::spawn_sched(task::ManualThreads(1u)) {
log(debug, ~"SERVER: starting worker for new req");
@ -1651,7 +1650,7 @@ mod test {
if result::is_err(&accept_result) {
log(debug, ~"SERVER: error accept connection");
let err_data = result::get_err(&accept_result);
core::comm::send(kill_ch, Some(err_data));
oldcomm::send(kill_ch, Some(err_data));
log(debug,
~"SERVER/WORKER: send on err cont ch");
cont_ch.send(());
@ -1677,12 +1676,12 @@ mod test {
log(debug, ~"SERVER: before write");
tcp_write_single(&sock, str::to_bytes(resp));
log(debug, ~"SERVER: after write.. die");
core::comm::send(kill_ch, None);
oldcomm::send(kill_ch, None);
}
result::Err(move err_data) => {
log(debug, fmt!("SERVER: error recvd: %s %s",
err_data.err_name, err_data.err_msg));
core::comm::send(kill_ch, Some(err_data));
oldcomm::send(kill_ch, Some(err_data));
server_ch.send(~"");
}
}
@ -1738,7 +1737,7 @@ mod test {
}
fn run_tcp_test_client(server_ip: &str, server_port: uint, resp: &str,
client_ch: comm::Chan<~str>,
client_ch: oldcomm::Chan<~str>,
iotask: IoTask) -> result::Result<~str,
TcpConnectErrData> {
let server_ip_addr = ip::v4::parse_addr(server_ip);

View File

@ -23,7 +23,6 @@ use result::{Ok, Err};
use io::WriterUtil;
use libc::size_t;
use task::TaskBuilder;
use comm = core::comm;
#[abi = "cdecl"]
extern mod rustrt {
@ -289,8 +288,8 @@ fn run_tests(opts: &TestOpts, tests: &[TestDesc],
let mut wait_idx = 0;
let mut done_idx = 0;
let p = core::comm::Port();
let ch = core::comm::Chan(&p);
let p = oldcomm::Port();
let ch = oldcomm::Chan(&p);
while done_idx < total {
while wait_idx < concurrency && run_idx < total {
@ -306,7 +305,7 @@ fn run_tests(opts: &TestOpts, tests: &[TestDesc],
run_idx += 1;
}
let (test, result) = core::comm::recv(p);
let (test, result) = oldcomm::recv(p);
if concurrency != 1 {
callback(TeWait(copy test));
}
@ -383,9 +382,9 @@ fn filter_tests(opts: &TestOpts,
type TestFuture = {test: TestDesc, wait: fn@() -> TestResult};
fn run_test(test: TestDesc, monitor_ch: comm::Chan<MonitorMsg>) {
fn run_test(test: TestDesc, monitor_ch: oldcomm::Chan<MonitorMsg>) {
if test.ignore {
core::comm::send(monitor_ch, (copy test, TrIgnored));
oldcomm::send(monitor_ch, (copy test, TrIgnored));
return;
}
@ -397,7 +396,7 @@ fn run_test(test: TestDesc, monitor_ch: comm::Chan<MonitorMsg>) {
}).spawn(move testfn);
let task_result = option::unwrap(move result_future).recv();
let test_result = calc_result(&test, task_result == task::Success);
comm::send(monitor_ch, (copy test, test_result));
oldcomm::send(monitor_ch, (copy test, test_result));
};
}
@ -424,10 +423,10 @@ mod tests {
ignore: true,
should_fail: false
};
let p = core::comm::Port();
let ch = core::comm::Chan(&p);
let p = oldcomm::Port();
let ch = oldcomm::Chan(&p);
run_test(desc, ch);
let (_, res) = core::comm::recv(p);
let (_, res) = oldcomm::recv(p);
assert res != TrOk;
}
@ -440,10 +439,10 @@ mod tests {
ignore: true,
should_fail: false
};
let p = core::comm::Port();
let ch = core::comm::Chan(&p);
let p = oldcomm::Port();
let ch = oldcomm::Chan(&p);
run_test(desc, ch);
let (_, res) = core::comm::recv(p);
let (_, res) = oldcomm::recv(p);
assert res == TrIgnored;
}
@ -457,10 +456,10 @@ mod tests {
ignore: false,
should_fail: true
};
let p = core::comm::Port();
let ch = core::comm::Chan(&p);
let p = oldcomm::Port();
let ch = oldcomm::Chan(&p);
run_test(desc, ch);
let (_, res) = core::comm::recv(p);
let (_, res) = oldcomm::recv(p);
assert res == TrOk;
}
@ -473,10 +472,10 @@ mod tests {
ignore: false,
should_fail: true
};
let p = core::comm::Port();
let ch = core::comm::Chan(&p);
let p = oldcomm::Port();
let ch = oldcomm::Chan(&p);
run_test(desc, ch);
let (_, res) = core::comm::recv(p);
let (_, res) = oldcomm::recv(p);
assert res == TrFailed;
}

View File

@ -14,7 +14,6 @@
use uv::iotask;
use uv::iotask::IoTask;
use comm = core::comm;
/**
* Wait for timeout period then send provided value over a channel
@ -33,10 +32,10 @@ use comm = core::comm;
* * val - a value of type T to send over the provided `ch`
*/
pub fn delayed_send<T: Owned>(iotask: IoTask,
msecs: uint, ch: comm::Chan<T>, val: T) {
msecs: uint, ch: oldcomm::Chan<T>, val: T) {
unsafe {
let timer_done_po = core::comm::Port::<()>();
let timer_done_ch = core::comm::Chan(&timer_done_po);
let timer_done_po = oldcomm::Port::<()>();
let timer_done_ch = oldcomm::Chan(&timer_done_po);
let timer_done_ch_ptr = ptr::addr_of(&timer_done_ch);
let timer = uv::ll::timer_t();
let timer_ptr = ptr::addr_of(&timer);
@ -62,11 +61,11 @@ pub fn delayed_send<T: Owned>(iotask: IoTask,
}
};
// delayed_send_cb has been processed by libuv
core::comm::recv(timer_done_po);
oldcomm::recv(timer_done_po);
// notify the caller immediately
core::comm::send(ch, move(val));
oldcomm::send(ch, move(val));
// uv_close for this timer has been processed
core::comm::recv(timer_done_po);
oldcomm::recv(timer_done_po);
};
}
@ -82,10 +81,10 @@ pub fn delayed_send<T: Owned>(iotask: IoTask,
* * msecs - an amount of time, in milliseconds, for the current task to block
*/
pub fn sleep(iotask: IoTask, msecs: uint) {
let exit_po = core::comm::Port::<()>();
let exit_ch = core::comm::Chan(&exit_po);
let exit_po = oldcomm::Port::<()>();
let exit_ch = oldcomm::Chan(&exit_po);
delayed_send(iotask, msecs, exit_ch, ());
core::comm::recv(exit_po);
oldcomm::recv(exit_po);
}
/**
@ -110,9 +109,9 @@ pub fn sleep(iotask: IoTask, msecs: uint) {
*/
pub fn recv_timeout<T: Copy Owned>(iotask: IoTask,
msecs: uint,
wait_po: comm::Port<T>) -> Option<T> {
let timeout_po = comm::Port::<()>();
let timeout_ch = comm::Chan(&timeout_po);
wait_po: oldcomm::Port<T>) -> Option<T> {
let timeout_po = oldcomm::Port::<()>();
let timeout_ch = oldcomm::Chan(&timeout_po);
delayed_send(iotask, msecs, timeout_ch, ());
// FIXME: This could be written clearer (#2618)
either::either(
@ -122,7 +121,7 @@ pub fn recv_timeout<T: Copy Owned>(iotask: IoTask,
None
}, |right_val| {
Some(*right_val)
}, &core::comm::select2(timeout_po, wait_po)
}, &oldcomm::select2(timeout_po, wait_po)
)
}
@ -131,10 +130,10 @@ extern fn delayed_send_cb(handle: *uv::ll::uv_timer_t,
status: libc::c_int) unsafe {
log(debug, fmt!("delayed_send_cb handle %? status %?", handle, status));
let timer_done_ch =
*(uv::ll::get_data_for_uv_handle(handle) as *comm::Chan<()>);
*(uv::ll::get_data_for_uv_handle(handle) as *oldcomm::Chan<()>);
let stop_result = uv::ll::timer_stop(handle);
if (stop_result == 0i32) {
core::comm::send(timer_done_ch, ());
oldcomm::send(timer_done_ch, ());
uv::ll::close(handle, delayed_send_close_cb);
}
else {
@ -147,8 +146,8 @@ extern fn delayed_send_cb(handle: *uv::ll::uv_timer_t,
extern fn delayed_send_close_cb(handle: *uv::ll::uv_timer_t) unsafe {
log(debug, fmt!("delayed_send_close_cb handle %?", handle));
let timer_done_ch =
*(uv::ll::get_data_for_uv_handle(handle) as *comm::Chan<()>);
comm::send(timer_done_ch, ());
*(uv::ll::get_data_for_uv_handle(handle) as *oldcomm::Chan<()>);
oldcomm::send(timer_done_ch, ());
}
#[cfg(test)]
@ -170,8 +169,8 @@ mod test {
#[test]
fn test_gl_timer_sleep_stress2() {
let po = core::comm::Port();
let ch = core::comm::Chan(&po);
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
let hl_loop = uv::global_loop::get();
let repeat = 20u;
@ -193,13 +192,13 @@ mod test {
for iter::repeat(times) {
sleep(hl_loop, rng.next() as uint % maxms);
}
core::comm::send(ch, ());
oldcomm::send(ch, ());
}
}
}
for iter::repeat(repeat * spec.len()) {
core::comm::recv(po)
oldcomm::recv(po)
}
}
@ -248,8 +247,8 @@ mod test {
for iter::repeat(times as uint) {
let expected = rand::Rng().gen_str(16u);
let test_po = core::comm::Port::<~str>();
let test_ch = core::comm::Chan(&test_po);
let test_po = oldcomm::Port::<~str>();
let test_ch = oldcomm::Chan(&test_po);
do task::spawn() {
delayed_send(hl_loop, 50u, test_ch, expected);

View File

@ -17,8 +17,7 @@ use iotask = uv_iotask;
use get_gl = get;
use uv_iotask::{IoTask, spawn_iotask};
use private::{chan_from_global_ptr, weaken_task};
use comm = core::comm;
use core::comm::{Port, Chan, select2, listen};
use core::oldcomm::{Port, Chan, select2, listen};
use task::TaskBuilder;
use either::{Left, Right};
@ -121,9 +120,9 @@ fn spawn_loop() -> IoTask {
mod test {
extern fn simple_timer_close_cb(timer_ptr: *ll::uv_timer_t) unsafe {
let exit_ch_ptr = ll::get_data_for_uv_handle(
timer_ptr as *libc::c_void) as *comm::Chan<bool>;
timer_ptr as *libc::c_void) as *oldcomm::Chan<bool>;
let exit_ch = *exit_ch_ptr;
core::comm::send(exit_ch, true);
oldcomm::send(exit_ch, true);
log(debug, fmt!("EXIT_CH_PTR simple_timer_close_cb exit_ch_ptr: %?",
exit_ch_ptr));
}
@ -142,8 +141,8 @@ mod test {
}
fn impl_uv_hl_simple_timer(iotask: IoTask) unsafe {
let exit_po = core::comm::Port::<bool>();
let exit_ch = core::comm::Chan(&exit_po);
let exit_po = oldcomm::Port::<bool>();
let exit_ch = oldcomm::Chan(&exit_po);
let exit_ch_ptr = ptr::addr_of(&exit_ch);
log(debug, fmt!("EXIT_CH_PTR newly created exit_ch_ptr: %?",
exit_ch_ptr));
@ -168,21 +167,21 @@ mod test {
fail ~"failure on ll::timer_init()";
}
};
core::comm::recv(exit_po);
oldcomm::recv(exit_po);
log(debug, ~"global_loop timer test: msg recv on exit_po, done..");
}
#[test]
fn test_gl_uv_global_loop_high_level_global_timer() unsafe {
let hl_loop = get_gl();
let exit_po = comm::Port::<()>();
let exit_ch = comm::Chan(&exit_po);
let exit_po = oldcomm::Port::<()>();
let exit_ch = oldcomm::Chan(&exit_po);
task::spawn_sched(task::ManualThreads(1u), || {
impl_uv_hl_simple_timer(hl_loop);
core::comm::send(exit_ch, ());
oldcomm::send(exit_ch, ());
});
impl_uv_hl_simple_timer(hl_loop);
core::comm::recv(exit_po);
oldcomm::recv(exit_po);
}
// keeping this test ignored until some kind of stress-test-harness
@ -191,17 +190,17 @@ mod test {
#[ignore]
fn test_stress_gl_uv_global_loop_high_level_global_timer() unsafe {
let hl_loop = get_gl();
let exit_po = core::comm::Port::<()>();
let exit_ch = core::comm::Chan(&exit_po);
let exit_po = oldcomm::Port::<()>();
let exit_ch = oldcomm::Chan(&exit_po);
let cycles = 5000u;
for iter::repeat(cycles) {
task::spawn_sched(task::ManualThreads(1u), || {
impl_uv_hl_simple_timer(hl_loop);
core::comm::send(exit_ch, ());
oldcomm::send(exit_ch, ());
});
};
for iter::repeat(cycles) {
core::comm::recv(exit_po);
oldcomm::recv(exit_po);
};
log(debug, ~"test_stress_gl_uv_global_loop_high_level_global_timer"+
~" exiting sucessfully!");

View File

@ -18,8 +18,7 @@
use libc::c_void;
use ptr::addr_of;
use comm = core::comm;
use core::comm::{Port, Chan, listen};
use core::oldcomm::{Port, Chan, listen};
use task::TaskBuilder;
use ll = uv_ll;
@ -178,7 +177,7 @@ mod test {
log(debug, fmt!("async_close_cb handle %?", handle));
let exit_ch = (*(ll::get_data_for_uv_handle(handle)
as *AhData)).exit_ch;
core::comm::send(exit_ch, ());
oldcomm::send(exit_ch, ());
}
extern fn async_handle_cb(handle: *ll::uv_async_t, status: libc::c_int)
unsafe {
@ -187,13 +186,13 @@ mod test {
}
type AhData = {
iotask: IoTask,
exit_ch: comm::Chan<()>
exit_ch: oldcomm::Chan<()>
};
fn impl_uv_iotask_async(iotask: IoTask) unsafe {
let async_handle = ll::async_t();
let ah_ptr = ptr::addr_of(&async_handle);
let exit_po = core::comm::Port::<()>();
let exit_ch = core::comm::Chan(&exit_po);
let exit_po = oldcomm::Port::<()>();
let exit_ch = oldcomm::Chan(&exit_po);
let ah_data = {
iotask: iotask,
exit_ch: exit_ch
@ -204,19 +203,19 @@ mod test {
ll::set_data_for_uv_handle(ah_ptr, ah_data_ptr as *libc::c_void);
ll::async_send(ah_ptr);
};
core::comm::recv(exit_po);
oldcomm::recv(exit_po);
}
// this fn documents the bear minimum neccesary to roll your own
// high_level_loop
unsafe fn spawn_test_loop(exit_ch: comm::Chan<()>) -> IoTask {
let iotask_port = comm::Port::<IoTask>();
let iotask_ch = comm::Chan(&iotask_port);
unsafe fn spawn_test_loop(exit_ch: oldcomm::Chan<()>) -> IoTask {
let iotask_port = oldcomm::Port::<IoTask>();
let iotask_ch = oldcomm::Chan(&iotask_port);
do task::spawn_sched(task::ManualThreads(1u)) {
run_loop(iotask_ch);
exit_ch.send(());
};
return core::comm::recv(iotask_port);
return oldcomm::recv(iotask_port);
}
extern fn lifetime_handle_close(handle: *libc::c_void) unsafe {
@ -231,8 +230,8 @@ mod test {
#[test]
fn test_uv_iotask_async() unsafe {
let exit_po = core::comm::Port::<()>();
let exit_ch = core::comm::Chan(&exit_po);
let exit_po = oldcomm::Port::<()>();
let exit_ch = oldcomm::Chan(&exit_po);
let iotask = spawn_test_loop(exit_ch);
// using this handle to manage the lifetime of the high_level_loop,
@ -241,20 +240,20 @@ mod test {
// under race-condition type situations.. this ensures that the loop
// lives until, at least, all of the impl_uv_hl_async() runs have been
// called, at least.
let work_exit_po = core::comm::Port::<()>();
let work_exit_ch = core::comm::Chan(&work_exit_po);
let work_exit_po = oldcomm::Port::<()>();
let work_exit_ch = oldcomm::Chan(&work_exit_po);
for iter::repeat(7u) {
do task::spawn_sched(task::ManualThreads(1u)) {
impl_uv_iotask_async(iotask);
core::comm::send(work_exit_ch, ());
oldcomm::send(work_exit_ch, ());
};
};
for iter::repeat(7u) {
core::comm::recv(work_exit_po);
oldcomm::recv(work_exit_po);
};
log(debug, ~"sending teardown_loop msg..");
exit(iotask);
core::comm::recv(exit_po);
oldcomm::recv(exit_po);
log(debug, ~"after recv on exit_po.. exiting..");
}
}

View File

@ -33,7 +33,6 @@
#[allow(non_camel_case_types)]; // C types
use libc::size_t;
use comm = core::comm;
use ptr::to_unsafe_ptr;
// libuv struct mappings
@ -1045,7 +1044,7 @@ pub mod test {
type request_wrapper = {
write_req: *uv_write_t,
req_buf: *~[uv_buf_t],
read_chan: *comm::Chan<~str>
read_chan: *oldcomm::Chan<~str>
};
extern fn after_close_cb(handle: *libc::c_void) {
@ -1083,7 +1082,7 @@ pub mod test {
let bytes = vec::from_buf(buf_base, buf_len as uint);
let read_chan = *((*client_data).read_chan);
let msg_from_server = str::from_bytes(bytes);
core::comm::send(read_chan, msg_from_server);
oldcomm::send(read_chan, msg_from_server);
close(stream as *libc::c_void, after_close_cb)
}
else if (nread == -1) {
@ -1143,7 +1142,7 @@ pub mod test {
}
fn impl_uv_tcp_request(ip: &str, port: int, req_str: &str,
client_chan: *comm::Chan<~str>) unsafe {
client_chan: *oldcomm::Chan<~str>) unsafe {
let test_loop = loop_new();
let tcp_handle = tcp_t();
let tcp_handle_ptr = ptr::addr_of(&tcp_handle);
@ -1268,7 +1267,7 @@ pub mod test {
log(debug, ~"SERVER: sending response to client");
read_stop(client_stream_ptr);
let server_chan = *((*client_data).server_chan);
core::comm::send(server_chan, request_str);
oldcomm::send(server_chan, request_str);
let write_result = write(
write_req,
client_stream_ptr as *libc::c_void,
@ -1360,12 +1359,12 @@ pub mod test {
server: *uv_tcp_t,
server_kill_msg: ~str,
server_resp_buf: *~[uv_buf_t],
server_chan: *comm::Chan<~str>,
server_chan: *oldcomm::Chan<~str>,
server_write_req: *uv_write_t
};
type async_handle_data = {
continue_chan: *comm::Chan<bool>
continue_chan: *oldcomm::Chan<bool>
};
extern fn async_close_cb(handle: *libc::c_void) {
@ -1383,7 +1382,7 @@ pub mod test {
async_handle as *libc::c_void) as *async_handle_data;
let continue_chan = *((*data).continue_chan);
let should_continue = status == 0i32;
core::comm::send(continue_chan, should_continue);
oldcomm::send(continue_chan, should_continue);
close(async_handle as *libc::c_void, async_close_cb);
}
@ -1391,8 +1390,8 @@ pub mod test {
server_port: int,
+kill_server_msg: ~str,
+server_resp_msg: ~str,
server_chan: *comm::Chan<~str>,
continue_chan: *comm::Chan<bool>) unsafe {
server_chan: *oldcomm::Chan<~str>,
continue_chan: *oldcomm::Chan<bool>) unsafe {
let test_loop = loop_new();
let tcp_server = tcp_t();
let tcp_server_ptr = ptr::addr_of(&tcp_server);
@ -1497,13 +1496,13 @@ pub mod test {
let port = 8886;
let kill_server_msg = ~"does a dog have buddha nature?";
let server_resp_msg = ~"mu!";
let client_port = core::comm::Port::<~str>();
let client_chan = core::comm::Chan::<~str>(&client_port);
let server_port = core::comm::Port::<~str>();
let server_chan = core::comm::Chan::<~str>(&server_port);
let client_port = oldcomm::Port::<~str>();
let client_chan = oldcomm::Chan::<~str>(&client_port);
let server_port = oldcomm::Port::<~str>();
let server_chan = oldcomm::Chan::<~str>(&server_port);
let continue_port = core::comm::Port::<bool>();
let continue_chan = core::comm::Chan::<bool>(&continue_port);
let continue_port = oldcomm::Port::<bool>();
let continue_chan = oldcomm::Chan::<bool>(&continue_port);
let continue_chan_ptr = ptr::addr_of(&continue_chan);
do task::spawn_sched(task::ManualThreads(1)) {
@ -1516,7 +1515,7 @@ pub mod test {
// block until the server up is.. possibly a race?
log(debug, ~"before receiving on server continue_port");
core::comm::recv(continue_port);
oldcomm::recv(continue_port);
log(debug, ~"received on continue port, set up tcp client");
do task::spawn_sched(task::ManualThreads(1u)) {
@ -1525,8 +1524,8 @@ pub mod test {
ptr::addr_of(&client_chan));
};
let msg_from_client = core::comm::recv(server_port);
let msg_from_server = core::comm::recv(client_port);
let msg_from_client = oldcomm::recv(server_port);
let msg_from_server = oldcomm::recv(client_port);
assert str::contains(msg_from_client, kill_server_msg);
assert str::contains(msg_from_server, server_resp_msg);

View File

@ -12,7 +12,7 @@
export foo;
use core::comm::*;
use core::oldcomm::*;
fn foo<T: Owned Copy>(x: T) -> Port<T> {
let p = Port();

View File

@ -9,7 +9,7 @@
// except according to those terms.
/*
Minimized version of core::comm for testing.
Minimized version of core::oldcomm for testing.
Could probably be more minimal.
*/
@ -22,7 +22,7 @@ export recv;
/**
* A communication endpoint that can receive messages
* A oldcommunication endpoint that can receive messages
*
* Each port has a unique per-task identity and may not be replicated or
* transmitted. If a port value is copied, both copies refer to the same

View File

@ -26,7 +26,7 @@ use std::deque;
use std::deque::Deque;
use std::par;
use io::WriterUtil;
use comm::*;
use oldcomm::*;
use int::abs;
type node_id = i64;

View File

@ -14,7 +14,7 @@
// that things will look really good once we get that lock out of the
// message path.
use comm::*;
use oldcomm::*;
extern mod std;
use std::time;
@ -22,8 +22,8 @@ use std::future;
fn thread_ring(i: uint,
count: uint,
num_chan: comm::Chan<uint>,
num_port: comm::Port<uint>) {
num_chan: oldcomm::Chan<uint>,
num_port: oldcomm::Port<uint>) {
// Send/Receive lots of messages.
for uint::range(0u, count) |j| {
num_chan.send(i * j);

View File

@ -1,83 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// A port of the simplistic benchmark from
//
// http://github.com/PaulKeeble/ScalaVErlangAgents
//
// I *think* it's the same, more or less.
extern mod std;
use io::Writer;
use io::WriterUtil;
enum request {
get_count,
bytes(uint),
stop
}
fn server(requests: comm::Port<request>, responses: comm::Chan<uint>) {
let mut count = 0u;
let mut done = false;
while !done {
match comm::recv(requests) {
get_count => { comm::send(responses, copy count); }
bytes(b) => { count += b; }
stop => { done = true; }
}
}
comm::send(responses, count);
}
fn run(args: ~[~str]) {
let (from_child, to_child) = do task::spawn_conversation |po, ch| {
server(po, ch);
};
let size = uint::from_str(args[1]).get();
let workers = uint::from_str(args[2]).get();
let start = std::time::precise_time_s();
let mut worker_results = ~[];
for uint::range(0, workers) |_i| {
do task::task().future_result(|+r| {
worker_results.push(move r);
}).spawn {
for uint::range(0, size / workers) |_i| {
comm::send(to_child, bytes(100));
}
};
}
for vec::each(worker_results) |r| {
r.recv();
}
comm::send(to_child, stop);
let result = comm::recv(from_child);
let end = std::time::precise_time_s();
let elapsed = end - start;
io::stdout().write_str(fmt!("Count is %?\n", result));
io::stdout().write_str(fmt!("Test took %? seconds\n", elapsed));
let thruput = ((size / workers * workers) as float) / (elapsed as float);
io::stdout().write_str(fmt!("Throughput=%f per sec\n", thruput));
}
fn main() {
let args = os::args();
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"1000000", ~"10000"]
} else if args.len() <= 1u {
~[~"", ~"10000", ~"4"]
} else {
args
};
debug!("%?", args);
run(args);
}

View File

@ -95,9 +95,9 @@ fn transform(aa: color, bb: color) -> color {
fn creature(
name: uint,
color: color,
from_rendezvous: comm::Port<Option<creature_info>>,
to_rendezvous: comm::Chan<creature_info>,
to_rendezvous_log: comm::Chan<~str>
from_rendezvous: oldcomm::Port<Option<creature_info>>,
to_rendezvous: oldcomm::Chan<creature_info>,
to_rendezvous_log: oldcomm::Chan<~str>
) {
let mut color = color;
let mut creatures_met = 0;
@ -105,8 +105,8 @@ fn creature(
loop {
// ask for a pairing
comm::send(to_rendezvous, {name: name, color: color});
let resp = comm::recv(from_rendezvous);
oldcomm::send(to_rendezvous, {name: name, color: color});
let resp = oldcomm::recv(from_rendezvous);
// log and change, or print and quit
match resp {
@ -123,7 +123,7 @@ fn creature(
// log creatures met and evil clones of self
let report = fmt!("%u", creatures_met) + ~" " +
show_number(evil_clones_met);
comm::send(to_rendezvous_log, report);
oldcomm::send(to_rendezvous_log, report);
break;
}
}
@ -131,22 +131,35 @@ fn creature(
}
fn rendezvous(nn: uint, set: ~[color]) {
pub fn spawn_listener<A: Send>(+f: fn~(oldcomm::Port<A>)) -> oldcomm::Chan<A> {
let setup_po = oldcomm::Port();
let setup_ch = oldcomm::Chan(&setup_po);
do task::spawn |move f| {
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
oldcomm::send(setup_ch, ch);
f(move po);
}
oldcomm::recv(setup_po)
}
// these ports will allow us to hear from the creatures
let from_creatures: comm::Port<creature_info> = comm::Port();
let from_creatures_log: comm::Port<~str> = comm::Port();
let from_creatures: oldcomm::Port<creature_info> = oldcomm::Port();
let from_creatures_log: oldcomm::Port<~str> = oldcomm::Port();
// these channels will be passed to the creatures so they can talk to us
let to_rendezvous = comm::Chan(&from_creatures);
let to_rendezvous_log = comm::Chan(&from_creatures_log);
let to_rendezvous = oldcomm::Chan(&from_creatures);
let to_rendezvous_log = oldcomm::Chan(&from_creatures_log);
// these channels will allow us to talk to each creature by 'name'/index
let to_creature: ~[comm::Chan<Option<creature_info>>] =
let to_creature: ~[oldcomm::Chan<Option<creature_info>>] =
vec::mapi(set, |ii, col| {
// create each creature as a listener with a port, and
// give us a channel to talk to each
let ii = ii;
let col = *col;
do task::spawn_listener |from_rendezvous, move ii, move col| {
do spawn_listener |from_rendezvous, move ii, move col| {
creature(ii, col, from_rendezvous, to_rendezvous,
to_rendezvous_log);
}
@ -156,24 +169,24 @@ fn rendezvous(nn: uint, set: ~[color]) {
// set up meetings...
for nn.times {
let fst_creature: creature_info = comm::recv(from_creatures);
let snd_creature: creature_info = comm::recv(from_creatures);
let fst_creature: creature_info = oldcomm::recv(from_creatures);
let snd_creature: creature_info = oldcomm::recv(from_creatures);
creatures_met += 2;
comm::send(to_creature[fst_creature.name], Some(snd_creature));
comm::send(to_creature[snd_creature.name], Some(fst_creature));
oldcomm::send(to_creature[fst_creature.name], Some(snd_creature));
oldcomm::send(to_creature[snd_creature.name], Some(fst_creature));
}
// tell each creature to stop
for vec::eachi(to_creature) |_ii, to_one| {
comm::send(*to_one, None);
oldcomm::send(*to_one, None);
}
// save each creature's meeting stats
let mut report = ~[];
for vec::each(to_creature) |_to_one| {
report.push(comm::recv(from_creatures_log));
report.push(oldcomm::recv(from_creatures_log));
}
// print each color in the set

View File

@ -129,7 +129,7 @@ fn make_sequence_processor(sz: uint, from_parent: pipes::Port<~[u8]>,
_ => { ~"" }
};
//comm::send(to_parent, fmt!("yay{%u}", sz));
//oldcomm::send(to_parent, fmt!("yay{%u}", sz));
to_parent.send(move buffer);
}

View File

@ -87,7 +87,7 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 {
rv
}
fn chanmb(i: uint, size: uint, ch: comm::Chan<line>) -> ()
fn chanmb(i: uint, size: uint, ch: oldcomm::Chan<line>) -> ()
{
let mut crv = ~[];
let incr = 2f64/(size as f64);
@ -97,7 +97,7 @@ fn chanmb(i: uint, size: uint, ch: comm::Chan<line>) -> ()
let x = cmplx {re: xincr*(j as f64) - 1.5f64, im: y};
crv.push(fillbyte(x, incr));
};
comm::send(ch, {i:i, b:crv});
oldcomm::send(ch, {i:i, b:crv});
}
type devnull = {dn: int};
@ -110,11 +110,11 @@ impl devnull: io::Writer {
fn get_type() -> io::WriterType { io::File }
}
fn writer(path: ~str, writech: comm::Chan<comm::Chan<line>>, size: uint)
fn writer(path: ~str, writech: oldcomm::Chan<oldcomm::Chan<line>>, size: uint)
{
let p: comm::Port<line> = comm::Port();
let ch = comm::Chan(&p);
comm::send(writech, ch);
let p: oldcomm::Port<line> = oldcomm::Port();
let ch = oldcomm::Chan(&p);
oldcomm::send(writech, ch);
let cout: io::Writer = match path {
~"" => {
{dn: 0} as io::Writer
@ -134,7 +134,7 @@ fn writer(path: ~str, writech: comm::Chan<comm::Chan<line>>, size: uint)
let mut done = 0_u;
let mut i = 0_u;
while i < size {
let aline = comm::recv(p);
let aline = oldcomm::recv(p);
if aline.i == done {
debug!("W %u", aline.i);
cout.write(aline.b);
@ -178,12 +178,12 @@ fn main() {
let size = if vec::len(args) < 2_u { 80_u }
else { uint::from_str(args[1]).get() };
let writep = comm::Port();
let writech = comm::Chan(&writep);
let writep = oldcomm::Port();
let writech = oldcomm::Chan(&writep);
do task::spawn |move path| {
writer(copy path, writech, size);
};
let ch = comm::recv(writep);
let ch = oldcomm::recv(writep);
for uint::range(0_u, size) |j| {
task::spawn(|| chanmb(j, size, ch) );
if j % yieldevery == 0_u {

View File

@ -14,7 +14,7 @@
A parallel version of fibonacci numbers.
This version is meant mostly as a way of stressing and benchmarking
the task system. It supports a lot of command-line arguments to
the task system. It supports a lot of oldcommand-line arguments to
control how it runs.
*/

View File

@ -1,63 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Based on threadring.erlang by Jira Isa
extern mod std;
const n_threads: int = 503;
fn start(+token: int) {
use iter::*;
let p = comm::Port();
let mut ch = comm::Chan(&p);
for int::range(2, n_threads + 1) |i| {
let id = n_threads + 2 - i;
let to_child = do task::spawn_listener::<int> |p, copy ch| {
roundtrip(id, p, ch)
};
ch = to_child;
}
comm::send(ch, token);
roundtrip(1, p, ch);
}
fn roundtrip(id: int, p: comm::Port<int>, ch: comm::Chan<int>) {
while (true) {
match comm::recv(p) {
1 => {
io::println(fmt!("%d\n", id));
return;
}
token => {
debug!("%d %d", id, token);
comm::send(ch, token - 1);
if token <= n_threads {
return;
}
}
}
}
}
fn main() {
let args = os::args();
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"2000000"]
} else if args.len() <= 1u {
~[~"", ~"1000"]
} else {
args
};
let token = int::from_str(args[1]).get();
start(token);
}

View File

@ -20,20 +20,20 @@
// Creates in the background 'num_tasks' tasks, all blocked forever.
// Doesn't return until all such tasks are ready, but doesn't block forever itself.
fn grandchild_group(num_tasks: uint) {
let po = comm::Port();
let ch = comm::Chan(&po);
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
for num_tasks.times {
do task::spawn { // linked
comm::send(ch, ());
comm::recv(comm::Port::<()>()); // block forever
oldcomm::send(ch, ());
oldcomm::recv(oldcomm::Port::<()>()); // block forever
}
}
error!("Grandchild group getting started");
for num_tasks.times {
// Make sure all above children are fully spawned; i.e., enlisted in
// their ancestor groups.
comm::recv(po);
oldcomm::recv(po);
}
error!("Grandchild group ready to go.");
// Master grandchild task exits early.

View File

@ -11,14 +11,14 @@
// Test for concurrent tasks
enum msg {
ready(comm::Chan<msg>),
ready(oldcomm::Chan<msg>),
start,
done(int),
}
fn calc(children: uint, parent_ch: comm::Chan<msg>) {
let port = comm::Port();
let chan = comm::Chan(&port);
fn calc(children: uint, parent_ch: oldcomm::Chan<msg>) {
let port = oldcomm::Port();
let chan = oldcomm::Chan(&port);
let mut child_chs = ~[];
let mut sum = 0;
@ -29,7 +29,7 @@ fn calc(children: uint, parent_ch: comm::Chan<msg>) {
}
for iter::repeat (children) {
match comm::recv(port) {
match oldcomm::recv(port) {
ready(child_ch) => {
child_chs.push(child_ch);
}
@ -37,25 +37,25 @@ fn calc(children: uint, parent_ch: comm::Chan<msg>) {
}
}
comm::send(parent_ch, ready(chan));
oldcomm::send(parent_ch, ready(chan));
match comm::recv(port) {
match oldcomm::recv(port) {
start => {
for vec::each(child_chs) |child_ch| {
comm::send(*child_ch, start);
oldcomm::send(*child_ch, start);
}
}
_ => fail ~"task-perf-one-million failed (port not in start state)"
}
for iter::repeat (children) {
match comm::recv(port) {
match oldcomm::recv(port) {
done(child_sum) => { sum += child_sum; }
_ => fail ~"task-perf-one-million failed (port not done)"
}
}
comm::send(parent_ch, done(sum + 1));
oldcomm::send(parent_ch, done(sum + 1));
}
fn main() {
@ -69,18 +69,18 @@ fn main() {
};
let children = uint::from_str(args[1]).get();
let port = comm::Port();
let chan = comm::Chan(&port);
let port = oldcomm::Port();
let chan = oldcomm::Chan(&port);
do task::spawn {
calc(children, chan);
};
match comm::recv(port) {
match oldcomm::recv(port) {
ready(chan) => {
comm::send(chan, start);
oldcomm::send(chan, start);
}
_ => fail ~"task-perf-one-million failed (port not ready)"
}
let sum = match comm::recv(port) {
let sum = match oldcomm::recv(port) {
done(sum) => { sum }
_ => fail ~"task-perf-one-million failed (port not done)"
};

View File

@ -13,7 +13,7 @@
This is meant primarily to demonstrate Rust's MapReduce framework.
It takes a list of files on the command line and outputs a list of
It takes a list of files on the oldcommand line and outputs a list of
words along with how many times each word is used.
*/
@ -32,10 +32,10 @@ use io::{ReaderUtil, WriterUtil};
use std::time;
use comm::Chan;
use comm::Port;
use comm::recv;
use comm::send;
use oldcomm::Chan;
use oldcomm::Port;
use oldcomm::recv;
use oldcomm::send;
use cmp::Eq;
use to_bytes::IterBytes;

View File

@ -12,7 +12,7 @@
extern mod std;
use std::arc;
use comm::*;
use oldcomm::*;
fn main() {
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

View File

@ -10,7 +10,7 @@
extern mod std;
use std::arc;
use comm::*;
use oldcomm::*;
fn main() {
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

View File

@ -10,20 +10,20 @@
fn main() {
struct foo {
_x: comm::Port<()>,
_x: oldcomm::Port<()>,
}
impl foo : Drop {
fn finalize(&self) {}
}
fn foo(x: comm::Port<()>) -> foo {
fn foo(x: oldcomm::Port<()>) -> foo {
foo {
_x: x
}
}
let x = ~mut Some(foo(comm::Port()));
let x = ~mut Some(foo(oldcomm::Port()));
do task::spawn |move x| { //~ ERROR not a sendable value
let mut y = None;

View File

@ -25,7 +25,7 @@ fn foo(i:int, j: @~str) -> foo {
fn main() {
let cat = ~"kitty";
let po = comm::Port(); //~ ERROR missing `owned`
let ch = comm::Chan(&po); //~ ERROR missing `owned`
comm::send(ch, foo(42, @(move cat))); //~ ERROR missing `owned`
let po = oldcomm::Port(); //~ ERROR missing `owned`
let ch = oldcomm::Chan(&po); //~ ERROR missing `owned`
oldcomm::send(ch, foo(42, @(move cat))); //~ ERROR missing `owned`
}

View File

@ -12,8 +12,8 @@
// error-pattern:1 == 2
extern mod std;
use comm::Port;
use comm::recv;
use oldcomm::Port;
use oldcomm::recv;
fn child() { assert (1 == 2); }

View File

@ -12,9 +12,9 @@
// error-pattern:fail
extern mod std;
use comm::Chan;
use comm::Port;
use comm::recv;
use oldcomm::Chan;
use oldcomm::Port;
use oldcomm::recv;
fn child() { fail; }

View File

@ -12,8 +12,8 @@
// error-pattern:fail
extern mod std;
use comm::Port;
use comm::recv;
use oldcomm::Port;
use oldcomm::recv;
fn grandchild() { fail ~"grandchild dies"; }

View File

@ -11,9 +11,9 @@
// error-pattern:1 == 2
extern mod std;
use comm::Chan;
use comm::Port;
use comm::recv;
use oldcomm::Chan;
use oldcomm::Port;
use oldcomm::recv;
fn child() { assert (1 == 2); }

View File

@ -10,10 +10,10 @@
// error-pattern:meep
extern mod std;
use comm::Chan;
use comm::Port;
use comm::send;
use comm::recv;
use oldcomm::Chan;
use oldcomm::Port;
use oldcomm::send;
use oldcomm::recv;
fn echo<T: Owned>(c: Chan<T>, oc: Chan<Chan<T>>) {
// Tests that the type argument in port gets

View File

@ -19,9 +19,9 @@ fn goodfail() {
fn main() {
task::spawn(|| goodfail() );
let po = comm::Port();
let po = oldcomm::Port();
// We shouldn't be able to get past this recv since there's no
// message available
let i: int = comm::recv(po);
let i: int = oldcomm::recv(po);
fail ~"badfail";
}

View File

@ -13,14 +13,14 @@
extern mod std;
fn f(c: comm::_chan<int>) {
fn f(c: oldcomm::_chan<int>) {
type t = {_0: int, _1: int, _2: int};
// Allocate a box.
let x: @t = @{_0: 1, _1: 2, _2: 3};
// Signal parent that we've allocated a box.
comm::send(c, 1);
oldcomm::send(c, 1);
loop {
@ -31,12 +31,12 @@ fn f(c: comm::_chan<int>) {
// sending to the channel are never received
// by the parent, therefore this test cases drops
// messages on the floor
comm::send(c, 1);
oldcomm::send(c, 1);
}
}
fn main() {
let p = comm::mk_port();
let p = oldcomm::mk_port();
task::_spawn(bind f(p.mk_chan()));
let i: int;

View File

@ -15,7 +15,7 @@
extern mod std;
// These tests used to be separate files, but I wanted to refactor all
// the common code.
// the oldcommon code.
use cmp::Eq;
use std::ebml;

View File

@ -10,25 +10,25 @@
// except according to those terms.
fn a(c: core::comm::Chan<int>) { core::comm::send(c, 10); }
fn a(c: core::oldcomm::Chan<int>) { core::oldcomm::send(c, 10); }
fn main() {
let p = core::comm::Port();
let ch = core::comm::Chan(&p);
let p = core::oldcomm::Port();
let ch = core::oldcomm::Chan(&p);
task::spawn(|| a(ch) );
task::spawn(|| a(ch) );
let mut n: int = 0;
n = core::comm::recv(p);
n = core::comm::recv(p);
n = core::oldcomm::recv(p);
n = core::oldcomm::recv(p);
// debug!("Finished.");
}
fn b(c: core::comm::Chan<int>) {
fn b(c: core::oldcomm::Chan<int>) {
// debug!("task b0");
// debug!("task b1");
// debug!("task b2");
// debug!("task b3");
// debug!("task b4");
// debug!("task b5");
core::comm::send(c, 10);
core::oldcomm::send(c, 10);
}

View File

@ -10,28 +10,28 @@
// except according to those terms.
fn a(c: core::comm::Chan<int>) {
fn a(c: core::oldcomm::Chan<int>) {
debug!("task a0");
debug!("task a1");
core::comm::send(c, 10);
core::oldcomm::send(c, 10);
}
fn main() {
let p = core::comm::Port();
let ch = core::comm::Chan(&p);
let p = core::oldcomm::Port();
let ch = core::oldcomm::Chan(&p);
task::spawn(|| a(ch) );
task::spawn(|| b(ch) );
let mut n: int = 0;
n = core::comm::recv(p);
n = core::comm::recv(p);
n = core::oldcomm::recv(p);
n = core::oldcomm::recv(p);
debug!("Finished.");
}
fn b(c: core::comm::Chan<int>) {
fn b(c: core::oldcomm::Chan<int>) {
debug!("task b0");
debug!("task b1");
debug!("task b2");
debug!("task b2");
debug!("task b3");
core::comm::send(c, 10);
core::oldcomm::send(c, 10);
}

View File

@ -10,7 +10,7 @@
// except according to those terms.
fn a(c: core::comm::Chan<int>) {
fn a(c: core::oldcomm::Chan<int>) {
if true {
debug!("task a");
debug!("task a");
@ -18,7 +18,7 @@ fn a(c: core::comm::Chan<int>) {
debug!("task a");
debug!("task a");
}
core::comm::send(c, 10);
core::oldcomm::send(c, 10);
}
fn k(x: int) -> int { return 15; }
@ -33,19 +33,19 @@ fn g(x: int, y: ~str) -> int {
fn main() {
let mut n: int = 2 + 3 * 7;
let s: ~str = ~"hello there";
let p = comm::Port();
let ch = core::comm::Chan(&p);
let p = oldcomm::Port();
let ch = core::oldcomm::Chan(&p);
task::spawn(|| a(ch) );
task::spawn(|| b(ch) );
let mut x: int = 10;
x = g(n, s);
log(debug, x);
n = core::comm::recv(p);
n = core::comm::recv(p);
n = core::oldcomm::recv(p);
n = core::oldcomm::recv(p);
debug!("children finished, root finishing");
}
fn b(c: core::comm::Chan<int>) {
fn b(c: core::oldcomm::Chan<int>) {
if true {
debug!("task b");
debug!("task b");
@ -54,5 +54,5 @@ fn b(c: core::comm::Chan<int>) {
debug!("task b");
debug!("task b");
}
core::comm::send(c, 10);
core::oldcomm::send(c, 10);
}

View File

@ -24,9 +24,9 @@
// course preferable, as the value itself is
// irrelevant).
fn foo(&&x: ()) -> core::comm::Port<()> {
let p = core::comm::Port();
let c = core::comm::Chan(&p);
fn foo(&&x: ()) -> core::oldcomm::Port<()> {
let p = core::oldcomm::Port();
let c = core::oldcomm::Chan(&p);
do task::spawn() |copy c, copy x| {
c.send(x);
}

View File

@ -18,7 +18,7 @@
extern mod cci_capture_clause;
use comm::recv;
use oldcomm::recv;
fn main() {
cci_capture_clause::foo(()).recv()

View File

@ -10,32 +10,32 @@
// Issue #763
enum request { quit, close(core::comm::Chan<bool>), }
enum request { quit, close(core::oldcomm::Chan<bool>), }
type ctx = core::comm::Chan<request>;
type ctx = core::oldcomm::Chan<request>;
fn request_task(c: core::comm::Chan<ctx>) {
let p = core::comm::Port();
core::comm::send(c, core::comm::Chan(&p));
fn request_task(c: core::oldcomm::Chan<ctx>) {
let p = core::oldcomm::Port();
core::oldcomm::send(c, core::oldcomm::Chan(&p));
let mut req: request;
req = core::comm::recv(p);
req = core::oldcomm::recv(p);
// Need to drop req before receiving it again
req = core::comm::recv(p);
req = core::oldcomm::recv(p);
}
fn new_cx() -> ctx {
let p = core::comm::Port();
let ch = core::comm::Chan(&p);
let p = core::oldcomm::Port();
let ch = core::oldcomm::Chan(&p);
let t = task::spawn(|| request_task(ch) );
let mut cx: ctx;
cx = core::comm::recv(p);
cx = core::oldcomm::recv(p);
return cx;
}
fn main() {
let cx = new_cx();
let p = core::comm::Port::<bool>();
core::comm::send(cx, close(core::comm::Chan(&p)));
core::comm::send(cx, quit);
let p = core::oldcomm::Port::<bool>();
core::oldcomm::send(cx, close(core::oldcomm::Chan(&p)));
core::oldcomm::send(cx, quit);
}

View File

@ -11,17 +11,17 @@
fn main() {
let p = comm::Port();
let ch = core::comm::Chan(&p);
let p = oldcomm::Port();
let ch = core::oldcomm::Chan(&p);
let t = task::spawn(|| child(ch) );
let y = core::comm::recv(p);
let y = core::oldcomm::recv(p);
error!("received");
log(error, y);
assert (y == 10);
}
fn child(c: core::comm::Chan<int>) {
fn child(c: core::oldcomm::Chan<int>) {
error!("sending");
core::comm::send(c, 10);
core::oldcomm::send(c, 10);
error!("value sent");
}

View File

@ -11,12 +11,12 @@
fn main() {
let po = core::comm::Port();
let ch = core::comm::Chan(&po);
core::comm::send(ch, 10);
let i = core::comm::recv(po);
let po = core::oldcomm::Port();
let ch = core::oldcomm::Chan(&po);
core::oldcomm::send(ch, 10);
let i = core::oldcomm::recv(po);
assert (i == 10);
core::comm::send(ch, 11);
let j = core::comm::recv(po);
core::oldcomm::send(ch, 11);
let j = core::oldcomm::recv(po);
assert (j == 11);
}

View File

@ -20,10 +20,10 @@ extern mod std;
use std::map;
use std::map::HashMap;
use comm::Chan;
use comm::Port;
use comm::send;
use comm::recv;
use oldcomm::Chan;
use oldcomm::Port;
use oldcomm::send;
use oldcomm::recv;
fn map(filename: ~str, emit: map_reduce::putter) { emit(filename, ~"1"); }

View File

@ -15,19 +15,19 @@
https://github.com/graydon/rust/issues/507
*/
fn grandchild(c: core::comm::Chan<int>) { core::comm::send(c, 42); }
fn grandchild(c: core::oldcomm::Chan<int>) { core::oldcomm::send(c, 42); }
fn child(c: core::comm::Chan<int>) {
fn child(c: core::oldcomm::Chan<int>) {
task::spawn(|| grandchild(c) )
}
fn main() {
let p = core::comm::Port();
let ch = core::comm::Chan(&p);
let p = core::oldcomm::Port();
let ch = core::oldcomm::Chan(&p);
task::spawn(|| child(ch) );
let x: int = core::comm::recv(p);
let x: int = core::oldcomm::recv(p);
log(debug, x);

View File

@ -10,18 +10,18 @@
enum msg { closed, received(~[u8]), }
fn producer(c: core::comm::Chan<~[u8]>) {
core::comm::send(c, ~[1u8, 2u8, 3u8, 4u8]);
fn producer(c: core::oldcomm::Chan<~[u8]>) {
core::oldcomm::send(c, ~[1u8, 2u8, 3u8, 4u8]);
let empty: ~[u8] = ~[];
core::comm::send(c, empty);
core::oldcomm::send(c, empty);
}
fn packager(cb: core::comm::Chan<core::comm::Chan<~[u8]>>, msg: core::comm::Chan<msg>) {
let p: core::comm::Port<~[u8]> = core::comm::Port();
core::comm::send(cb, core::comm::Chan(&p));
fn packager(cb: core::oldcomm::Chan<core::oldcomm::Chan<~[u8]>>, msg: core::oldcomm::Chan<msg>) {
let p: core::oldcomm::Port<~[u8]> = core::oldcomm::Port();
core::oldcomm::send(cb, core::oldcomm::Chan(&p));
loop {
debug!("waiting for bytes");
let data = core::comm::recv(p);
let data = core::oldcomm::recv(p);
debug!("got bytes");
if vec::len(data) == 0u {
debug!("got empty bytes, quitting");
@ -29,26 +29,26 @@ fn packager(cb: core::comm::Chan<core::comm::Chan<~[u8]>>, msg: core::comm::Chan
}
debug!("sending non-empty buffer of length");
log(debug, vec::len(data));
core::comm::send(msg, received(data));
core::oldcomm::send(msg, received(data));
debug!("sent non-empty buffer");
}
debug!("sending closed message");
core::comm::send(msg, closed);
core::oldcomm::send(msg, closed);
debug!("sent closed message");
}
fn main() {
let p: core::comm::Port<msg> = core::comm::Port();
let ch = core::comm::Chan(&p);
let recv_reader: core::comm::Port<core::comm::Chan<~[u8]>> = core::comm::Port();
let recv_reader_chan = core::comm::Chan(&recv_reader);
let p: core::oldcomm::Port<msg> = core::oldcomm::Port();
let ch = core::oldcomm::Chan(&p);
let recv_reader: core::oldcomm::Port<core::oldcomm::Chan<~[u8]>> = core::oldcomm::Port();
let recv_reader_chan = core::oldcomm::Chan(&recv_reader);
let pack = task::spawn(|| packager(recv_reader_chan, ch) );
let source_chan: core::comm::Chan<~[u8]> = core::comm::recv(recv_reader);
let source_chan: core::oldcomm::Chan<~[u8]> = core::oldcomm::recv(recv_reader);
let prod = task::spawn(|| producer(source_chan) );
loop {
let msg = core::comm::recv(p);
let msg = core::oldcomm::recv(p);
match msg {
closed => { debug!("Got close message"); break; }
received(data) => {

View File

@ -10,14 +10,14 @@
fn a() {
fn doit() {
fn b(c: core::comm::Chan<core::comm::Chan<int>>) {
let p = core::comm::Port();
core::comm::send(c, core::comm::Chan(&p));
fn b(c: core::oldcomm::Chan<core::oldcomm::Chan<int>>) {
let p = core::oldcomm::Port();
core::oldcomm::send(c, core::oldcomm::Chan(&p));
}
let p = core::comm::Port();
let ch = core::comm::Chan(&p);
let p = core::oldcomm::Port();
let ch = core::oldcomm::Chan(&p);
task::spawn(|| b(ch) );
core::comm::recv(p);
core::oldcomm::recv(p);
}
let mut i = 0;
while i < 100 {

View File

@ -1,13 +1,13 @@
fn producer(c: core::comm::Chan<~[u8]>) {
core::comm::send(c,
fn producer(c: core::oldcomm::Chan<~[u8]>) {
core::oldcomm::send(c,
~[1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8, 11u8, 12u8,
13u8]);
}
fn main() {
let p: core::comm::Port<~[u8]> = core::comm::Port();
let ch = core::comm::Chan(&p);
let p: core::oldcomm::Port<~[u8]> = core::oldcomm::Port();
let ch = core::oldcomm::Chan(&p);
let prod = task::spawn(|| producer(ch) );
let data: ~[u8] = core::comm::recv(p);
let data: ~[u8] = core::oldcomm::recv(p);
}

View File

@ -10,21 +10,21 @@
// except according to those terms.
fn main() {
let p = core::comm::Port();
let ch = core::comm::Chan(&p);
let p = core::oldcomm::Port();
let ch = core::oldcomm::Chan(&p);
let mut y: int;
task::spawn(|| child(ch) );
y = core::comm::recv(p);
y = core::oldcomm::recv(p);
debug!("received 1");
log(debug, y);
assert (y == 10);
task::spawn(|| child(ch) );
y = core::comm::recv(p);
y = core::oldcomm::recv(p);
debug!("received 2");
log(debug, y);
assert (y == 10);
}
fn child(c: core::comm::Chan<int>) { core::comm::send(c, 10); }
fn child(c: core::oldcomm::Chan<int>) { core::oldcomm::send(c, 10); }

View File

@ -12,23 +12,23 @@
extern mod std;
fn sub(parent: comm::Chan<int>, id: int) {
fn sub(parent: oldcomm::Chan<int>, id: int) {
if id == 0 {
comm::send(parent, 0);
oldcomm::send(parent, 0);
} else {
let p = comm::Port();
let ch = comm::Chan(&p);
let p = oldcomm::Port();
let ch = oldcomm::Chan(&p);
let child = task::spawn(|| sub(ch, id - 1) );
let y = comm::recv(p);
comm::send(parent, y + 1);
let y = oldcomm::recv(p);
oldcomm::send(parent, y + 1);
}
}
fn main() {
let p = comm::Port();
let ch = comm::Chan(&p);
let p = oldcomm::Port();
let ch = oldcomm::Chan(&p);
let child = task::spawn(|| sub(ch, 200) );
let y = comm::recv(p);
let y = oldcomm::recv(p);
debug!("transmission complete");
log(debug, y);
assert (y == 200);

View File

@ -11,6 +11,6 @@
/*
* This is a multi-line comment.
* This is a multi-line oldcomment.
*/
fn main() { }

View File

@ -13,7 +13,7 @@
// Regression tests for circular_buffer when using a unit
// that has a size that is not a power of two
// A 12-byte unit to core::comm::send over the channel
// A 12-byte unit to core::oldcomm::send over the channel
type record = {val1: u32, val2: u32, val3: u32};
@ -22,52 +22,52 @@ type record = {val1: u32, val2: u32, val3: u32};
// power of two so needs to be rounded up. Don't trigger any
// assertions.
fn test_init() {
let myport = core::comm::Port();
let mychan = core::comm::Chan(&myport);
let myport = core::oldcomm::Port();
let mychan = core::oldcomm::Chan(&myport);
let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
core::comm::send(mychan, val);
core::oldcomm::send(mychan, val);
}
// Dump lots of items into the channel so it has to grow.
// Don't trigger any assertions.
fn test_grow() {
let myport = core::comm::Port();
let mychan = core::comm::Chan(&myport);
let myport = core::oldcomm::Port();
let mychan = core::oldcomm::Chan(&myport);
for uint::range(0u, 100u) |i| {
let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
core::comm::send(mychan, val);
core::oldcomm::send(mychan, val);
}
}
// Don't allow the buffer to shrink below it's original size
fn test_shrink1() {
let myport = core::comm::Port();
let mychan = core::comm::Chan(&myport);
core::comm::send(mychan, 0i8);
let x = core::comm::recv(myport);
let myport = core::oldcomm::Port();
let mychan = core::oldcomm::Chan(&myport);
core::oldcomm::send(mychan, 0i8);
let x = core::oldcomm::recv(myport);
}
fn test_shrink2() {
let myport = core::comm::Port();
let mychan = core::comm::Chan(&myport);
let myport = core::oldcomm::Port();
let mychan = core::oldcomm::Chan(&myport);
for uint::range(0u, 100u) |_i| {
let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
core::comm::send(mychan, val);
core::oldcomm::send(mychan, val);
}
for uint::range(0u, 100u) |_i| { let x = core::comm::recv(myport); }
for uint::range(0u, 100u) |_i| { let x = core::oldcomm::recv(myport); }
}
// Test rotating the buffer when the unit size is not a power of two
fn test_rotate() {
let myport = core::comm::Port();
let mychan = core::comm::Chan(&myport);
let myport = core::oldcomm::Port();
let mychan = core::oldcomm::Chan(&myport);
for uint::range(0u, 100u) |i| {
let val = {val1: i as u32, val2: i as u32, val3: i as u32};
core::comm::send(mychan, val);
let x = core::comm::recv(myport);
core::oldcomm::send(mychan, val);
let x = core::oldcomm::recv(myport);
assert (x.val1 == i as u32);
assert (x.val2 == i as u32);
assert (x.val3 == i as u32);
@ -78,16 +78,16 @@ fn test_rotate() {
// Test rotating and growing the buffer when
// the unit size is not a power of two
fn test_rotate_grow() {
let myport = core::comm::Port::<record>();
let mychan = core::comm::Chan(&myport);
let myport = core::oldcomm::Port::<record>();
let mychan = core::oldcomm::Chan(&myport);
for uint::range(0u, 10u) |j| {
for uint::range(0u, 10u) |i| {
let val: record =
{val1: i as u32, val2: i as u32, val3: i as u32};
core::comm::send(mychan, val);
core::oldcomm::send(mychan, val);
}
for uint::range(0u, 10u) |i| {
let x = core::comm::recv(myport);
let x = core::oldcomm::recv(myport);
assert (x.val1 == i as u32);
assert (x.val2 == i as u32);
assert (x.val3 == i as u32);

View File

@ -25,8 +25,8 @@ extern mod rustrt {
}
fn main() unsafe {
let po = comm::Port();
let ch = comm::Chan(&po);
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
let parent_sched_id = rustrt::rust_get_sched_id();
error!("parent %?", parent_sched_id);
let num_threads = 1u;
@ -39,10 +39,10 @@ fn main() unsafe {
error!("child_sched_id %?", child_sched_id);
assert child_sched_id != parent_sched_id;
assert child_sched_id == new_sched_id;
comm::send(ch, ());
oldcomm::send(ch, ());
};
let fptr = cast::reinterpret_cast(&ptr::addr_of(&f));
rustrt::start_task(new_task_id, fptr);
cast::forget(move f);
comm::recv(po);
oldcomm::recv(po);
}

View File

@ -17,13 +17,13 @@ fn die() {
fn iloop() {
task::spawn(|| die() );
let p = comm::Port::<()>();
let c = comm::Chan(&p);
let p = oldcomm::Port::<()>();
let c = oldcomm::Chan(&p);
loop {
// Sending and receiving here because these actions yield,
// at which point our child can kill us
comm::send(c, ());
comm::recv(p);
oldcomm::send(c, ());
oldcomm::recv(p);
}
}

View File

@ -23,12 +23,12 @@ fn test(f: int) -> test {
}
fn main() {
let p = core::comm::Port();
let c = core::comm::Chan(&p);
let p = core::oldcomm::Port();
let c = core::oldcomm::Chan(&p);
do task::spawn() {
let p = core::comm::Port();
c.send(core::comm::Chan(&p));
let p = core::oldcomm::Port();
c.send(core::oldcomm::Chan(&p));
let _r = p.recv();
}

View File

@ -11,8 +11,8 @@
// tests that ctrl's type gets inferred properly
type command<K: Owned, V: Owned> = {key: K, val: V};
fn cache_server<K: Owned, V: Owned>(c: core::comm::Chan<core::comm::Chan<command<K, V>>>) {
let ctrl = core::comm::Port();
core::comm::send(c, core::comm::Chan(&ctrl));
fn cache_server<K: Owned, V: Owned>(c: oldcomm::Chan<oldcomm::Chan<command<K, V>>>) {
let ctrl = oldcomm::Port();
oldcomm::send(c, oldcomm::Chan(&ctrl));
}
fn main() { }

View File

@ -23,7 +23,7 @@ fn foo(i:int, j: char) -> foo {
}
fn main() {
let po = comm::Port::<foo>();
let ch = comm::Chan(&po);
comm::send(ch, foo(42, 'c'));
let po = oldcomm::Port::<foo>();
let ch = oldcomm::Chan(&po);
oldcomm::send(ch, foo(42, 'c'));
}

View File

@ -13,8 +13,8 @@
extern mod std;
use comm::Chan;
use comm::send;
use oldcomm::Chan;
use oldcomm::send;
fn main() { test05(); }

View File

@ -17,14 +17,14 @@
extern mod std;
type ctx = comm::Chan<int>;
type ctx = oldcomm::Chan<int>;
fn iotask(cx: ctx, ip: ~str) {
assert (ip == ~"localhost");
}
fn main() {
let p = comm::Port::<int>();
let ch = comm::Chan(&p);
let p = oldcomm::Port::<int>();
let ch = oldcomm::Chan(&p);
task::spawn(|| iotask(ch, ~"localhost") );
}

View File

@ -11,7 +11,7 @@
extern mod std;
fn main() {
let p = comm::Port();
let c = comm::Chan(&p);
comm::send(c, ~"coffee");
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
oldcomm::send(c, ~"coffee");
}

View File

@ -11,7 +11,7 @@
extern mod std;
fn main() {
let p = comm::Port();
let c = comm::Chan(&p);
comm::send(c, ~"coffee");
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
oldcomm::send(c, ~"coffee");
}

View File

@ -12,8 +12,8 @@ extern mod std;
fn main() {
let c = {
let p = comm::Port();
comm::Chan(&p)
let p = oldcomm::Port();
oldcomm::Chan(&p)
};
comm::send(c, ~"coffee");
oldcomm::send(c, ~"coffee");
}

View File

@ -13,16 +13,16 @@ extern mod std;
// We're trying to trigger a race between send and port destruction that
// results in the string not being freed
fn starship(&&ch: comm::Chan<~str>) {
fn starship(&&ch: oldcomm::Chan<~str>) {
for int::range(0, 10) |_i| {
comm::send(ch, ~"pew pew");
oldcomm::send(ch, ~"pew pew");
}
}
fn starbase() {
for int::range(0, 10) |_i| {
let p = comm::Port();
let c = comm::Chan(&p);
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
task::spawn(|| starship(c) );
task::yield();
}

View File

@ -16,9 +16,9 @@ extern mod std;
// any size, but rustc currently can because they do have size. Whether
// or not this is desirable I don't know, but here's a regression test.
fn main() {
let po = comm::Port();
let ch = comm::Chan(&po);
comm::send(ch, ());
let n: () = comm::recv(po);
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
oldcomm::send(ch, ());
let n: () = oldcomm::recv(po);
assert (n == ());
}

View File

@ -17,12 +17,12 @@ fn main() {
test06();
}
fn test00_start(ch: core::comm::Chan<int>, message: int, count: int) {
fn test00_start(ch: core::oldcomm::Chan<int>, message: int, count: int) {
debug!("Starting test00_start");
let mut i: int = 0;
while i < count {
debug!("Sending Message");
core::comm::send(ch, message + 0);
core::oldcomm::send(ch, message + 0);
i = i + 1;
}
debug!("Ending test00_start");
@ -33,8 +33,8 @@ fn test00() {
let number_of_messages: int = 4;
debug!("Creating tasks");
let po = core::comm::Port();
let ch = core::comm::Chan(&po);
let po = core::oldcomm::Port();
let ch = core::oldcomm::Chan(&po);
let mut i: int = 0;
@ -50,7 +50,7 @@ fn test00() {
let mut sum: int = 0;
for results.each |r| {
i = 0;
while i < number_of_messages { sum += core::comm::recv(po); i = i + 1; }
while i < number_of_messages { sum += core::oldcomm::recv(po); i = i + 1; }
}
for results.each |r| { r.recv(); }
@ -63,19 +63,19 @@ fn test00() {
}
fn test01() {
let p = core::comm::Port();
let p = core::oldcomm::Port();
debug!("Reading from a port that is never written to.");
let value: int = core::comm::recv(p);
let value: int = core::oldcomm::recv(p);
log(debug, value);
}
fn test02() {
let p = core::comm::Port();
let c = core::comm::Chan(&p);
let p = core::oldcomm::Port();
let c = core::oldcomm::Chan(&p);
debug!("Writing to a local task channel.");
core::comm::send(c, 42);
core::oldcomm::send(c, 42);
debug!("Reading from a local task port.");
let value: int = core::comm::recv(p);
let value: int = core::oldcomm::recv(p);
log(debug, value);
}
@ -93,22 +93,22 @@ fn test04() {
debug!("Finishing up.");
}
fn test05_start(ch: core::comm::Chan<int>) {
core::comm::send(ch, 10);
core::comm::send(ch, 20);
core::comm::send(ch, 30);
core::comm::send(ch, 30);
core::comm::send(ch, 30);
fn test05_start(ch: core::oldcomm::Chan<int>) {
core::oldcomm::send(ch, 10);
core::oldcomm::send(ch, 20);
core::oldcomm::send(ch, 30);
core::oldcomm::send(ch, 30);
core::oldcomm::send(ch, 30);
}
fn test05() {
let po = core::comm::Port();
let ch = core::comm::Chan(&po);
let po = core::oldcomm::Port();
let ch = core::oldcomm::Chan(&po);
task::spawn(|| test05_start(ch) );
let mut value: int;
value = core::comm::recv(po);
value = core::comm::recv(po);
value = core::comm::recv(po);
value = core::oldcomm::recv(po);
value = core::oldcomm::recv(po);
value = core::oldcomm::recv(po);
log(debug, value);
}

View File

@ -18,7 +18,7 @@ extern mod std;
fn child() { }
struct notify {
ch: comm::Chan<bool>, v: @mut bool,
ch: oldcomm::Chan<bool>, v: @mut bool,
}
impl notify : Drop {
@ -29,19 +29,19 @@ impl notify : Drop {
task::failing(),
*(self.v));
let b = *(self.v);
comm::send(self.ch, b);
oldcomm::send(self.ch, b);
}
}
fn notify(ch: comm::Chan<bool>, v: @mut bool) -> notify {
fn notify(ch: oldcomm::Chan<bool>, v: @mut bool) -> notify {
notify {
ch: ch,
v: v
}
}
fn joinable(+f: fn~()) -> comm::Port<bool> {
fn wrapper(+c: comm::Chan<bool>, +f: fn()) {
fn joinable(+f: fn~()) -> oldcomm::Port<bool> {
fn wrapper(+c: oldcomm::Chan<bool>, +f: fn()) {
let b = @mut false;
error!("wrapper: task=%? allocated v=%x",
task::get_task(),
@ -50,14 +50,14 @@ fn joinable(+f: fn~()) -> comm::Port<bool> {
f();
*b = true;
}
let p = comm::Port();
let c = comm::Chan(&p);
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
do task::spawn_unlinked { wrapper(c, copy f) };
p
}
fn join(port: comm::Port<bool>) -> bool {
comm::recv(port)
fn join(port: oldcomm::Port<bool>) -> bool {
oldcomm::recv(port)
}
fn main() {
@ -76,15 +76,15 @@ fn main() {
let p1;
let p2;
p1 = comm::Port::<int>();
p2 = comm::Port::<int>();
p1 = oldcomm::Port::<int>();
p2 = oldcomm::Port::<int>();
assert (p1 == p1);
assert (p1 != p2);
// channels
let c1 = comm::Chan(p1);
let c2 = comm::Chan(p2);
let c1 = oldcomm::Chan(p1);
let c2 = oldcomm::Chan(p2);
assert (c1 == c1);
assert (c1 != c2);

View File

@ -14,7 +14,7 @@
// the join.
struct notify {
ch: comm::Chan<bool>, v: @mut bool,
ch: oldcomm::Chan<bool>, v: @mut bool,
}
impl notify : Drop {
@ -25,19 +25,19 @@ impl notify : Drop {
task::failing(),
*(self.v));
let b = *(self.v);
comm::send(self.ch, b);
oldcomm::send(self.ch, b);
}
}
fn notify(ch: comm::Chan<bool>, v: @mut bool) -> notify {
fn notify(ch: oldcomm::Chan<bool>, v: @mut bool) -> notify {
notify {
ch: ch,
v: v
}
}
fn joinable(+f: fn~()) -> comm::Port<bool> {
fn wrapper(+c: comm::Chan<bool>, +f: fn()) {
fn joinable(+f: fn~()) -> oldcomm::Port<bool> {
fn wrapper(+c: oldcomm::Chan<bool>, +f: fn()) {
let b = @mut false;
error!("wrapper: task=%? allocated v=%x",
task::get_task(),
@ -46,14 +46,14 @@ fn joinable(+f: fn~()) -> comm::Port<bool> {
f();
*b = true;
}
let p = comm::Port();
let c = comm::Chan(&p);
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
do task::spawn_unlinked { wrapper(c, f) };
p
}
fn join(port: comm::Port<bool>) -> bool {
comm::recv(port)
fn join(port: oldcomm::Port<bool>) -> bool {
oldcomm::recv(port)
}
fn supervised() {

View File

@ -9,8 +9,8 @@
// except according to those terms.
fn main() {
let p = comm::Port::<uint>();
let ch = comm::Chan(&p);
let p = oldcomm::Port::<uint>();
let ch = oldcomm::Chan(&p);
let x = ~1;
let x_in_parent = ptr::addr_of(&(*x)) as uint;
@ -20,17 +20,17 @@ fn main() {
task::spawn(fn~(copy ch, copy y, move x) {
let x_in_child = ptr::addr_of(&(*x)) as uint;
comm::send(ch, x_in_child);
oldcomm::send(ch, x_in_child);
let y_in_child = ptr::addr_of(&(*y)) as uint;
comm::send(ch, y_in_child);
oldcomm::send(ch, y_in_child);
});
// Ensure last-use analysis doesn't move y to child.
let _q = y;
let x_in_child = comm::recv(p);
let x_in_child = oldcomm::recv(p);
assert x_in_parent == x_in_child;
let y_in_child = comm::recv(p);
let y_in_child = oldcomm::recv(p);
assert y_in_parent != y_in_child;
}

View File

@ -10,13 +10,13 @@
extern mod std;
fn child(c: comm::Chan<~uint>, i: uint) {
comm::send(c, ~i);
fn child(c: oldcomm::Chan<~uint>, i: uint) {
oldcomm::send(c, ~i);
}
fn main() {
let p = comm::Port();
let ch = comm::Chan(&p);
let p = oldcomm::Port();
let ch = oldcomm::Chan(&p);
let n = 100u;
let mut expected = 0u;
for uint::range(0u, n) |i| {
@ -26,7 +26,7 @@ fn main() {
let mut actual = 0u;
for uint::range(0u, n) |_i| {
let j = comm::recv(p);
let j = oldcomm::recv(p);
actual += *j;
}

View File

@ -11,9 +11,9 @@
extern mod std;
fn main() {
let p = comm::Port();
let c = comm::Chan(&p);
comm::send(c, ~100);
let v = comm::recv(p);
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
oldcomm::send(c, ~100);
let v = oldcomm::recv(p);
assert v == ~100;
}

View File

@ -12,33 +12,33 @@
extern mod std;
struct complainer {
c: comm::Chan<bool>,
c: oldcomm::Chan<bool>,
}
impl complainer : Drop {
fn finalize(&self) {
error!("About to send!");
comm::send(self.c, true);
oldcomm::send(self.c, true);
error!("Sent!");
}
}
fn complainer(c: comm::Chan<bool>) -> complainer {
fn complainer(c: oldcomm::Chan<bool>) -> complainer {
error!("Hello!");
complainer {
c: c
}
}
fn f(c: comm::Chan<bool>) {
fn f(c: oldcomm::Chan<bool>) {
let _c = move complainer(c);
fail;
}
fn main() {
let p = comm::Port();
let c = comm::Chan(&p);
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
task::spawn_unlinked(|| f(c) );
error!("hiiiiiiiii");
assert comm::recv(p);
assert oldcomm::recv(p);
}

View File

@ -15,7 +15,7 @@ enum crew_of_enterprise_d {
#[captain]
jean_luc_picard,
#[commander]
#[oldcommander]
william_t_riker,
#[chief_medical_officer]
@ -24,7 +24,7 @@ enum crew_of_enterprise_d {
#[ships_councellor]
deanna_troi,
#[lieutenant_commander]
#[lieutenant_oldcommander]
data,
#[chief_of_security]