Skip to content

Commit cc353aa

Browse files
author
Eric Holk
committed
Removed old object-based chans.
1 parent 7ad1339 commit cc353aa

15 files changed

+89
-126
lines changed

src/lib/comm.rs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import unsafe;
44
import task;
55
import task::task_id;
66

7-
export chan_t;
87
export _chan;
98
export _port;
109

@@ -36,44 +35,19 @@ native "rust-intrinsic" mod rusti {
3635

3736
type port_id = int;
3837

39-
type chan_t[~T] = {
38+
type _chan[~T] = {
4039
task : task_id,
4140
port : port_id
4241
};
4342

44-
resource chan_ptr(ch: *rustrt::rust_chan) {
45-
rustrt::drop_chan(ch);
46-
}
47-
4843
resource port_ptr(po: *rustrt::rust_port) {
4944
rustrt::drop_port(po);
5045
rustrt::del_port(po);
5146
}
5247

53-
obj _chan[~T](raw_chan : @chan_ptr) {
54-
fn send(v : &T) {
55-
rustrt::chan_send(**raw_chan,
56-
unsafe::reinterpret_cast(ptr::addr_of(v)));
57-
}
58-
59-
// Use this to get something we can send over a channel.
60-
fn unsafe_ptr() -> *u8 {
61-
rustrt::take_chan(**raw_chan);
62-
ret unsafe::reinterpret_cast(**raw_chan);
63-
}
64-
}
65-
66-
fn chan_from_unsafe_ptr[~T](ch : *u8) -> _chan[T] {
67-
_chan(@chan_ptr(unsafe::reinterpret_cast(ch)))
68-
}
69-
7048
obj _port[~T](raw_port : @port_ptr) {
71-
fn mk_chan() -> _chan[T] {
72-
_chan(@chan_ptr(rustrt::new_chan(**raw_port)))
73-
}
74-
7549
// FIXME: rename this to chan once chan is not a keyword.
76-
fn mk_chan2() -> chan_t[T] {
50+
fn mk_chan() -> _chan[T] {
7751
{
7852
task: task::get_task_id(),
7953
port: rustrt::get_port_id(**raw_port)
@@ -89,6 +63,6 @@ fn mk_port[~T]() -> _port[T] {
8963
_port(@port_ptr(rustrt::new_port(sys::size_of[T]())))
9064
}
9165

92-
fn send[~T](ch : chan_t[T], data : -T) {
66+
fn send[~T](ch : _chan[T], data : -T) {
9367
rustrt::chan_id_send(ch.task, ch.port, data);
9468
}

src/test/run-pass/spawn-types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import std::str;
1010
import std::comm;
1111
import std::task;
1212

13-
type ctx = comm::chan_t[int];
13+
type ctx = comm::_chan[int];
1414

1515
fn iotask(cx: ctx, ip: str) { assert (str::eq(ip, "localhost")); }
1616

1717
fn main() {
1818
let p = comm::mk_port[int]();
19-
task::_spawn(bind iotask(p.mk_chan2(), "localhost"));
19+
task::_spawn(bind iotask(p.mk_chan(), "localhost"));
2020
}

src/test/run-pass/task-comm-0.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
use std;
44

55
import std::comm;
6-
import std::comm::chan_t;
6+
import std::comm::_chan;
77
import std::comm::send;
88
import std::task;
99

1010
fn main() { test05(); }
1111

12-
fn test05_start(ch : chan_t[int]) {
12+
fn test05_start(ch : _chan[int]) {
1313
log_err ch;
1414
send(ch, 10);
1515
log_err "sent 10";
@@ -21,7 +21,7 @@ fn test05_start(ch : chan_t[int]) {
2121

2222
fn test05() {
2323
let po = comm::mk_port[int]();
24-
let ch = po.mk_chan2();
24+
let ch = po.mk_chan();
2525
task::_spawn(bind test05_start(ch));
2626
let value = po.recv();
2727
log_err value;

src/test/run-pass/task-comm-1.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std;
22

3-
import std::task::join;
3+
import std::task::_spawn;
4+
import std::task::join_id;
45

56
fn main() { test00(); }
67

78
fn start() { log "Started / Finished task."; }
89

9-
fn test00() { let t: task = spawn start(); join(t); log "Completing."; }
10+
fn test00() { let t = _spawn(bind start()); join_id(t); log "Completing."; }

src/test/run-pass/task-comm-11.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// xfail-stage3
22
use std;
33
import std::comm;
4+
import std::task;
45

5-
fn start(pcc: *u8) {
6-
let c = comm::chan_from_unsafe_ptr(pcc);
6+
fn start(c: comm::_chan[comm::_chan[int]]) {
77
let p : comm::_port[int] = comm::mk_port();
8-
c.send(p.mk_chan().unsafe_ptr());
8+
comm::send(c, p.mk_chan());
99
}
1010

1111
fn main() {
12-
let p = comm::mk_port();
13-
let child = spawn start(p.mk_chan().unsafe_ptr());
14-
let pc = p.recv();
15-
let c : comm::_chan[int] = comm::chan_from_unsafe_ptr(pc);
12+
let p = comm::mk_port[comm::_chan[int]]();
13+
let child = task::_spawn(bind start(p.mk_chan()));
14+
let c = p.recv();
1615
}

src/test/run-pass/task-comm-13.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use std;
22
import std::task;
33
import std::comm;
4+
import std::comm::send;
45

5-
fn start(pc: *u8, start: int, number_of_messages: int) {
6-
let c = comm::chan_from_unsafe_ptr(pc);
6+
fn start(c: comm::_chan[int], start: int, number_of_messages: int) {
77
let i: int = 0;
8-
while i < number_of_messages { c.send(start + i); i += 1; }
8+
while i < number_of_messages { send(c, start + i); i += 1; }
99
}
1010

1111
fn main() {
1212
log "Check that we don't deadlock.";
1313
let p : comm::_port[int] = comm::mk_port();
14-
let a: task = spawn start(p.mk_chan().unsafe_ptr(), 0, 10);
15-
task::join(a);
14+
let a = task::_spawn(bind start(p.mk_chan(), 0, 10));
15+
task::join_id(a);
1616
log "Joined task";
17-
}
17+
}

src/test/run-pass/task-comm-16.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use std;
44
import std::comm;
5+
import std::comm::send;
56
import std::comm::mk_port;
67

78
// Tests of ports and channels on various types
@@ -11,7 +12,7 @@ fn test_rec() {
1112
let po = comm::mk_port();
1213
let ch = po.mk_chan();
1314
let r0: r = {val0: 0, val1: 1u8, val2: '2'};
14-
ch.send(r0);
15+
send(ch, r0);
1516
let r1: r;
1617
r1 = po.recv();
1718
assert (r1.val0 == 0);
@@ -23,7 +24,7 @@ fn test_vec() {
2324
let po = comm::mk_port();
2425
let ch = po.mk_chan();
2526
let v0: [int] = ~[0, 1, 2];
26-
ch.send(v0);
27+
send(ch, v0);
2728
let v1: [int];
2829
v1 = po.recv();
2930
assert (v1.(0) == 0);
@@ -37,7 +38,7 @@ fn test_str() {
3738
let po = comm::mk_port();
3839
let ch = po.mk_chan();
3940
let s0: str = "test";
40-
ch.send(s0);
41+
send(ch, s0);
4142
let s1: str;
4243
s1 = po.recv();
4344
assert (s1.(0) as u8 == 't' as u8);
@@ -51,9 +52,9 @@ fn test_tag() {
5152
tag t { tag1; tag2(int); tag3(int, u8, char); }
5253
let po = comm::mk_port();
5354
let ch = po.mk_chan();
54-
ch.send(tag1);
55-
ch.send(tag2(10));
56-
ch.send(tag3(10, 11u8, 'A'));
55+
send(ch, tag1);
56+
send(ch, tag2(10));
57+
send(ch, tag3(10, 11u8, 'A'));
5758
// FIXME: Do port semantics really guarantee these happen in order?
5859
let t1: t;
5960
t1 = po.recv();
@@ -69,13 +70,11 @@ fn test_chan() {
6970
let ch = po.mk_chan();
7071
let po0 = comm::mk_port();
7172
let ch0 = po0.mk_chan();
72-
ch.send(ch0.unsafe_ptr());
73-
let pch1;
74-
pch1 = po.recv();
75-
let ch1 = comm::chan_from_unsafe_ptr(pch1);
73+
send(ch, ch0);
74+
let ch1 = po.recv();
7675
// Does the transmitted channel still work?
7776

78-
ch1.send(10);
77+
send(ch1, 10);
7978
let i: int;
8079
i = po0.recv();
8180
assert (i == 10);

src/test/run-pass/task-comm-2.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ fn test00() {
1515
let number_of_tasks: int = 8;
1616

1717
let i: int = 0;
18-
let tasks: [task] = ~[];
19-
while i < number_of_tasks { i = i + 1; tasks += ~[spawn start(i)]; }
18+
let tasks = [];
19+
while i < number_of_tasks {
20+
i = i + 1;
21+
tasks += [task::_spawn(bind start(i))];
22+
}
2023

21-
for t: task in tasks { task::join(t); }
24+
for t: task::task_id in tasks { task::join_id(t); }
2225

2326
log "Joined all task.";
2427
}

src/test/run-pass/task-comm-4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn test00() {
88
let r: int = 0;
99
let sum: int = 0;
1010
let p = comm::mk_port();
11-
let c = p.mk_chan2();
11+
let c = p.mk_chan();
1212
send(c, 1);
1313
send(c, 2);
1414
send(c, 3);

src/test/run-pass/task-comm-5.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn test00() {
1010
let c = p.mk_chan();
1111
let number_of_messages: int = 1000;
1212
let i: int = 0;
13-
while i < number_of_messages { c.send(i); i += 1; }
13+
while i < number_of_messages { comm::send(c, i+0); i += 1; }
1414
i = 0;
1515
while i < number_of_messages { r = p.recv(); sum += r; i += 1; }
1616
assert (sum == number_of_messages * (number_of_messages - 1) / 2);

src/test/run-pass/task-comm-6.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std;
22
import std::comm;
3+
import std::comm::send;
34

45
fn main() { test00(); }
56

@@ -14,10 +15,10 @@ fn test00() {
1415
let number_of_messages: int = 1000;
1516
let i: int = 0;
1617
while i < number_of_messages {
17-
c0.send(i);
18-
c1.send(i);
19-
c2.send(i);
20-
c3.send(i);
18+
send(c0, i+0);
19+
send(c1, i+0);
20+
send(c2, i+0);
21+
send(c3, i+0);
2122
i += 1;
2223
}
2324
i = 0;

src/test/run-pass/task-comm-7.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import std::comm;
44

55
fn main() { test00(); }
66

7-
fn test00_start(pc: *u8, start: int, number_of_messages: int) {
8-
let c = comm::chan_from_unsafe_ptr(pc);
7+
fn test00_start(c: comm::_chan[int], start: int, number_of_messages: int) {
98
let i: int = 0;
10-
while i < number_of_messages { c.send(start + i); i += 1; }
9+
while i < number_of_messages { comm::send(c, start + i); i += 1; }
1110
}
1211

1312
fn test00() {
@@ -16,18 +15,18 @@ fn test00() {
1615
let p = comm::mk_port();
1716
let number_of_messages: int = 10;
1817

19-
let t0: task =
20-
spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 0,
21-
number_of_messages);
22-
let t1: task =
23-
spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 1,
24-
number_of_messages);
25-
let t2: task =
26-
spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 2,
27-
number_of_messages);
28-
let t3: task =
29-
spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 3,
30-
number_of_messages);
18+
let t0 =
19+
task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 0,
20+
number_of_messages));
21+
let t1 =
22+
task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 1,
23+
number_of_messages));
24+
let t2 =
25+
task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 2,
26+
number_of_messages));
27+
let t3 =
28+
task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 3,
29+
number_of_messages));
3130

3231
let i: int = 0;
3332
while i < number_of_messages {
@@ -42,10 +41,10 @@ fn test00() {
4241
i += 1;
4342
}
4443

45-
task::join(t0);
46-
task::join(t1);
47-
task::join(t2);
48-
task::join(t3);
44+
task::join_id(t0);
45+
task::join_id(t1);
46+
task::join_id(t2);
47+
task::join_id(t3);
4948

5049
assert (sum == number_of_messages * 4 * (number_of_messages * 4 - 1) / 2);
5150
}

0 commit comments

Comments
 (0)