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.
/// 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>,
/// 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,
})
}
- /// 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
}
}