]> git.lizzy.rs Git - rust.git/blobdiff - src/libsync/comm/mod.rs
rollup merge of #17355 : gamazeps/issue17210
[rust.git] / src / libsync / comm / mod.rs
index e4df661b56201946dc852f7e75144b8357e12da5..4e66dd69a607b932d357d04843d6a92293520402 100644 (file)
@@ -86,6 +86,8 @@
 //!
 //! ```
 //! // Create a shared channel which can be sent along from many tasks
+//! // where tx is the sending half (tx for transmission), and rx is the receiving
+//! // half (rx for receiving).
 //! let (tx, rx) = channel();
 //! for i in range(0i, 10i) {
 //!     let tx = tx.clone();
@@ -377,14 +379,14 @@ pub struct Receiver<T> {
     inner: UnsafeCell<Flavor<T>>,
     receives: Cell<uint>,
     // can't share in an arc
-    marker: marker::NoSync,
+    _marker: marker::NoSync,
 }
 
 /// An iterator over messages on a receiver, this iterator will block
 /// whenever `next` is called, waiting for a new message, and `None` will be
 /// returned when the corresponding channel has hung up.
 #[unstable]
-pub struct Messages<'a, T> {
+pub struct Messages<'a, T:'a> {
     rx: &'a Receiver<T>
 }
 
@@ -395,7 +397,7 @@ pub struct Sender<T> {
     inner: UnsafeCell<Flavor<T>>,
     sends: Cell<uint>,
     // can't share in an arc
-    marker: marker::NoSync,
+    _marker: marker::NoSync,
 }
 
 /// The sending-half of Rust's synchronous channel type. This half can only be
@@ -404,7 +406,7 @@ pub struct Sender<T> {
 pub struct SyncSender<T> {
     inner: Arc<UnsafeCell<sync::Packet<T>>>,
     // can't share in an arc
-    marker: marker::NoSync,
+    _marker: marker::NoSync,
 }
 
 /// This enumeration is the list of the possible reasons that try_recv could not
@@ -447,7 +449,7 @@ enum Flavor<T> {
 #[doc(hidden)]
 trait UnsafeFlavor<T> {
     fn inner_unsafe<'a>(&'a self) -> &'a UnsafeCell<Flavor<T>>;
-    unsafe fn mut_inner<'a>(&'a self) -> &'a mut Flavor<T> {
+    unsafe fn inner_mut<'a>(&'a self) -> &'a mut Flavor<T> {
         &mut *self.inner_unsafe().get()
     }
     unsafe fn inner<'a>(&'a self) -> &'a Flavor<T> {
@@ -473,6 +475,8 @@ fn inner_unsafe<'a>(&'a self) -> &'a UnsafeCell<Flavor<T>> {
 /// # Example
 ///
 /// ```
+/// // tx is is the sending half (tx for transmission), and rx is the receiving
+/// // half (rx for receiving).
 /// let (tx, rx) = channel();
 ///
 /// // Spawn off an expensive computation
@@ -539,7 +543,7 @@ fn new(inner: Flavor<T>) -> Sender<T> {
         Sender {
             inner: UnsafeCell::new(inner),
             sends: Cell::new(0),
-            marker: marker::NoSync,
+            _marker: marker::NoSync,
         }
     }
 
@@ -650,7 +654,7 @@ pub fn send_opt(&self, t: T) -> Result<(), T> {
 
         unsafe {
             let tmp = Sender::new(Stream(new_inner));
-            mem::swap(self.mut_inner(), tmp.mut_inner());
+            mem::swap(self.inner_mut(), tmp.inner_mut());
         }
         return ret;
     }
@@ -691,7 +695,7 @@ fn clone(&self) -> Sender<T> {
             (*packet.get()).inherit_blocker(sleeper);
 
             let tmp = Sender::new(Shared(packet.clone()));
-            mem::swap(self.mut_inner(), tmp.mut_inner());
+            mem::swap(self.inner_mut(), tmp.inner_mut());
         }
         Sender::new(Shared(packet))
     }
