Struct crossbeam_channel::flavors::list::Channel
source · pub(crate) struct Channel<T> {
head: CachePadded<Position<T>>,
tail: CachePadded<Position<T>>,
receivers: SyncWaker,
_marker: PhantomData<T>,
}
Expand description
Unbounded channel implemented as a linked list.
Each message sent into the channel is assigned a sequence number, i.e. an index. Indices are
represented as numbers of type usize
and wrap on overflow.
Consecutive messages are grouped into blocks in order to put less pressure on the allocator and improve cache efficiency.
Fields§
§head: CachePadded<Position<T>>
The head of the channel.
tail: CachePadded<Position<T>>
The tail of the channel.
receivers: SyncWaker
Receivers waiting while the channel is empty and not disconnected.
_marker: PhantomData<T>
Indicates that dropping a Channel<T>
may drop messages of type T
.
Implementations§
source§impl<T> Channel<T>
impl<T> Channel<T>
sourcefn start_send(&self, token: &mut Token) -> bool
fn start_send(&self, token: &mut Token) -> bool
Attempts to reserve a slot for sending a message.
sourcepub(crate) unsafe fn write(&self, token: &mut Token, msg: T) -> Result<(), T>
pub(crate) unsafe fn write(&self, token: &mut Token, msg: T) -> Result<(), T>
Writes a message into the channel.
sourcefn start_recv(&self, token: &mut Token) -> bool
fn start_recv(&self, token: &mut Token) -> bool
Attempts to reserve a slot for receiving a message.
sourcepub(crate) unsafe fn read(&self, token: &mut Token) -> Result<T, ()>
pub(crate) unsafe fn read(&self, token: &mut Token) -> Result<T, ()>
Reads a message from the channel.
sourcepub(crate) fn try_send(&self, msg: T) -> Result<(), TrySendError<T>>
pub(crate) fn try_send(&self, msg: T) -> Result<(), TrySendError<T>>
Attempts to send a message into the channel.
sourcepub(crate) fn send(
&self,
msg: T,
_deadline: Option<Instant>,
) -> Result<(), SendTimeoutError<T>>
pub(crate) fn send( &self, msg: T, _deadline: Option<Instant>, ) -> Result<(), SendTimeoutError<T>>
Sends a message into the channel.
sourcepub(crate) fn try_recv(&self) -> Result<T, TryRecvError>
pub(crate) fn try_recv(&self) -> Result<T, TryRecvError>
Attempts to receive a message without blocking.
sourcepub(crate) fn recv(
&self,
deadline: Option<Instant>,
) -> Result<T, RecvTimeoutError>
pub(crate) fn recv( &self, deadline: Option<Instant>, ) -> Result<T, RecvTimeoutError>
Receives a message from the channel.
sourcepub(crate) fn disconnect_senders(&self) -> bool
pub(crate) fn disconnect_senders(&self) -> bool
Disconnects senders and wakes up all blocked receivers.
Returns true
if this call disconnected the channel.
sourcepub(crate) fn disconnect_receivers(&self) -> bool
pub(crate) fn disconnect_receivers(&self) -> bool
Disconnects receivers.
Returns true
if this call disconnected the channel.
sourcefn discard_all_messages(&self)
fn discard_all_messages(&self)
Discards all messages.
This method should only be called when all receivers are dropped.
sourcepub(crate) fn is_disconnected(&self) -> bool
pub(crate) fn is_disconnected(&self) -> bool
Returns true
if the channel is disconnected.