Skip to content

Commit 0470b2a

Browse files
committed
std: Remove PortSet. Not supported by new scheduler. Replace uses with SharedChan.
1 parent 3c1d0f7 commit 0470b2a

File tree

9 files changed

+38
-119
lines changed

9 files changed

+38
-119
lines changed

src/libextra/arc.rs

-4
Original file line numberDiff line numberDiff line change
@@ -576,16 +576,12 @@ mod tests {
576576
let (p, c) = comm::stream();
577577
578578
do task::spawn() || {
579-
let p = comm::PortSet::new();
580-
c.send(p.chan());
581-
582579
let arc_v : Arc<~[int]> = p.recv();
583580
584581
let v = (*arc_v.get()).clone();
585582
assert_eq!(v[3], 4);
586583
};
587584
588-
let c = p.recv();
589585
c.send(arc_v.clone());
590586
591587
assert_eq!(arc_v.get()[2], 3);

src/libstd/comm.rs

+2-81
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,10 @@ Message passing
1414

1515
#[allow(missing_doc)];
1616

17-
use cast::{transmute, transmute_mut};
18-
use container::Container;
17+
use cast::transmute;
1918
use either::{Either, Left, Right};
2019
use kinds::Send;
21-
use option::{Option, Some, None};
22-
use uint;
23-
use vec::OwnedVector;
24-
use util::replace;
20+
use option::{Option, Some};
2521
use unstable::sync::Exclusive;
2622
use rtcomm = rt::comm;
2723
use rt;
@@ -143,81 +139,6 @@ impl<T: Send> Selectable for Port<T> {
143139
}
144140
}
145141

