about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-04-16 23:45:29 -0700
committerBrian Anderson <banderson@mozilla.com>2013-04-18 14:07:35 -0700
commitdecd3901d5d63013a98ecc481c441f3f793b5207 (patch)
tree37327a47db463003bcb8c5342fcecb04d56d1c64 /src/libcore
parentbc60d84507ba4d492889c9b702318346b5784e5c (diff)
downloadrust-decd3901d5d63013a98ecc481c441f3f793b5207.tar.gz
rust-decd3901d5d63013a98ecc481c441f3f793b5207.zip
core::comm: Modernize constructors to use `new`
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/comm.rs34
-rw-r--r--src/libcore/run.rs2
-rw-r--r--src/libcore/task/mod.rs4
-rw-r--r--src/libcore/unstable/weak_task.rs2
4 files changed, 27 insertions, 15 deletions
diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs
index 60ec4fbfddb..fc13463bd1c 100644
--- a/src/libcore/comm.rs
+++ b/src/libcore/comm.rs
@@ -19,6 +19,7 @@ use option::{Option, Some, None};
 use uint;
 use unstable;
 use vec;
+use unstable::Exclusive;
 
 use pipes::{recv, try_recv, wait_many, peek, PacketHeader};
 
@@ -218,13 +219,14 @@ pub struct PortSet<T> {
     mut ports: ~[Port<T>],
 }
 
-pub fn PortSet<T: Owned>() -> PortSet<T>{
-    PortSet {
-        ports: ~[]
+pub impl<T: Owned> PortSet<T> {
+
+    fn new() -> PortSet<T> {
+        PortSet {
+            ports: ~[]
+        }
     }
-}
 
-pub impl<T: Owned> PortSet<T> {
     fn add(&self, port: Port<T>) {
         self.ports.push(port)
     }
@@ -279,12 +281,21 @@ impl<T: Owned> Peekable<T> for PortSet<T> {
 }
 
 /// A channel that can be shared between many senders.
-pub type SharedChan<T> = unstable::Exclusive<Chan<T>>;
+pub struct SharedChan<T> {
+    ch: Exclusive<Chan<T>>
+}
+
+impl<T: Owned> SharedChan<T> {
+    /// Converts a `chan` into a `shared_chan`.
+    pub fn new(c: Chan<T>) -> SharedChan<T> {
+        SharedChan { ch: unstable::exclusive(c) }
+    }
+}
 
 impl<T: Owned> GenericChan<T> for SharedChan<T> {
     fn send(&self, x: T) {
         let mut xx = Some(x);
-        do self.with_imm |chan| {
+        do self.ch.with_imm |chan| {
             let mut x = None;
             x <-> xx;
             chan.send(x.unwrap())
@@ -295,7 +306,7 @@ impl<T: Owned> GenericChan<T> for SharedChan<T> {
 impl<T: Owned> GenericSmartChan<T> for SharedChan<T> {
     fn try_send(&self, x: T) -> bool {
         let mut xx = Some(x);
-        do self.with_imm |chan| {
+        do self.ch.with_imm |chan| {
             let mut x = None;
             x <-> xx;
             chan.try_send(x.unwrap())
@@ -303,9 +314,10 @@ impl<T: Owned> GenericSmartChan<T> for SharedChan<T> {
     }
 }
 
-/// Converts a `chan` into a `shared_chan`.
-pub fn SharedChan<T:Owned>(c: Chan<T>) -> SharedChan<T> {
-    unstable::exclusive(c)
+impl<T: Owned> ::clone::Clone for SharedChan<T> {
+    fn clone(&self) -> SharedChan<T> {
+        SharedChan { ch: self.ch.clone() }
+    }
 }
 
 /*proto! oneshot (
diff --git a/src/libcore/run.rs b/src/libcore/run.rs
index 9e6524c25cb..8b18cc3c696 100644
--- a/src/libcore/run.rs
+++ b/src/libcore/run.rs
@@ -405,7 +405,7 @@ pub fn program_output(prog: &str, args: &[~str]) -> ProgramOutput {
     // or the other. FIXME (#2625): Surely there's a much more
     // clever way to do this.
     let (p, ch) = stream();
-    let ch = SharedChan(ch);
+    let ch = SharedChan::new(ch);
     let ch_clone = ch.clone();
     do task::spawn_sched(task::SingleThreaded) {
         let errput = readclose(pipe_err.in);
diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs
index 2975f3d5e46..55546514e4f 100644
--- a/src/libcore/task/mod.rs
+++ b/src/libcore/task/mod.rs
@@ -657,7 +657,7 @@ 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, ch) = stream();
-    let ch = SharedChan(ch);
+    let ch = SharedChan::new(ch);
     do spawn_unlinked {
         let ch = ch.clone();
         do spawn_unlinked {
@@ -881,7 +881,7 @@ fn test_spawn_sched_no_threads() {
 #[test]
 fn test_spawn_sched() {
     let (po, ch) = stream::<()>();
-    let ch = SharedChan(ch);
+    let ch = SharedChan::new(ch);
 
     fn f(i: int, ch: SharedChan<()>) {
         let parent_sched_id = unsafe { rt::rust_get_sched_id() };
diff --git a/src/libcore/unstable/weak_task.rs b/src/libcore/unstable/weak_task.rs
index 6eabb0629d1..4e2174fd5d2 100644
--- a/src/libcore/unstable/weak_task.rs
+++ b/src/libcore/unstable/weak_task.rs
@@ -69,7 +69,7 @@ fn create_global_service() -> ~WeakTaskService {
     debug!("creating global weak task service");
     let (port, chan) = stream::<ServiceMsg>();
     let port = Cell(port);
-    let chan = SharedChan(chan);
+    let chan = SharedChan::new(chan);
     let chan_clone = chan.clone();
 
     do task().unlinked().spawn {