]> git.proxmox.com Git - rustc.git/blobdiff - vendor/crossbeam-channel/src/flavors/zero.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / vendor / crossbeam-channel / src / flavors / zero.rs
index 031bfb8b11c6edaed758c1994f3518893bd89572..ee1bfc5344781711f1d4bafc04afc6b8a2065d94 100644 (file)
@@ -12,7 +12,7 @@ use crossbeam_utils::Backoff;
 use context::Context;
 use err::{RecvTimeoutError, SendTimeoutError, TryRecvError, TrySendError};
 use select::{Operation, SelectHandle, Selected, Token};
-use utils::Mutex;
+use utils::Spinlock;
 use waker::Waker;
 
 /// A pointer to a packet.
@@ -82,7 +82,7 @@ struct Inner {
 /// Zero-capacity channel.
 pub struct Channel<T> {
     /// Inner representation of the channel.
-    inner: Mutex<Inner>,
+    inner: Spinlock<Inner>,
 
     /// Indicates that dropping a `Channel<T>` may drop values of type `T`.
     _marker: PhantomData<T>,
@@ -92,7 +92,7 @@ impl<T> Channel<T> {
     /// Constructs a new zero-capacity channel.
     pub fn new() -> Self {
         Channel {
-            inner: Mutex::new(Inner {
+            inner: Spinlock::new(Inner {
                 senders: Waker::new(),
                 receivers: Waker::new(),
                 is_disconnected: false,
@@ -322,14 +322,19 @@ impl<T> Channel<T> {
         })
     }
 
-    /// Disconnects the channel and wakes up all blocked receivers.
-    pub fn disconnect(&self) {
+    /// Disconnects the channel and wakes up all blocked senders and receivers.
+    ///
+    /// Returns `true` if this call disconnected the channel.
+    pub fn disconnect(&self) -> bool {
         let mut inner = self.inner.lock();
 
         if !inner.is_disconnected {
             inner.is_disconnected = true;
             inner.senders.disconnect();
             inner.receivers.disconnect();
+            true
+        } else {
+            false
         }
     }