Skip to content

Commit decd390

Browse files
committed
core::comm: Modernize constructors to use new
1 parent bc60d84 commit decd390

32 files changed

+79
-67
lines changed

doc/tutorial-tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ Instead we can use a `SharedChan`, a type that allows a single
236236
use core::comm::{stream, SharedChan};
237237
238238
let (port, chan) = stream();
239-
let chan = SharedChan(chan);
239+
let chan = SharedChan::new(chan);
240240
241241
for uint::range(0, 3) |init_val| {
242242
// Create a new channel handle to distribute to the child task

src/compiletest/procsrv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn run(lib_path: ~str,
7373
7474
7575
writeclose(pipe_in.out, input);
76-
let p = comm::PortSet();
76+
let p = comm::PortSet::new();
7777
let ch = p.chan();
7878
do task::spawn_sched(task::SingleThreaded) || {
7979
let errput = readclose(pipe_err.in);

src/libcore/comm.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use option::{Option, Some, None};
1919
use uint;
2020
use unstable;
2121
use vec;
22+
use unstable::Exclusive;
2223

2324
use pipes::{recv, try_recv, wait_many, peek, PacketHeader};
2425

@@ -218,13 +219,14 @@ pub struct PortSet<T> {
218219
mut ports: ~[Port<T>],
219220
}
220221
221-
pub fn PortSet<T: Owned>() -> PortSet<T>{
222-
PortSet {
223-
ports: ~[]
222+
pub impl<T: Owned> PortSet<T> {
223+
224+
fn new() -> PortSet<T> {
225+
PortSet {
226+
ports: ~[]
227+
}
224228
}
225-
}
226229
227-
pub impl<T: Owned> PortSet<T> {
228230
fn add(&self, port: Port<T>) {
229231
self.ports.push(port)
230232
}
@@ -279,12 +281,21 @@ impl<T: Owned> Peekable<T> for PortSet<T> {
279281
}
280282
281283
/// A channel that can be shared between many senders.
282-
pub type SharedChan<T> = unstable::Exclusive<Chan<T>>;
284+
pub struct SharedChan<T> {
285+
ch: Exclusive<Chan<T>>
286+
}
287+
288+
impl<T: Owned> SharedChan<T> {
289+
/// Converts a `chan` into a `shared_chan`.
290+
pub fn new(c: Chan<T>) -> SharedChan<T> {
291+
SharedChan { ch: unstable::exclusive(c) }
292+
}
293+
}
283294
284295
impl<T: Owned> GenericChan<T> for SharedChan<T> {
285296
fn send(&self, x: T) {
286297
let mut xx = Some(x);
287-
do self.with_imm |chan| {
298+
do self.ch.with_imm |chan| {
288299
let mut x = None;
289300
x <-> xx;
290301
chan.send(x.unwrap())
@@ -295,17 +306,18 @@ impl<T: Owned> GenericChan<T> for SharedChan<T> {
295306
impl<T: Owned> GenericSmartChan<T> for SharedChan<T> {
296307
fn try_send(&self, x: T) -> bool {
297308
let mut xx = Some(x);
298-
do self.with_imm |chan| {
309+
do self.ch.with_imm |chan| {
299310
let mut x = None;
300311
x <-> xx;
301312
chan.try_send(x.unwrap())
302313
}
303314
}
304315
}
305316
306-
/// Converts a `chan` into a `shared_chan`.
307-
pub fn SharedChan<T:Owned>(c: Chan<T>) -> SharedChan<T> {
308-
unstable::exclusive(c)
317+
impl<T: Owned> ::clone::Clone for SharedChan<T> {
318+
fn clone(&self) -> SharedChan<T> {
319+
SharedChan { ch: self.ch.clone() }
320+
}
309321
}
310322
311323
/*proto! oneshot (

src/libcore/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ pub fn program_output(prog: &str, args: &[~str]) -> ProgramOutput {
405405
// or the other. FIXME (#2625): Surely there's a much more
406406
// clever way to do this.
407407
let (p, ch) = stream();
408-
let ch = SharedChan(ch);
408+
let ch = SharedChan::new(ch);
409409
let ch_clone = ch.clone();
410410
do task::spawn_sched(task::SingleThreaded) {
411411
let errput = readclose(pipe_err.in);

src/libcore/task/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ fn test_cant_dup_task_builder() {
657657
#[test] #[ignore(cfg(windows))]
658658
fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port
659659
let (po, ch) = stream();
660-
let ch = SharedChan(ch);
660+
let ch = SharedChan::new(ch);
661661
do spawn_unlinked {
662662
let ch = ch.clone();
663663
do spawn_unlinked {
@@ -881,7 +881,7 @@ fn test_spawn_sched_no_threads() {
881881
#[test]
882882
fn test_spawn_sched() {
883883
let (po, ch) = stream::<()>();
884-
let ch = SharedChan(ch);
884+
let ch = SharedChan::new(ch);
885885

886886
fn f(i: int, ch: SharedChan<()>) {
887887
let parent_sched_id = unsafe { rt::rust_get_sched_id() };

src/libcore/unstable/weak_task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn create_global_service() -> ~WeakTaskService {
6969
debug!("creating global weak task service");
7070
let (port, chan) = stream::<ServiceMsg>();
7171
let port = Cell(port);
72-
let chan = SharedChan(chan);
72+
let chan = SharedChan::new(chan);
7373
let chan_clone = chan.clone();
7474

7575
do task().unlinked().spawn {

src/librustc/rustc.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ bug and need to present an error.
307307
pub fn monitor(+f: ~fn(diagnostic::Emitter)) {
308308
use core::comm::*;
309309
let (p, ch) = stream();
310-
let ch = SharedChan(ch);
310+
let ch = SharedChan::new(ch);
311311
let ch_capture = ch.clone();
312312
match do task::try || {
313313
let ch = ch_capture.clone();

src/librustdoc/astsrv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn run<T>(owner: SrvOwner<T>, source: ~str, parse: Parser) -> T {
6969
}
7070

7171
let srv_ = Srv {
72-
ch: SharedChan(ch)
72+
ch: SharedChan::new(ch)
7373
};
7474

7575
let res = owner(srv_.clone());

src/librustdoc/markdown_writer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ fn write_file(path: &Path, s: ~str) {
232232
pub fn future_writer_factory(
233233
) -> (WriterFactory, Port<(doc::Page, ~str)>) {
234234
let (markdown_po, markdown_ch) = stream();
235-
let markdown_ch = SharedChan(markdown_ch);
235+
let markdown_ch = SharedChan::new(markdown_ch);
236236
let writer_factory: WriterFactory = |page| {
237237
let (writer_po, writer_ch) = comm::stream();
238238
let markdown_ch = markdown_ch.clone();

src/librustdoc/page_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn run(
5050

5151
let (result_port, result_chan) = stream();
5252
let (page_port, page_chan) = stream();
53-
let page_chan = SharedChan(page_chan);
53+
let page_chan = SharedChan::new(page_chan);
5454
do task::spawn {
5555
result_chan.send(make_doc_from_pages(&page_port));
5656
};

0 commit comments

Comments
 (0)