about summary refs log tree commit diff
path: root/src/libnative
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-13 14:06:37 -0700
committerbors <bors@rust-lang.org>2014-03-13 14:06:37 -0700
commitb4d324334cb48198c27d782002d75eba14a6abde (patch)
tree950d8daa5e6305090bdd69625bb18ead48471865 /src/libnative
parent6ff3c9995e63b63c16d13739a0fc2d321f95410e (diff)
parent78580651131c9daacd7e5e4669af819cdd719f09 (diff)
downloadrust-b4d324334cb48198c27d782002d75eba14a6abde.tar.gz
rust-b4d324334cb48198c27d782002d75eba14a6abde.zip
auto merge of #12815 : alexcrichton/rust/chan-rename, r=brson
* Chan<T> => Sender<T>
* Port<T> => Receiver<T>
* Chan::new() => channel()
* constructor returns (Sender, Receiver) instead of (Receiver, Sender)
* local variables named `port` renamed to `rx`
* local variables named `chan` renamed to `tx`

Closes #11765
Diffstat (limited to 'src/libnative')
-rw-r--r--src/libnative/io/file_unix.rs34
-rw-r--r--src/libnative/io/mod.rs2
-rw-r--r--src/libnative/io/timer_helper.rs16
-rw-r--r--src/libnative/io/timer_other.rs40
-rw-r--r--src/libnative/io/timer_timerfd.rs34
-rw-r--r--src/libnative/io/timer_win32.rs28
-rw-r--r--src/libnative/task.rs55
7 files changed, 103 insertions, 106 deletions
diff --git a/src/libnative/io/file_unix.rs b/src/libnative/io/file_unix.rs
index cf9ada97a32..ff1ff9a569d 100644
--- a/src/libnative/io/file_unix.rs
+++ b/src/libnative/io/file_unix.rs
@@ -532,26 +532,24 @@ mod tests {
     fn test_file_desc() {
         // Run this test with some pipes so we don't have to mess around with
         // opening or closing files.
-        unsafe {
-            let os::Pipe { input, out } = os::pipe();
-            let mut reader = FileDesc::new(input, true);
-            let mut writer = FileDesc::new(out, true);
-
-            writer.inner_write(bytes!("test")).unwrap();
-            let mut buf = [0u8, ..4];
-            match reader.inner_read(buf) {
-                Ok(4) => {
-                    assert_eq!(buf[0], 't' as u8);
-                    assert_eq!(buf[1], 'e' as u8);
-                    assert_eq!(buf[2], 's' as u8);
-                    assert_eq!(buf[3], 't' as u8);
-                }
-                r => fail!("invalid read: {:?}", r)
+        let os::Pipe { input, out } = os::pipe();
+        let mut reader = FileDesc::new(input, true);
+        let mut writer = FileDesc::new(out, true);
+
+        writer.inner_write(bytes!("test")).unwrap();
+        let mut buf = [0u8, ..4];
+        match reader.inner_read(buf) {
+            Ok(4) => {
+                assert_eq!(buf[0], 't' as u8);
+                assert_eq!(buf[1], 'e' as u8);
+                assert_eq!(buf[2], 's' as u8);
+                assert_eq!(buf[3], 't' as u8);
             }
-
-            assert!(writer.inner_read(buf).is_err());
-            assert!(reader.inner_write(buf).is_err());
+            r => fail!("invalid read: {:?}", r)
         }
+
+        assert!(writer.inner_read(buf).is_err());
+        assert!(reader.inner_write(buf).is_err());
     }
 
     #[test]
diff --git a/src/libnative/io/mod.rs b/src/libnative/io/mod.rs
index 2e3e9b3b506..a054ee66391 100644
--- a/src/libnative/io/mod.rs
+++ b/src/libnative/io/mod.rs
@@ -336,7 +336,7 @@ impl rtio::IoFactory for IoFactory {
             })
         }
     }
-    fn signal(&mut self, _signal: Signum, _channel: Chan<Signum>)
+    fn signal(&mut self, _signal: Signum, _channel: Sender<Signum>)
         -> IoResult<~RtioSignal> {
         Err(unimpl())
     }
