Struct futures_channel::oneshot::Inner
source · struct Inner<T> {
complete: AtomicBool,
data: Lock<Option<T>>,
rx_task: Lock<Option<Waker>>,
tx_task: Lock<Option<Waker>>,
}
Expand description
Internal state of the Receiver
/Sender
pair above. This is all used as
the internal synchronization between the two for send/recv operations.
Fields§
§complete: AtomicBool
Indicates whether this oneshot is complete yet. This is filled in both
by Sender::drop
and by Receiver::drop
, and both sides interpret it
appropriately.
For Receiver
, if this is true
, then it’s guaranteed that data
is
unlocked and ready to be inspected.
For Sender
if this is true
then the oneshot has gone away and it
can return ready from poll_canceled
.
data: Lock<Option<T>>
The actual data being transferred as part of this Receiver
. This is
filled in by Sender::complete
and read by Receiver::poll
.
Note that this is protected by Lock
, but it is in theory safe to
replace with an UnsafeCell
as it’s actually protected by complete
above. I wouldn’t recommend doing this, however, unless someone is
supremely confident in the various atomic orderings here and there.
rx_task: Lock<Option<Waker>>
Field to store the task which is blocked in Receiver::poll
.
This is filled in when a oneshot is polled but not ready yet. Note that
the Lock
here, unlike in data
above, is important to resolve races.
Both the Receiver
and the Sender
halves understand that if they
can’t acquire the lock then some important interference is happening.
tx_task: Lock<Option<Waker>>
Like rx_task
above, except for the task blocked in
Sender::poll_canceled
. Additionally, Lock
cannot be UnsafeCell
.