146-
/// Treat many ports as one.
147-
#[unsafe_mut_field(ports)]
148-
pub struct PortSet<T> {
149-
ports: ~[pipesy::Port<T>],
150-
}
151-
152-
impl<T: Send> PortSet<T> {
153-
pub fn new() -> PortSet<T> {
154-
PortSet {
155-
ports: ~[]
156-
}
157-
}
158-
159-
pub fn add(&self, port: Port<T>) {
160-
let Port { inner } = port;
161-
let port = match inner {
162-
Left(p) => p,
163-
Right(_) => fail!("PortSet not implemented")
164-
};
165-
unsafe {
166-
let self_ports = transmute_mut(&self.ports);
167-
self_ports.push(port)
168-
}
169-
}
170-
171-
pub fn chan(&self) -> Chan<T> {
172-
let (po, ch) = stream();
173-
self.add(po);
174-
ch
175-
}
176-
}
177-
178-
impl<T:Send> GenericPort<T> for PortSet<T> {
179-
fn try_recv(&self) -> Option<T> {
180-
unsafe {
181-
let self_ports = transmute_mut(&self.ports);
182-
let mut result = None;
183-
// we have to swap the ports array so we aren't borrowing
184-
// aliasable mutable memory.
185-
let mut ports = replace(self_ports, ~[]);
186-
while result.is_none() && ports.len() > 0 {
187-
let i = wait_many(ports);
188-
match ports[i].try_recv() {
189-
Some(m) => {
190-
result = Some(m);
191-
}
192-
None => {
193-
// Remove this port.
194-
let _ = ports.swap_remove(i);
195-
}
196-
}
197-
}
198-
*self_ports = ports;
199-
result
200-
}
201-
}
202-
fn recv(&self) -> T {
203-
self.try_recv().expect("port_set: endpoints closed")
204-
}
205-
}
206-
207-
impl<T: Send> Peekable<T> for PortSet<T> {
208-
fn peek(&self) -> bool {
209-
// It'd be nice to use self.port.each, but that version isn't
210-
// pure.
211-
for uint::range(0, self.ports.len()) |i| {
212-
let port: &pipesy::Port<T> = &self.ports[i];
213-
if port.peek() {
214-
return true;
215-
}
216-
}
217-
false
218-
}
219-
}
220-
221142
/// A channel that can be shared between many senders.
222143
pub struct SharedChan<T> {
223144
inner: Either<Exclusive<pipesy::Chan<T>>, rtcomm::SharedChan<T>>

src/test/bench/msgsend-pipes.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
extern mod extra;
1818

19-
use std::comm::{PortSet, Chan, stream};
19+
use std::comm::{SharedChan, Chan, stream};
2020
use std::io;
2121
use std::os;
2222
use std::task;
@@ -30,7 +30,7 @@ enum request {
3030
stop
3131
}
3232

33-
fn server(requests: &PortSet<request>, responses: &Chan<uint>) {
33+
fn server(requests: &Port<request>, responses: &Chan<uint>) {
3434
let mut count: uint = 0;
3535
let mut done = false;
3636
while !done {
@@ -50,18 +50,16 @@ fn server(requests: &PortSet<request>, responses: &Chan<uint>) {
5050

5151
fn run(args: &[~str]) {
5252
let (from_child, to_parent) = stream();
53-
let (from_parent_, to_child) = stream();
54-
let from_parent = PortSet::new();
55-
from_parent.add(from_parent_);
53+
let (from_parent, to_child) = stream();
54+
let to_child = SharedChan::new(to_child);
5655

5756
let size = uint::from_str(args[1]).get();
5857
let workers = uint::from_str(args[2]).get();
5958
let num_bytes = 100;
6059
let start = extra::time::precise_time_s();
6160
let mut worker_results = ~[];
6261
for uint::range(0, workers) |_i| {
63-
let (from_parent_, to_child) = stream();
64-
from_parent.add(from_parent_);
62+
let to_child = to_child.clone();
6563
let mut builder = task::task();
6664
builder.future_result(|r| worker_results.push(r));
6765
do builder.spawn {

src/test/bench/shootout-pfib.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,24 @@ use std::u64;
3333
use std::uint;
3434

3535
fn fib(n: int) -> int {
36-
fn pfib(c: &Chan<int>, n: int) {
36+
fn pfib(c: &SharedChan<int>, n: int) {
3737
if n == 0 {
3838
c.send(0);
3939
} else if n <= 2 {
4040
c.send(1);
4141
} else {
42-
let p = PortSet::new();
43-
let ch = p.chan();
42+
let (pp, cc) = stream();
43+
let cc = SharedChan::new(cc);
44+
let ch = cc.clone();
4445
task::spawn(|| pfib(&ch, n - 1) );
45-
let ch = p.chan();
46+
let ch = cc.clone();
4647
task::spawn(|| pfib(&ch, n - 2) );
47-
c.send(p.recv() + p.recv());
48+
c.send(pp.recv() + pp.recv());
4849
}
4950
}
5051

5152
let (p, ch) = stream();
53+
let ch = SharedChan::new(ch);
5254
let _t = task::spawn(|| pfib(&ch, n) );
5355
p.recv()
5456
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ use std::comm;
1414
use std::task;
1515

1616
pub fn main() {
17-
let po = comm::PortSet::new();
17+
let (po, ch) = comm::stream();
18+
let ch = comm::SharedChan::new(ch);
1819

1920
// Spawn 10 tasks each sending us back one int.
2021
let mut i = 10;
2122
while (i > 0) {
2223
info!(i);
23-
let (p, ch) = comm::stream();
24-
po.add(p);
24+
let ch = ch.clone();
2525
task::spawn({let i = i; || child(i, &ch)});
2626
i = i - 1;
2727
}
@@ -39,7 +39,7 @@ pub fn main() {
3939
info!("main thread exiting");
4040
}
4141

42-
fn child(x: int, ch: &comm::Chan<int>) {
42+
fn child(x: int, ch: &comm::SharedChan<int>) {
4343
info!(x);
4444
ch.send(x);
4545
}

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
extern mod extra;
1414

15-
use std::comm::Chan;
15+
use std::comm::SharedChan;
1616
use std::comm;
1717
use std::task;
1818

1919
pub fn main() { info!("===== WITHOUT THREADS ====="); test00(); }
2020

21-
fn test00_start(ch: &Chan<int>, message: int, count: int) {
21+
fn test00_start(ch: &SharedChan<int>, message: int, count: int) {
2222
info!("Starting test00_start");
2323
let mut i: int = 0;
2424
while i < count {
@@ -35,14 +35,15 @@ fn test00() {
3535

3636
info!("Creating tasks");
3737

38-
let po = comm::PortSet::new();
38+
let (po, ch) = comm::stream();
39+
let ch = comm::SharedChan::new(ch);
3940

4041
let mut i: int = 0;
4142

4243
// Create and spawn tasks...
4344
let mut results = ~[];
4445
while i < number_of_tasks {
45-
let ch = po.chan();
46+
let ch = ch.clone();
4647
let mut builder = task::task();
4748
builder.future_result(|r| results.push(r));
4849
builder.spawn({

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::comm::Chan;
11+
use std::comm::SharedChan;
1212
use std::comm;
1313

1414
pub fn main() { test00(); }
1515

1616
fn test00() {
1717
let mut r: int = 0;
1818
let mut sum: int = 0;
19-
let p = comm::PortSet::new();
20-
let c0 = p.chan();
21-
let c1 = p.chan();
22-
let c2 = p.chan();
23-
let c3 = p.chan();
19+
let (p, ch) = comm::stream();
20+
let ch = SharedChan::new(ch);
21+
let c0 = ch.clone();
22+
let c1 = ch.clone();
23+
let c2 = ch.clone();
24+
let c3 = ch.clone();
2425
let number_of_messages: int = 1000;
2526
let mut i: int = 0;
2627
while i < number_of_messages {

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,31 @@ use std::task;
1717

1818
pub fn main() { test00(); }
1919

20-
fn test00_start(c: &comm::Chan<int>, start: int, number_of_messages: int) {
20+
fn test00_start(c: &comm::SharedChan<int>, start: int, number_of_messages: int) {
2121
let mut i: int = 0;
2222
while i < number_of_messages { c.send(start + i); i += 1; }
2323
}
2424

2525
fn test00() {
2626
let mut r: int = 0;
2727
let mut sum: int = 0;
28-
let p = comm::PortSet::new();
28+
let (p, ch) = comm::stream();
29+
let ch = comm::SharedChan::new(ch);
2930
let number_of_messages: int = 10;
3031

31-
let c = p.chan();
32+
let c = ch.clone();
3233
do task::spawn || {
3334
test00_start(&c, number_of_messages * 0, number_of_messages);
3435
}
35-
let c = p.chan();
36+
let c = ch.clone();
3637
do task::spawn || {
3738
test00_start(&c, number_of_messages * 1, number_of_messages);
3839
}
39-
let c = p.chan();
40+
let c = ch.clone();
4041
do task::spawn || {
4142
test00_start(&c, number_of_messages * 2, number_of_messages);
4243
}
43-
let c = p.chan();
44+
let c = ch.clone();
4445
do task::spawn || {
4546
test00_start(&c, number_of_messages * 3, number_of_messages);
4647
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ fn test00_start(c: &comm::Chan<int>, number_of_messages: int) {
2525
fn test00() {
2626
let r: int = 0;
2727
let mut sum: int = 0;
28-
let p = comm::PortSet::new();
28+
let (p, ch) = comm::stream();
2929
let number_of_messages: int = 10;
30-
let ch = p.chan();
3130

3231
let mut result = None;
3332
let mut builder = task::task();

0 commit comments

Comments
 (0)