diff --git a/src/libnative/io/timer_helper.rs b/src/libnative/io/timer_helper.rs
index 62e41771423..c5b6705ceaa 100644
--- a/src/libnative/io/timer_helper.rs
+++ b/src/libnative/io/timer_helper.rs
@@ -33,28 +33,28 @@ use task;
 // only torn down after everything else has exited. This means that these
 // variables are read-only during use (after initialization) and both of which
 // are safe to use concurrently.
-static mut HELPER_CHAN: *mut Chan<Req> = 0 as *mut Chan<Req>;
+static mut HELPER_CHAN: *mut Sender<Req> = 0 as *mut Sender<Req>;
 static mut HELPER_SIGNAL: imp::signal = 0 as imp::signal;
 
 static mut TIMER_HELPER_EXIT: StaticNativeMutex = NATIVE_MUTEX_INIT;
 
-pub fn boot(helper: fn(imp::signal, Port<Req>)) {
+pub fn boot(helper: fn(imp::signal, Receiver<Req>)) {
     static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
     static mut INITIALIZED: bool = false;
 
     unsafe {
         let mut _guard = LOCK.lock();
         if !INITIALIZED {
-            let (msgp, msgc) = Chan::new();
+            let (tx, rx) = channel();
             // promote this to a shared channel
-            drop(msgc.clone());
-            HELPER_CHAN = cast::transmute(~msgc);
+            drop(tx.clone());
+            HELPER_CHAN = cast::transmute(~tx);
             let (receive, send) = imp::new();
             HELPER_SIGNAL = send;
 
             task::spawn(proc() {
                 bookkeeping::decrement();
-                helper(receive, msgp);
+                helper(receive, rx);
                 TIMER_HELPER_EXIT.lock().signal()
             });
 
@@ -86,8 +86,8 @@ fn shutdown() {
     // Clean up after ther helper thread
     unsafe {
         imp::close(HELPER_SIGNAL);
-        let _chan: ~Chan<Req> = cast::transmute(HELPER_CHAN);
-        HELPER_CHAN = 0 as *mut Chan<Req>;
+        let _chan: ~Sender<Req> = cast::transmute(HELPER_CHAN);
+        HELPER_CHAN = 0 as *mut Sender<Req>;
         HELPER_SIGNAL = 0 as imp::signal;
     }
 }
diff --git a/src/libnative/io/timer_other.rs b/src/libnative/io/timer_other.rs
index d7323ddf499..edd7af312c8 100644
--- a/src/libnative/io/timer_other.rs
+++ b/src/libnative/io/timer_other.rs
@@ -64,7 +64,7 @@ pub struct Timer {
 }
 
 struct Inner {
-    chan: Option<Chan<()>>,
+    tx: Option<Sender<()>>,
     interval: u64,
     repeat: bool,
     target: u64,
@@ -78,7 +78,7 @@ pub enum Req {
 
     // Remove a timer based on its id and then send it back on the channel
     // provided
-    RemoveTimer(uint, Chan<~Inner>),
+    RemoveTimer(uint, Sender<~Inner>),
 
     // Shut down the loop and then ACK this channel once it's shut down
     Shutdown,
@@ -93,7 +93,7 @@ fn now() -> u64 {
     }
 }
 
-fn helper(input: libc::c_int, messages: Port<Req>) {
+fn helper(input: libc::c_int, messages: Receiver<Req>) {
     let mut set: imp::fd_set = unsafe { mem::init() };
 
     let mut fd = FileDesc::new(input, true);
@@ -118,13 +118,13 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
         let mut timer = match active.shift() {
             Some(timer) => timer, None => return
         };
-        let chan = timer.chan.take_unwrap();
-        if chan.try_send(()) && timer.repeat {
-            timer.chan = Some(chan);
+        let tx = timer.tx.take_unwrap();
+        if tx.try_send(()) && timer.repeat {
+            timer.tx = Some(tx);
             timer.target += timer.interval;
             insert(timer, active);
         } else {
-            drop(chan);
+            drop(tx);
             dead.push((timer.id, timer));
         }
     }
@@ -208,7 +208,7 @@ impl Timer {
         Ok(Timer {
             id: id,
             inner: Some(~Inner {
-                chan: None,
+                tx: None,
                 interval: 0,
                 target: 0,
                 repeat: false,
@@ -233,9 +233,9 @@ impl Timer {
         match self.inner.take() {
             Some(i) => i,
             None => {
-                let (p, c) = Chan::new();
-                timer_helper::send(RemoveTimer(self.id, c));
-                p.recv()
+                let (tx, rx) = channel();
+                timer_helper::send(RemoveTimer(self.id, tx));
+                rx.recv()
             }
         }
     }
@@ -244,38 +244,38 @@ impl Timer {
 impl rtio::RtioTimer for Timer {
     fn sleep(&mut self, msecs: u64) {
         let mut inner = self.inner();
-        inner.chan = None; // cancel any previous request
+        inner.tx = None; // cancel any previous request
         self.inner = Some(inner);
 
         Timer::sleep(msecs);
     }
 
-    fn oneshot(&mut self, msecs: u64) -> Port<()> {
+    fn oneshot(&mut self, msecs: u64) -> Receiver<()> {
         let now = now();
         let mut inner = self.inner();
 
-        let (p, c) = Chan::new();
+        let (tx, rx) = channel();
         inner.repeat = false;
-        inner.chan = Some(c);
+        inner.tx = Some(tx);
         inner.interval = msecs;
         inner.target = now + msecs;
 
         timer_helper::send(NewTimer(inner));
-        return p;
+        return rx;
     }
 
-    fn period(&mut self, msecs: u64) -> Port<()> {
+    fn period(&mut self, msecs: u64) -> Receiver<()> {
         let now = now();
         let mut inner = self.inner();
 
-        let (p, c) = Chan::new();
+        let (tx, rx) = channel();
         inner.repeat = true;
-        inner.chan = Some(c);
+        inner.tx = Some(tx);
         inner.interval = msecs;
         inner.target = now + msecs;
 
         timer_helper::send(NewTimer(inner));
-        return p;
+        return rx;
     }
 }
 
diff --git a/src/libnative/io/timer_timerfd.rs b/src/libnative/io/timer_timerfd.rs
index 55301b6f7c8..1b0e08ca6fb 100644
--- a/src/libnative/io/timer_timerfd.rs
+++ b/src/libnative/io/timer_timerfd.rs
@@ -46,12 +46,12 @@ pub struct Timer {
 
 #[allow(visible_private_types)]
 pub enum Req {
-    NewTimer(libc::c_int, Chan<()>, bool, imp::itimerspec),
-    RemoveTimer(libc::c_int, Chan<()>),
+    NewTimer(libc::c_int, Sender<()>, bool, imp::itimerspec),
+    RemoveTimer(libc::c_int, Sender<()>),
     Shutdown,
 }
 
-fn helper(input: libc::c_int, messages: Port<Req>) {
+fn helper(input: libc::c_int, messages: Receiver<Req>) {
     let efd = unsafe { imp::epoll_create(10) };
     let _fd1 = FileDesc::new(input, true);
     let _fd2 = FileDesc::new(efd, true);
@@ -76,7 +76,7 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
 
     add(efd, input);
     let events: [imp::epoll_event, ..16] = unsafe { mem::init() };
-    let mut list: ~[(libc::c_int, Chan<()>, bool)] = ~[];
+    let mut list: ~[(libc::c_int, Sender<()>, bool)] = ~[];
     'outer: loop {
         let n = match unsafe {
             imp::epoll_wait(efd, events.as_ptr(),
@@ -197,9 +197,9 @@ impl Timer {
     fn remove(&mut self) {
         if !self.on_worker { return }
 
-        let (p, c) = Chan::new();
-        timer_helper::send(RemoveTimer(self.fd.fd(), c));
-        p.recv();
+        let (tx, rx) = channel();
+        timer_helper::send(RemoveTimer(self.fd.fd(), tx));
+        rx.recv();
         self.on_worker = false;
     }
 }
@@ -224,8 +224,8 @@ impl rtio::RtioTimer for Timer {
     // before returning to guarantee the invariant that when oneshot() and
     // period() return that the old port will never receive any more messages.
 
-    fn oneshot(&mut self, msecs: u64) -> Port<()> {
-        let (p, c) = Chan::new();
+    fn oneshot(&mut self, msecs: u64) -> Receiver<()> {
+        let (tx, rx) = channel();
 
         let new_value = imp::itimerspec {
             it_interval: imp::timespec { tv_sec: 0, tv_nsec: 0 },
@@ -234,26 +234,26 @@ impl rtio::RtioTimer for Timer {
                 tv_nsec: ((msecs % 1000) * 1000000) as libc::c_long,
             }
         };
-        timer_helper::send(NewTimer(self.fd.fd(), c, true, new_value));
-        p.recv();
+        timer_helper::send(NewTimer(self.fd.fd(), tx, true, new_value));
+        rx.recv();
         self.on_worker = true;
 
-        return p;
+        return rx;
     }
 
-    fn period(&mut self, msecs: u64) -> Port<()> {
-        let (p, c) = Chan::new();
+    fn period(&mut self, msecs: u64) -> Receiver<()> {
+        let (tx, rx) = channel();
 
         let spec = imp::timespec {
             tv_sec: (msecs / 1000) as libc::time_t,
             tv_nsec: ((msecs % 1000) * 1000000) as libc::c_long,
         };
         let new_value = imp::itimerspec { it_interval: spec, it_value: spec, };
-        timer_helper::send(NewTimer(self.fd.fd(), c, false, new_value));
-        p.recv();
+        timer_helper::send(NewTimer(self.fd.fd(), tx, false, new_value));
+        rx.recv();
         self.on_worker = true;
 
-        return p;
+        return rx;
     }
 }
 
diff --git a/src/libnative/io/timer_win32.rs b/src/libnative/io/timer_win32.rs
index 6b472d2f46d..cdfe2e0d033 100644
--- a/src/libnative/io/timer_win32.rs
+++ b/src/libnative/io/timer_win32.rs
@@ -34,12 +34,12 @@ pub struct Timer {
 }
 
 pub enum Req {
-    NewTimer(libc::HANDLE, Chan<()>, bool),
-    RemoveTimer(libc::HANDLE, Chan<()>),
+    NewTimer(libc::HANDLE, Sender<()>, bool),
+    RemoveTimer(libc::HANDLE, Sender<()>),
     Shutdown,
 }
 
-fn helper(input: libc::HANDLE, messages: Port<Req>) {
+fn helper(input: libc::HANDLE, messages: Receiver<Req>) {
     let mut objs = ~[input];
     let mut chans = ~[];
 
@@ -113,9 +113,9 @@ impl Timer {
     fn remove(&mut self) {
         if !self.on_worker { return }
 
-        let (p, c) = Chan::new();
-        timer_helper::send(RemoveTimer(self.obj, c));
-        p.recv();
+        let (tx, rx) = channel();
+        timer_helper::send(RemoveTimer(self.obj, tx));
+        rx.recv();
 
         self.on_worker = false;
     }
@@ -136,9 +136,9 @@ impl rtio::RtioTimer for Timer {
         let _ = unsafe { imp::WaitForSingleObject(self.obj, libc::INFINITE) };
     }
 
-    fn oneshot(&mut self, msecs: u64) -> Port<()> {
+    fn oneshot(&mut self, msecs: u64) -> Receiver<()> {
         self.remove();
-        let (p, c) = Chan::new();
+        let (tx, rx) = channel();
 
         // see above for the calculation
         let due = -(msecs * 10000) as libc::LARGE_INTEGER;
@@ -147,14 +147,14 @@ impl rtio::RtioTimer for Timer {
                                   ptr::mut_null(), 0)
         }, 1);
 
-        timer_helper::send(NewTimer(self.obj, c, true));
+        timer_helper::send(NewTimer(self.obj, tx, true));
         self.on_worker = true;
-        return p;
+        return rx;
     }
 
-    fn period(&mut self, msecs: u64) -> Port<()> {
+    fn period(&mut self, msecs: u64) -> Receiver<()> {
         self.remove();
-        let (p, c) = Chan::new();
+        let (tx, rx) = channel();
 
         // see above for the calculation
         let due = -(msecs * 10000) as libc::LARGE_INTEGER;
@@ -163,10 +163,10 @@ impl rtio::RtioTimer for Timer {
                                   ptr::null(), ptr::mut_null(), 0)
         }, 1);
 
-        timer_helper::send(NewTimer(self.obj, c, false));
+        timer_helper::send(NewTimer(self.obj, tx, false));
         self.on_worker = true;
 
-        return p;
+        return rx;
     }
 }
 
diff --git a/src/libnative/task.rs b/src/libnative/task.rs
index 793e4d48e13..8510b50777a 100644
--- a/src/libnative/task.rs
+++ b/src/libnative/task.rs
@@ -262,21 +262,21 @@ mod tests {
 
     #[test]
     fn smoke() {
-        let (p, c) = Chan::new();
+        let (tx, rx) = channel();
         spawn(proc() {
-            c.send(());
+            tx.send(());
         });
-        p.recv();
+        rx.recv();
     }
 
     #[test]
     fn smoke_fail() {
-        let (p, c) = Chan::<()>::new();
+        let (tx, rx) = channel::<()>();
         spawn(proc() {
-            let _c = c;
+            let _tx = tx;
             fail!()
         });
-        assert_eq!(p.recv_opt(), None);
+        assert_eq!(rx.recv_opt(), None);
     }
 
     #[test]
@@ -284,55 +284,54 @@ mod tests {
         let mut opts = TaskOpts::new();
         opts.name = Some("test".into_maybe_owned());
         opts.stack_size = Some(20 * 4096);
-        let (p, c) = Chan::new();
-        opts.notify_chan = Some(c);
+        let (tx, rx) = channel();
+        opts.notify_chan = Some(tx);
         spawn_opts(opts, proc() {});
-        assert!(p.recv().is_ok());
+        assert!(rx.recv().is_ok());
     }
 
     #[test]
     fn smoke_opts_fail() {
         let mut opts = TaskOpts::new();
-        let (p, c) = Chan::new();
-        opts.notify_chan = Some(c);
+        let (tx, rx) = channel();
+        opts.notify_chan = Some(tx);
         spawn_opts(opts, proc() { fail!() });
-        assert!(p.recv().is_err());
+        assert!(rx.recv().is_err());
     }
 
     #[test]
     fn yield_test() {
-        let (p, c) = Chan::new();
+        let (tx, rx) = channel();
         spawn(proc() {
             for _ in range(0, 10) { task::deschedule(); }
-            c.send(());
+            tx.send(());
         });
-        p.recv();
+        rx.recv();
     }
 
     #[test]
     fn spawn_children() {
-        let (p, c) = Chan::new();
+        let (tx1, rx) = channel();
         spawn(proc() {
-            let (p, c2) = Chan::new();
+            let (tx2, rx) = channel();
             spawn(proc() {
-                let (p, c3) = Chan::new();
+                let (tx3, rx) = channel();
                 spawn(proc() {
-                    c3.send(());
+                    tx3.send(());
                 });
-                p.recv();
-                c2.send(());
+                rx.recv();
+                tx2.send(());
             });
-            p.recv();
-            c.send(());
+            rx.recv();
+            tx1.send(());
         });
-        p.recv();
+        rx.recv();
     }
 
     #[test]
     fn spawn_inherits() {
-        let (p, c) = Chan::new();
+        let (tx, rx) = channel();
         spawn(proc() {
-            let c = c;
             spawn(proc() {
                 let mut task: ~Task = Local::take();
                 match task.maybe_take_runtime::<Ops>() {
@@ -342,9 +341,9 @@ mod tests {
                     None => fail!(),
                 }
                 Local::put(task);
-                c.send(());
+                tx.send(());
             });
         });
-        p.recv();
+        rx.recv();
     }
 }