Removed old object-based chans.
This commit is contained in:
parent
7ad13392bd
commit
cc353aa17a
@ -4,7 +4,6 @@ import unsafe;
|
||||
import task;
|
||||
import task::task_id;
|
||||
|
||||
export chan_t;
|
||||
export _chan;
|
||||
export _port;
|
||||
|
||||
@ -36,44 +35,19 @@ native "rust-intrinsic" mod rusti {
|
||||
|
||||
type port_id = int;
|
||||
|
||||
type chan_t[~T] = {
|
||||
type _chan[~T] = {
|
||||
task : task_id,
|
||||
port : port_id
|
||||
};
|
||||
|
||||
resource chan_ptr(ch: *rustrt::rust_chan) {
|
||||
rustrt::drop_chan(ch);
|
||||
}
|
||||
|
||||
resource port_ptr(po: *rustrt::rust_port) {
|
||||
rustrt::drop_port(po);
|
||||
rustrt::del_port(po);
|
||||
}
|
||||
|
||||
obj _chan[~T](raw_chan : @chan_ptr) {
|
||||
fn send(v : &T) {
|
||||
rustrt::chan_send(**raw_chan,
|
||||
unsafe::reinterpret_cast(ptr::addr_of(v)));
|
||||
}
|
||||
|
||||
// Use this to get something we can send over a channel.
|
||||
fn unsafe_ptr() -> *u8 {
|
||||
rustrt::take_chan(**raw_chan);
|
||||
ret unsafe::reinterpret_cast(**raw_chan);
|
||||
}
|
||||
}
|
||||
|
||||
fn chan_from_unsafe_ptr[~T](ch : *u8) -> _chan[T] {
|
||||
_chan(@chan_ptr(unsafe::reinterpret_cast(ch)))
|
||||
}
|
||||
|
||||
obj _port[~T](raw_port : @port_ptr) {
|
||||
fn mk_chan() -> _chan[T] {
|
||||
_chan(@chan_ptr(rustrt::new_chan(**raw_port)))
|
||||
}
|
||||
|
||||
// FIXME: rename this to chan once chan is not a keyword.
|
||||
fn mk_chan2() -> chan_t[T] {
|
||||
fn mk_chan() -> _chan[T] {
|
||||
{
|
||||
task: task::get_task_id(),
|
||||
port: rustrt::get_port_id(**raw_port)
|
||||
@ -89,6 +63,6 @@ fn mk_port[~T]() -> _port[T] {
|
||||
_port(@port_ptr(rustrt::new_port(sys::size_of[T]())))
|
||||
}
|
||||
|
||||
fn send[~T](ch : chan_t[T], data : -T) {
|
||||
fn send[~T](ch : _chan[T], data : -T) {
|
||||
rustrt::chan_id_send(ch.task, ch.port, data);
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ import std::str;
|
||||
import std::comm;
|
||||
import std::task;
|
||||
|
||||
type ctx = comm::chan_t[int];
|
||||
type ctx = comm::_chan[int];
|
||||
|
||||
fn iotask(cx: ctx, ip: str) { assert (str::eq(ip, "localhost")); }
|
||||
|
||||
fn main() {
|
||||
let p = comm::mk_port[int]();
|
||||
task::_spawn(bind iotask(p.mk_chan2(), "localhost"));
|
||||
task::_spawn(bind iotask(p.mk_chan(), "localhost"));
|
||||
}
|
||||
|
@ -3,13 +3,13 @@
|
||||
use std;
|
||||
|
||||
import std::comm;
|
||||
import std::comm::chan_t;
|
||||
import std::comm::_chan;
|
||||
import std::comm::send;
|
||||
import std::task;
|
||||
|
||||
fn main() { test05(); }
|
||||
|
||||
fn test05_start(ch : chan_t[int]) {
|
||||
fn test05_start(ch : _chan[int]) {
|
||||
log_err ch;
|
||||
send(ch, 10);
|
||||
log_err "sent 10";
|
||||
@ -21,7 +21,7 @@ fn test05_start(ch : chan_t[int]) {
|
||||
|
||||
fn test05() {
|
||||
let po = comm::mk_port[int]();
|
||||
let ch = po.mk_chan2();
|
||||
let ch = po.mk_chan();
|
||||
task::_spawn(bind test05_start(ch));
|
||||
let value = po.recv();
|
||||
log_err value;
|
||||
|
@ -1,9 +1,10 @@
|
||||
use std;
|
||||
|
||||
import std::task::join;
|
||||
import std::task::_spawn;
|
||||
import std::task::join_id;
|
||||
|
||||
fn main() { test00(); }
|
||||
|
||||
fn start() { log "Started / Finished task."; }
|
||||
|
||||
fn test00() { let t: task = spawn start(); join(t); log "Completing."; }
|
||||
fn test00() { let t = _spawn(bind start()); join_id(t); log "Completing."; }
|
||||
|
@ -1,16 +1,15 @@
|
||||
// xfail-stage3
|
||||
use std;
|
||||
import std::comm;
|
||||
import std::task;
|
||||
|
||||
fn start(pcc: *u8) {
|
||||
let c = comm::chan_from_unsafe_ptr(pcc);
|
||||
fn start(c: comm::_chan[comm::_chan[int]]) {
|
||||
let p : comm::_port[int] = comm::mk_port();
|
||||
c.send(p.mk_chan().unsafe_ptr());
|
||||
comm::send(c, p.mk_chan());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let p = comm::mk_port();
|
||||
let child = spawn start(p.mk_chan().unsafe_ptr());
|
||||
let pc = p.recv();
|
||||
let c : comm::_chan[int] = comm::chan_from_unsafe_ptr(pc);
|
||||
let p = comm::mk_port[comm::_chan[int]]();
|
||||
let child = task::_spawn(bind start(p.mk_chan()));
|
||||
let c = p.recv();
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
use std;
|
||||
import std::task;
|
||||
import std::comm;
|
||||
import std::comm::send;
|
||||
|
||||
fn start(pc: *u8, start: int, number_of_messages: int) {
|
||||
let c = comm::chan_from_unsafe_ptr(pc);
|
||||
fn start(c: comm::_chan[int], start: int, number_of_messages: int) {
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { c.send(start + i); i += 1; }
|
||||
while i < number_of_messages { send(c, start + i); i += 1; }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
log "Check that we don't deadlock.";
|
||||
let p : comm::_port[int] = comm::mk_port();
|
||||
let a: task = spawn start(p.mk_chan().unsafe_ptr(), 0, 10);
|
||||
task::join(a);
|
||||
let a = task::_spawn(bind start(p.mk_chan(), 0, 10));
|
||||
task::join_id(a);
|
||||
log "Joined task";
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
use std;
|
||||
import std::comm;
|
||||
import std::comm::send;
|
||||
import std::comm::mk_port;
|
||||
|
||||
// Tests of ports and channels on various types
|
||||
@ -11,7 +12,7 @@ fn test_rec() {
|
||||
let po = comm::mk_port();
|
||||
let ch = po.mk_chan();
|
||||
let r0: r = {val0: 0, val1: 1u8, val2: '2'};
|
||||
ch.send(r0);
|
||||
send(ch, r0);
|
||||
let r1: r;
|
||||
r1 = po.recv();
|
||||
assert (r1.val0 == 0);
|
||||
@ -23,7 +24,7 @@ fn test_vec() {
|
||||
let po = comm::mk_port();
|
||||
let ch = po.mk_chan();
|
||||
let v0: [int] = ~[0, 1, 2];
|
||||
ch.send(v0);
|
||||
send(ch, v0);
|
||||
let v1: [int];
|
||||
v1 = po.recv();
|
||||
assert (v1.(0) == 0);
|
||||
@ -37,7 +38,7 @@ fn test_str() {
|
||||
let po = comm::mk_port();
|
||||
let ch = po.mk_chan();
|
||||
let s0: str = "test";
|
||||
ch.send(s0);
|
||||
send(ch, s0);
|
||||
let s1: str;
|
||||
s1 = po.recv();
|
||||
assert (s1.(0) as u8 == 't' as u8);
|
||||
@ -51,9 +52,9 @@ fn test_tag() {
|
||||
tag t { tag1; tag2(int); tag3(int, u8, char); }
|
||||
let po = comm::mk_port();
|
||||
let ch = po.mk_chan();
|
||||
ch.send(tag1);
|
||||
ch.send(tag2(10));
|
||||
ch.send(tag3(10, 11u8, 'A'));
|
||||
send(ch, tag1);
|
||||
send(ch, tag2(10));
|
||||
send(ch, tag3(10, 11u8, 'A'));
|
||||
// FIXME: Do port semantics really guarantee these happen in order?
|
||||
let t1: t;
|
||||
t1 = po.recv();
|
||||
@ -69,13 +70,11 @@ fn test_chan() {
|
||||
let ch = po.mk_chan();
|
||||
let po0 = comm::mk_port();
|
||||
let ch0 = po0.mk_chan();
|
||||
ch.send(ch0.unsafe_ptr());
|
||||
let pch1;
|
||||
pch1 = po.recv();
|
||||
let ch1 = comm::chan_from_unsafe_ptr(pch1);
|
||||
send(ch, ch0);
|
||||
let ch1 = po.recv();
|
||||
// Does the transmitted channel still work?
|
||||
|
||||
ch1.send(10);
|
||||
send(ch1, 10);
|
||||
let i: int;
|
||||
i = po0.recv();
|
||||
assert (i == 10);
|
||||
|
@ -15,10 +15,13 @@ fn test00() {
|
||||
let number_of_tasks: int = 8;
|
||||
|
||||
let i: int = 0;
|
||||
let tasks: [task] = ~[];
|
||||
while i < number_of_tasks { i = i + 1; tasks += ~[spawn start(i)]; }
|
||||
let tasks = [];
|
||||
while i < number_of_tasks {
|
||||
i = i + 1;
|
||||
tasks += [task::_spawn(bind start(i))];
|
||||
}
|
||||
|
||||
for t: task in tasks { task::join(t); }
|
||||
for t: task::task_id in tasks { task::join_id(t); }
|
||||
|
||||
log "Joined all task.";
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ fn test00() {
|
||||
let r: int = 0;
|
||||
let sum: int = 0;
|
||||
let p = comm::mk_port();
|
||||
let c = p.mk_chan2();
|
||||
let c = p.mk_chan();
|
||||
send(c, 1);
|
||||
send(c, 2);
|
||||
send(c, 3);
|
||||
|
@ -10,7 +10,7 @@ fn test00() {
|
||||
let c = p.mk_chan();
|
||||
let number_of_messages: int = 1000;
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { c.send(i); i += 1; }
|
||||
while i < number_of_messages { comm::send(c, i+0); i += 1; }
|
||||
i = 0;
|
||||
while i < number_of_messages { r = p.recv(); sum += r; i += 1; }
|
||||
assert (sum == number_of_messages * (number_of_messages - 1) / 2);
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std;
|
||||
import std::comm;
|
||||
import std::comm::send;
|
||||
|
||||
fn main() { test00(); }
|
||||
|
||||
@ -14,10 +15,10 @@ fn test00() {
|
||||
let number_of_messages: int = 1000;
|
||||
let i: int = 0;
|
||||
while i < number_of_messages {
|
||||
c0.send(i);
|
||||
c1.send(i);
|
||||
c2.send(i);
|
||||
c3.send(i);
|
||||
send(c0, i+0);
|
||||
send(c1, i+0);
|
||||
send(c2, i+0);
|
||||
send(c3, i+0);
|
||||
i += 1;
|
||||
}
|
||||
i = 0;
|
||||
|
@ -4,10 +4,9 @@ import std::comm;
|
||||
|
||||
fn main() { test00(); }
|
||||
|
||||
fn test00_start(pc: *u8, start: int, number_of_messages: int) {
|
||||
let c = comm::chan_from_unsafe_ptr(pc);
|
||||
fn test00_start(c: comm::_chan[int], start: int, number_of_messages: int) {
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { c.send(start + i); i += 1; }
|
||||
while i < number_of_messages { comm::send(c, start + i); i += 1; }
|
||||
}
|
||||
|
||||
fn test00() {
|
||||
@ -16,18 +15,18 @@ fn test00() {
|
||||
let p = comm::mk_port();
|
||||
let number_of_messages: int = 10;
|
||||
|
||||
let t0: task =
|
||||
spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 0,
|
||||
number_of_messages);
|
||||
let t1: task =
|
||||
spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 1,
|
||||
number_of_messages);
|
||||
let t2: task =
|
||||
spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 2,
|
||||
number_of_messages);
|
||||
let t3: task =
|
||||
spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 3,
|
||||
number_of_messages);
|
||||
let t0 =
|
||||
task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 0,
|
||||
number_of_messages));
|
||||
let t1 =
|
||||
task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 1,
|
||||
number_of_messages));
|
||||
let t2 =
|
||||
task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 2,
|
||||
number_of_messages));
|
||||
let t3 =
|
||||
task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 3,
|
||||
number_of_messages));
|
||||
|
||||
let i: int = 0;
|
||||
while i < number_of_messages {
|
||||
@ -42,10 +41,10 @@ fn test00() {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
task::join(t0);
|
||||
task::join(t1);
|
||||
task::join(t2);
|
||||
task::join(t3);
|
||||
task::join_id(t0);
|
||||
task::join_id(t1);
|
||||
task::join_id(t2);
|
||||
task::join_id(t3);
|
||||
|
||||
assert (sum == number_of_messages * 4 * (number_of_messages * 4 - 1) / 2);
|
||||
}
|
@ -4,10 +4,9 @@ import std::comm;
|
||||
|
||||
fn main() { test00(); }
|
||||
|
||||
fn test00_start(pc: *u8, start: int, number_of_messages: int) {
|
||||
let c = comm::chan_from_unsafe_ptr(pc);
|
||||
fn test00_start(c : comm::_chan[int], start: int, number_of_messages: int) {
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { c.send(start + i); i += 1; }
|
||||
while i < number_of_messages { comm::send(c, start + i); i += 1; }
|
||||
}
|
||||
|
||||
fn test00() {
|
||||
@ -16,18 +15,18 @@ fn test00() {
|
||||
let p = comm::mk_port();
|
||||
let number_of_messages: int = 10;
|
||||
|
||||
let t0: task =
|
||||
spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 0,
|
||||
number_of_messages);
|
||||
let t1: task =
|
||||
spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 1,
|
||||
number_of_messages);
|
||||
let t2: task =
|
||||
spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 2,
|
||||
number_of_messages);
|
||||
let t3: task =
|
||||
spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 3,
|
||||
number_of_messages);
|
||||
let t0 =
|
||||
task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 0,
|
||||
number_of_messages));
|
||||
let t1 =
|
||||
task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 1,
|
||||
number_of_messages));
|
||||
let t2 =
|
||||
task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 2,
|
||||
number_of_messages));
|
||||
let t3 =
|
||||
task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 3,
|
||||
number_of_messages));
|
||||
|
||||
let i: int = 0;
|
||||
while i < number_of_messages {
|
||||
@ -42,10 +41,10 @@ fn test00() {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
task::join(t0);
|
||||
task::join(t1);
|
||||
task::join(t2);
|
||||
task::join(t3);
|
||||
task::join_id(t0);
|
||||
task::join_id(t1);
|
||||
task::join_id(t2);
|
||||
task::join_id(t3);
|
||||
|
||||
assert (sum == number_of_messages * 4 * (number_of_messages * 4 - 1) / 2);
|
||||
}
|
@ -4,10 +4,9 @@ import std::comm;
|
||||
|
||||
fn main() { test00(); }
|
||||
|
||||
fn test00_start(pc: *u8, number_of_messages: int) {
|
||||
let c = comm::chan_from_unsafe_ptr(pc);
|
||||
fn test00_start(c: comm::_chan[int], number_of_messages: int) {
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { c.send(i); i += 1; }
|
||||
while i < number_of_messages { comm::send(c, i+0); i += 1; }
|
||||
}
|
||||
|
||||
fn test00() {
|
||||
@ -16,13 +15,13 @@ fn test00() {
|
||||
let p = comm::mk_port();
|
||||
let number_of_messages: int = 10;
|
||||
|
||||
let t0: task = spawn test00_start(p.mk_chan().unsafe_ptr(),
|
||||
number_of_messages);
|
||||
let t0 = task::_spawn(bind test00_start(p.mk_chan(),
|
||||
number_of_messages));
|
||||
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { r = p.recv(); sum += r; log r; i += 1; }
|
||||
|
||||
task::join(t0);
|
||||
task::join_id(t0);
|
||||
|
||||
assert (sum == number_of_messages * (number_of_messages - 1) / 2);
|
||||
}
|
||||
}
|
||||
|
@ -9,19 +9,8 @@ fn create_port_and_chan() {
|
||||
|
||||
#[test]
|
||||
fn send_recv() {
|
||||
let p = comm::mk_port();
|
||||
let c = p.mk_chan();
|
||||
|
||||
c.send(42);
|
||||
let v = p.recv();
|
||||
log_err v;
|
||||
assert(42 == v);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_recv2() {
|
||||
let p = comm::mk_port[int]();
|
||||
let c = p.mk_chan2();
|
||||
let c = p.mk_chan();
|
||||
|
||||
comm::send(c, 42);
|
||||
let v = p.recv();
|
||||
|
Loading…
Reference in New Issue
Block a user