@@ -700,7 +704,7 @@ fn clone(&self) -> Sender<T> {
 #[unsafe_destructor]
 impl<T: Send> Drop for Sender<T> {
     fn drop(&mut self) {
-        match *unsafe { self.mut_inner() } {
+        match *unsafe { self.inner_mut() } {
             Oneshot(ref mut p) => unsafe { (*p.get()).drop_chan(); },
             Stream(ref mut p) => unsafe { (*p.get()).drop_chan(); },
             Shared(ref mut p) => unsafe { (*p.get()).drop_chan(); },
@@ -715,7 +719,7 @@ fn drop(&mut self) {
 
 impl<T: Send> SyncSender<T> {
     fn new(inner: Arc<UnsafeCell<sync::Packet<T>>>) -> SyncSender<T> {
-        SyncSender { inner: inner, marker: marker::NoSync }
+        SyncSender { inner: inner, _marker: marker::NoSync }
     }
 
     /// Sends a value on this synchronous channel.
@@ -803,7 +807,7 @@ fn drop(&mut self) {
 
 impl<T: Send> Receiver<T> {
     fn new(inner: Flavor<T>) -> Receiver<T> {
-        Receiver { inner: UnsafeCell::new(inner), receives: Cell::new(0), marker: marker::NoSync }
+        Receiver { inner: UnsafeCell::new(inner), receives: Cell::new(0), _marker: marker::NoSync }
     }
 
     /// Blocks waiting for a value on this receiver
@@ -891,8 +895,8 @@ pub fn try_recv(&self) -> Result<T, TryRecvError> {
                 }
             };
             unsafe {
-                mem::swap(self.mut_inner(),
-                          new_port.mut_inner());
+                mem::swap(self.inner_mut(),
+                          new_port.inner_mut());
             }
         }
     }
@@ -939,7 +943,7 @@ pub fn recv_opt(&self) -> Result<T, ()> {
                 Sync(ref p) => return unsafe { (*p.get()).recv() }
             };
             unsafe {
-                mem::swap(self.mut_inner(), new_port.mut_inner());
+                mem::swap(self.inner_mut(), new_port.inner_mut());
             }
         }
     }
@@ -976,8 +980,8 @@ fn can_recv(&self) -> bool {
                 }
             };
             unsafe {
-                mem::swap(self.mut_inner(),
-                          new_port.mut_inner());
+                mem::swap(self.inner_mut(),
+                          new_port.inner_mut());
             }
         }
     }
@@ -1008,8 +1012,8 @@ fn start_selection(&self, mut task: BlockedTask) -> Result<(), BlockedTask>{
             };
             task = t;
             unsafe {
-                mem::swap(self.mut_inner(),
-                          new_port.mut_inner());
+                mem::swap(self.inner_mut(),
+                          new_port.inner_mut());
             }
         }
     }
@@ -1032,8 +1036,8 @@ fn abort_selection(&self) -> bool {
             let new_port = match result { Ok(b) => return b, Err(p) => p };
             was_upgrade = true;
             unsafe {
-                mem::swap(self.mut_inner(),
-                          new_port.mut_inner());
+                mem::swap(self.inner_mut(),
+                          new_port.inner_mut());
             }
         }
     }
@@ -1047,7 +1051,7 @@ fn next(&mut self) -> Option<T> { self.rx.recv_opt().ok() }
 #[unsafe_destructor]
 impl<T: Send> Drop for Receiver<T> {
     fn drop(&mut self) {
-        match *unsafe { self.mut_inner() } {
+        match *unsafe { self.inner_mut() } {
             Oneshot(ref mut p) => unsafe { (*p.get()).drop_port(); },
             Stream(ref mut p) => unsafe { (*p.get()).drop_port(); },
             Shared(ref mut p) => unsafe { (*p.get()).drop_port(); },