id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokio-rs/tokio:tokio/src/sync/oneshot.rs:29 | true
}
fn poll_recv(&self, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> {
// Keep track of task budget
let coop = ready!(crate::coop::poll_proceed(cx));
// Load the state
let mut state = State::load(&self.state, Acquire);
if state.is_complete() {
coo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 34b8ebbe662cd8c818bc017e81a717a465ab1f01 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/34b8ebbe662cd8c818bc017e81a717a465ab1f01/tokio/src/sync/oneshot.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:30 | };
} else {
unsafe { self.rx_task.drop_task() };
}
}
}
if !state.is_rx_task_set() {
// Attempt to set the task
unsafe {
self.rx_task.set_task(cx);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 34b8ebbe662cd8c818bc017e81a717a465ab1f01 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/34b8ebbe662cd8c818bc017e81a717a465ab1f01/tokio/src/sync/oneshot.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:31 | }
/// Consumes the value. This function does not check `state`.
///
/// # Safety
///
/// Calling this method concurrently on multiple threads will result in a
/// data race. The `VALUE_SENT` state bit is used to ensure that only the
/// sender *or* the receiver will call this method at a gi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 34b8ebbe662cd8c818bc017e81a717a465ab1f01 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/34b8ebbe662cd8c818bc017e81a717a465ab1f01/tokio/src/sync/oneshot.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:32 | impl<T: fmt::Debug> fmt::Debug for Inner<T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
use std::sync::atomic::Ordering::Relaxed;
fmt.debug_struct("Inner")
.field("state", &State::load(&self.state, Relaxed))
.finish()
}
}
/// Indicates that a waker fo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 34b8ebbe662cd8c818bc017e81a717a465ab1f01 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/34b8ebbe662cd8c818bc017e81a717a465ab1f01/tokio/src/sync/oneshot.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:33 | fn is_complete(self) -> bool {
self.0 & VALUE_SENT == VALUE_SENT
}
fn set_complete(cell: &AtomicUsize) -> State {
// This method is a compare-and-swap loop rather than a fetch-or like
// other `set_$WHATEVER` methods on `State`. This is because we must
// check if the state has ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 34b8ebbe662cd8c818bc017e81a717a465ab1f01 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/34b8ebbe662cd8c818bc017e81a717a465ab1f01/tokio/src/sync/oneshot.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:34 | self.0 & RX_TASK_SET == RX_TASK_SET
}
fn set_rx_task(cell: &AtomicUsize) -> State {
let val = cell.fetch_or(RX_TASK_SET, AcqRel);
State(val | RX_TASK_SET)
}
fn unset_rx_task(cell: &AtomicUsize) -> State {
let val = cell.fetch_and(!RX_TASK_SET, AcqRel);
State(val & !RX_T... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 34b8ebbe662cd8c818bc017e81a717a465ab1f01 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/34b8ebbe662cd8c818bc017e81a717a465ab1f01/tokio/src/sync/oneshot.rs | 1,321 | 1,378 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:35 | }
fn load(cell: &AtomicUsize, order: Ordering) -> State {
let val = cell.load(order);
State(val)
}
}
impl fmt::Debug for State {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("State")
.field("is_complete", &self.is_complete())
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 34b8ebbe662cd8c818bc017e81a717a465ab1f01 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/34b8ebbe662cd8c818bc017e81a717a465ab1f01/tokio/src/sync/oneshot.rs | 1,361 | 1,378 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:8 | /// use tokio::sync::oneshot;
/// use tokio::time::{interval, sleep, Duration};
///
/// #[tokio::main]
/// # async fn _doc() {}
/// # #[tokio::main(flavor = "current_thread", start_paused = true)]
/// async fn main() {
/// let (send, mut recv) = oneshot::channel();
/// let mut interval = interval(Duration::from... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:9 | //! Oneshot error types.
use std::fmt;
/// Error returned by the `Future` implementation for `Receiver`.
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct RecvError(pub(super) ());
/// Error returned by the `try_recv` function on `Receiver`.
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:10 | }
use self::error::*;
struct Inner<T> {
/// Manages the state of the inner cell.
state: AtomicUsize,
/// The value. This is set by `Sender` and read by `Receiver`. The state of
/// the cell is tracked by `state`.
value: UnsafeCell<Option<T>>,
/// The task to notify when the receiver drops wi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:11 | self.0.with(|ptr| {
let waker: *const Waker = (&*ptr).as_ptr();
f(&*waker)
})
}
unsafe fn drop_task(&self) {
self.0.with_mut(|ptr| {
let ptr: *mut Waker = (&mut *ptr).as_mut_ptr();
ptr.drop_in_place();
});
}
unsafe fn set_task(&se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:12 | /// let (tx, rx) = oneshot::channel();
///
/// tokio::spawn(async move {
/// if let Err(_) = tx.send(3) {
/// println!("the receiver dropped");
/// }
/// });
///
/// match rx.await {
/// Ok(v) => println!("got = {:?}", v),
/// Err(_) => println!("the sender dr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:13 | rx_dropped = false,
rx_dropped.op = "override",
)
});
resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
value_sent = false,
value_sent.op = "override",
)
});
resour... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:14 | #[cfg(all(tokio_unstable, feature = "tracing"))]
let async_op_poll_span =
async_op_span.in_scope(|| tracing::trace_span!("runtime.resource.async_op.poll"));
let rx = Receiver {
inner: Some(inner),
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span,
#[cfg(all(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:15 | /// ```
/// use tokio::sync::oneshot;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, rx) = oneshot::channel();
///
/// tokio::spawn(async move {
/// if let Err(_) = tx.send(3) {
/// println!("the receiver dropped");
/// }
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:17 | /// async fn main() {
/// let (mut tx, rx) = oneshot::channel::<()>();
///
/// tokio::spawn(async move {
/// drop(rx);
/// });
///
/// tx.closed().await;
/// println!("the receiver dropped");
/// }
/// ```
///
/// Paired with select
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:18 | /// // Wait for up to 10 seconds
/// let _ = time::timeout(Duration::from_secs(10), rx).await;
/// }
/// ```
pub async fn closed(&mut self) {
use crate::future::poll_fn;
#[cfg(all(tokio_unstable, feature = "tracing"))]
let resource_span = self.resource_span.clone();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:20 | /// use tokio::sync::oneshot;
///
/// use futures::future::poll_fn;
///
/// #[tokio::main]
/// async fn main() {
/// let (mut tx, mut rx) = oneshot::channel::<()>();
///
/// tokio::spawn(async move {
/// rx.close();
/// });
///
/// poll_fn(|cx| tx.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:21 | return Ready(());
} else {
unsafe { inner.tx_task.drop_task() };
}
}
}
if !state.is_tx_task_set() {
// Attempt to set the task
unsafe {
inner.tx_task.set_task(cx);
}
// Updat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:25 | /// `try_recv` when the sender dropped before sending a value
///
/// ```
/// use tokio::sync::oneshot;
/// use tokio::sync::oneshot::error::TryRecvError;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx) = oneshot::channel::<()>();
///
/// drop(tx);
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:26 | }
None => Err(TryRecvError::Closed),
}
} else if state.is_closed() {
Err(TryRecvError::Closed)
} else {
// Not ready, this does not clear `inner`
return Err(TryRecvError::Empty);
}
} else {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:27 | /// }
/// ```
#[cfg(feature = "sync")]
pub fn blocking_recv(self) -> Result<T, RecvError> {
crate::future::block_on(self)
}
}
impl<T> Drop for Receiver<T> {
fn drop(&mut self) {
if let Some(inner) = self.inner.as_ref() {
inner.close();
#[cfg(all(tokio_unstabl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:28 | #[cfg(any(not(tokio_unstable), not(feature = "tracing")))]
let res = ready!(inner.poll_recv(cx))?;
res
} else {
panic!("called after complete");
};
self.inner = None;
Ready(Ok(ret))
}
}
impl<T> Inner<T> {
fn complete(&self) -> bool {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:29 | match unsafe { self.consume_value() } {
Some(value) => Ready(Ok(value)),
None => Ready(Err(RecvError(()))),
}
} else if state.is_closed() {
coop.made_progress();
Ready(Err(RecvError(())))
} else {
if state.is_rx_task_set() {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:30 | // Update the state
state = State::set_rx_task(&self.state);
if state.is_complete() {
coop.made_progress();
match unsafe { self.consume_value() } {
Some(value) => Ready(Ok(value)),
None => Ready(Err(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:31 | self.value.with_mut(|ptr| (*ptr).take())
}
}
unsafe impl<T: Send> Send for Inner<T> {}
unsafe impl<T: Send> Sync for Inner<T> {}
fn mut_load(this: &mut AtomicUsize) -> usize {
this.with_mut(|v| *v)
}
impl<T> Drop for Inner<T> {
fn drop(&mut self) {
let state = State(mut_load(&mut self.state));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:32 | ///
/// # Safety
///
/// If this bit is not set, the `rx_task` field may be uninitialized.
const RX_TASK_SET: usize = 0b00001;
/// Indicates that a value has been stored in the channel's inner `UnsafeCell`.
///
/// # Safety
///
/// This bit controls which side of the channel is permitted to access the
/// `UnsafeCell`.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:33 | // it's okay to access the inner `UnsafeCell`. Immediately after calling
// `set_complete`, if the channel was closed, the sender will _also_
// access the `UnsafeCell` to take the value back out, so if a
// `poll_recv` or `try_recv` call is occurring concurrently, both
// threads may tr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:34 | fn is_closed(self) -> bool {
self.0 & CLOSED == CLOSED
}
fn set_closed(cell: &AtomicUsize) -> State {
// Acquire because we want all later writes (attempting to poll) to be
// ordered after this.
let val = cell.fetch_or(CLOSED, Acquire);
State(val)
}
fn set_tx_t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 3652f71ade9caa07378ac0225a198e83207f4213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/oneshot.rs | 1,321 | 1,366 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:8 | /// use tokio::sync::oneshot;
/// use tokio::time::{interval, sleep, Duration};
///
/// #[tokio::main]
/// # async fn _doc() {}
/// # #[tokio::main(flavor = "current_thread", start_paused = true)]
/// async fn main() {
/// let (send, mut recv) = oneshot::channel();
/// let mut interval = interval(Duration::from... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/oneshot.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:9 | //! Oneshot error types.
use std::fmt;
/// Error returned by the `Future` implementation for `Receiver`.
#[derive(Debug, Eq, PartialEq)]
pub struct RecvError(pub(super) ());
/// Error returned by the `try_recv` function on `Receiver`.
#[derive(Debug, Eq, PartialEq)]
pub enum TryRecvError ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | dee26c92ddb32e23acb0c1587e775ddab29e07f9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dee26c92ddb32e23acb0c1587e775ddab29e07f9/tokio/src/sync/oneshot.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:13 | rx_dropped = false,
rx_dropped.op = "override",
)
});
resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
value_sent = false,
value_sent.op = "override",
)
});
resour... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | bcb968af8494d2808c2986104d6e67d0b276b1fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/bcb968af8494d2808c2986104d6e67d0b276b1fe/tokio/src/sync/oneshot.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:14 | #[cfg(all(tokio_unstable, feature = "tracing"))]
let async_op_poll_span =
async_op_span.in_scope(|| tracing::trace_span!("runtime.resource.async_op.poll"));
let rx = Receiver {
inner: Some(inner),
#[cfg(all(tokio_unstable, feature = "tracing"))]
resource_span: resource_span,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | bcb968af8494d2808c2986104d6e67d0b276b1fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/bcb968af8494d2808c2986104d6e67d0b276b1fe/tokio/src/sync/oneshot.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:25 | /// `try_recv` when the sender dropped before sending a value
///
/// ```
/// use tokio::sync::oneshot;
/// use tokio::sync::oneshot::error::TryRecvError;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx) = oneshot::channel::<()>();
///
/// drop(tx);
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/oneshot.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:26 | }
None => Err(TryRecvError::Closed),
}
} else if state.is_closed() {
Err(TryRecvError::Closed)
} else {
// Not ready, this does not clear `inner`
return Err(TryRecvError::Empty);
}
} else {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/oneshot.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:27 | let _res_span = self.resource_span.clone().entered();
#[cfg(all(tokio_unstable, feature = "tracing"))]
let _ao_span = self.async_op_span.clone().entered();
#[cfg(all(tokio_unstable, feature = "tracing"))]
let _ao_poll_span = self.async_op_poll_span.clone().entered();
let ret = i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/oneshot.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:28 | fn poll_recv(&self, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> {
// Keep track of task budget
let coop = ready!(crate::coop::poll_proceed(cx));
// Load the state
let mut state = State::load(&self.state, Acquire);
if state.is_complete() {
coop.made_progress(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/oneshot.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:29 | unsafe { self.rx_task.drop_task() };
}
}
}
if !state.is_rx_task_set() {
// Attempt to set the task
unsafe {
self.rx_task.set_task(cx);
}
// Update the state
s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/oneshot.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:30 | /// Consumes the value. This function does not check `state`.
///
/// # Safety
///
/// Calling this method concurrently on multiple threads will result in a
/// data race. The `VALUE_SENT` state bit is used to ensure that only the
/// sender *or* the receiver will call this method at a given poi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/oneshot.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:31 | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
use std::sync::atomic::Ordering::Relaxed;
fmt.debug_struct("Inner")
.field("state", &State::load(&self.state, Relaxed))
.finish()
}
}
/// Indicates that a waker for the receiving task has been set.
///
/// # Safet... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/oneshot.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:32 | }
fn set_complete(cell: &AtomicUsize) -> State {
// This method is a compare-and-swap loop rather than a fetch-or like
// other `set_$WHATEVER` methods on `State`. This is because we must
// check if the state has been closed before setting the `VALUE_SENT`
// bit.
//
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/oneshot.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:33 | fn set_rx_task(cell: &AtomicUsize) -> State {
let val = cell.fetch_or(RX_TASK_SET, AcqRel);
State(val | RX_TASK_SET)
}
fn unset_rx_task(cell: &AtomicUsize) -> State {
let val = cell.fetch_and(!RX_TASK_SET, AcqRel);
State(val & !RX_TASK_SET)
}
fn is_closed(self) -> bool ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/oneshot.rs | 1,281 | 1,336 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:34 | fn load(cell: &AtomicUsize, order: Ordering) -> State {
let val = cell.load(order);
State(val)
}
}
impl fmt::Debug for State {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("State")
.field("is_complete", &self.is_complete())
.field... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4e3268d222423e874f5bbfa67e20f773da3c025f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4e3268d222423e874f5bbfa67e20f773da3c025f/tokio/src/sync/oneshot.rs | 1,321 | 1,336 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:8 | /// # async fn _doc() {}
/// # #[tokio::main(flavor = "current_thread", start_paused = true)]
/// async fn main() {
/// let (send, mut recv) = oneshot::channel();
/// let mut interval = interval(Duration::from_millis(100));
///
/// # let handle =
/// tokio::spawn(async move {
/// sleep(Duration:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/src/sync/oneshot.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:9 | pub enum TryRecvError {
/// The send half of the channel has not yet sent a value.
Empty,
/// The send half of the channel was dropped without sending a value.
Closed,
}
// ===== impl RecvError =====
impl fmt::Display for RecvError {
fn fmt(&self, fmt: &mut fmt::Fo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/src/sync/oneshot.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:10 | value: UnsafeCell<Option<T>>,
/// The task to notify when the receiver drops without consuming the value.
///
/// ## Safety
///
/// The `TX_TASK_SET` bit in the `state` field is set if this field is
/// initialized. If that bit is unset, this field may be uninitialized.
tx_task: Task,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/src/sync/oneshot.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:11 | });
}
unsafe fn set_task(&self, cx: &mut Context<'_>) {
self.0.with_mut(|ptr| {
let ptr: *mut Waker = (&mut *ptr).as_mut_ptr();
ptr.write(cx.waker().clone());
});
}
}
#[derive(Clone, Copy)]
struct State(usize);
/// Creates a new one-shot channel for sending single ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/src/sync/oneshot.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:12 | /// Err(_) => println!("the sender dropped"),
/// }
/// }
/// ```
pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
let inner = Arc::new(Inner {
state: AtomicUsize::new(State::new().as_usize()),
value: UnsafeCell::new(None),
tx_task: Task(UnsafeCell::new(MaybeUninit::uninit())),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/src/sync/oneshot.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:17 | ///
/// A [`Receiver`] is closed by either calling [`close`] explicitly, or when the
/// [`Receiver`] value is dropped.
///
/// Note that on multiple calls to poll, only the `Waker` from the `Context` passed
/// to the most recent call will be scheduled to receive a wakeup.
///
/// [`Receive... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/src/sync/oneshot.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:18 | let inner = self.inner.as_ref().unwrap();
let mut state = State::load(&inner.state, Acquire);
if state.is_closed() {
coop.made_progress();
return Poll::Ready(());
}
if state.is_tx_task_set() {
let will_notify = unsafe { inner.tx_task.will_wake(cx) }... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/src/sync/oneshot.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:22 | /// }
/// }
/// ```
///
/// `try_recv` when the sender dropped before sending a value
///
/// ```
/// use tokio::sync::oneshot;
/// use tokio::sync::oneshot::error::TryRecvError;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx) = oneshot::channel:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/src/sync/oneshot.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:23 | // Not ready, this does not clear `inner`
return Err(TryRecvError::Empty);
}
} else {
Err(TryRecvError::Closed)
};
self.inner = None;
result
}
}
impl<T> Drop for Receiver<T> {
fn drop(&mut self) {
if let Some(inner) = self.inner.a... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/src/sync/oneshot.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:24 | if prev.is_closed() {
return false;
}
if prev.is_rx_task_set() {
// TODO: Consume waker?
unsafe {
self.rx_task.with_task(Waker::wake_by_ref);
}
}
true
}
fn poll_recv(&self, cx: &mut Context<'_>) -> Poll<Result<T, ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | b1afd95994be0d46ea70ba784439a684a787f50e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1afd95994be0d46ea70ba784439a684a787f50e/tokio/src/sync/oneshot.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:8 | /// let (send, mut recv) = oneshot::channel();
/// let mut interval = interval(Duration::from_millis(100));
///
/// # let handle =
/// tokio::spawn(async move {
/// sleep(Duration::from_secs(1)).await;
/// send.send("shut down").unwrap();
/// });
///
/// loop {
/// tokio:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 26f0938bf323bdc04c23491685548924c29ea897 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/26f0938bf323bdc04c23491685548924c29ea897/tokio/src/sync/oneshot.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:9 | /// The send half of the channel was dropped without sending a value.
Closed,
}
// ===== impl RecvError =====
impl fmt::Display for RecvError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "channel closed")
}
}
impl std::error::Error... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 26f0938bf323bdc04c23491685548924c29ea897 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/26f0938bf323bdc04c23491685548924c29ea897/tokio/src/sync/oneshot.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:10 | ///
/// ## Safety
///
/// The `TX_TASK_SET` bit in the `state` field is set if this field is
/// initialized. If that bit is unset, this field may be uninitialized.
tx_task: Task,
/// The task to notify when the value is sent.
///
/// ## Safety
///
/// The `RX_TASK_SET` bit in t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 26f0938bf323bdc04c23491685548924c29ea897 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/26f0938bf323bdc04c23491685548924c29ea897/tokio/src/sync/oneshot.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:11 | unsafe fn set_task(&self, cx: &mut Context<'_>) {
self.0.with_mut(|ptr| {
let ptr: *mut Waker = (&mut *ptr).as_mut_ptr();
ptr.write(cx.waker().clone());
});
}
}
#[derive(Clone, Copy)]
struct State(usize);
/// Creates a new one-shot channel for sending single values across a... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 26f0938bf323bdc04c23491685548924c29ea897 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/26f0938bf323bdc04c23491685548924c29ea897/tokio/src/sync/oneshot.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:12 | /// ```
pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
let inner = Arc::new(Inner {
state: AtomicUsize::new(State::new().as_usize()),
value: UnsafeCell::new(None),
tx_task: Task(UnsafeCell::new(MaybeUninit::uninit())),
rx_task: Task(UnsafeCell::new(MaybeUninit::uninit())),
});... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 26f0938bf323bdc04c23491685548924c29ea897 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/26f0938bf323bdc04c23491685548924c29ea897/tokio/src/sync/oneshot.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:17 | ///
/// Note that on multiple calls to poll, only the `Waker` from the `Context` passed
/// to the most recent call will be scheduled to receive a wakeup.
///
/// [`Receiver`]: struct@crate::sync::oneshot::Receiver
/// [`close`]: fn@crate::sync::oneshot::Receiver::close
///
/// # Return valu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 26f0938bf323bdc04c23491685548924c29ea897 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/26f0938bf323bdc04c23491685548924c29ea897/tokio/src/sync/oneshot.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:18 | let mut state = State::load(&inner.state, Acquire);
if state.is_closed() {
coop.made_progress();
return Poll::Ready(());
}
if state.is_tx_task_set() {
let will_notify = unsafe { inner.tx_task.will_wake(cx) };
if !will_notify {
st... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 26f0938bf323bdc04c23491685548924c29ea897 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/26f0938bf323bdc04c23491685548924c29ea897/tokio/src/sync/oneshot.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:22 | ///
/// `try_recv` when the sender dropped before sending a value
///
/// ```
/// use tokio::sync::oneshot;
/// use tokio::sync::oneshot::error::TryRecvError;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx) = oneshot::channel::<()>();
///
/// drop(tx... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 26f0938bf323bdc04c23491685548924c29ea897 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/26f0938bf323bdc04c23491685548924c29ea897/tokio/src/sync/oneshot.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:23 | } else {
Err(TryRecvError::Closed)
};
self.inner = None;
result
}
}
impl<T> Drop for Receiver<T> {
fn drop(&mut self) {
if let Some(inner) = self.inner.as_ref() {
inner.close();
}
}
}
impl<T> Future for Receiver<T> {
type Output = Result... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 26f0938bf323bdc04c23491685548924c29ea897 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/26f0938bf323bdc04c23491685548924c29ea897/tokio/src/sync/oneshot.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:24 | if prev.is_rx_task_set() {
// TODO: Consume waker?
unsafe {
self.rx_task.with_task(Waker::wake_by_ref);
}
}
true
}
fn poll_recv(&self, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> {
// Keep track of task budget
let coop... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 26f0938bf323bdc04c23491685548924c29ea897 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/26f0938bf323bdc04c23491685548924c29ea897/tokio/src/sync/oneshot.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:9 | /// The send half of the channel was dropped without sending a value.
Closed,
}
// ===== impl RecvError =====
impl fmt::Display for RecvError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "channel closed")
}
}
impl std::error::Error... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4b78ed4d68107be1d4c723cd55bec8eecfdc540a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b78ed4d68107be1d4c723cd55bec8eecfdc540a/tokio/src/sync/oneshot.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:10 | tx_task: Task,
/// The task to notify when the value is sent.
rx_task: Task,
}
struct Task(UnsafeCell<MaybeUninit<Waker>>);
impl Task {
unsafe fn will_wake(&self, cx: &mut Context<'_>) -> bool {
self.with_task(|w| w.will_wake(cx.waker()))
}
unsafe fn with_task<F, R>(&self, f: F) -> R
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4b78ed4d68107be1d4c723cd55bec8eecfdc540a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b78ed4d68107be1d4c723cd55bec8eecfdc540a/tokio/src/sync/oneshot.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:11 | /// Creates a new one-shot channel for sending single values across asynchronous
/// tasks.
///
/// The function returns separate "send" and "receive" handles. The `Sender`
/// handle is used by the producer to send the value. The `Receiver` handle is
/// used by the consumer to receive the value.
///
/// Each handle c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4b78ed4d68107be1d4c723cd55bec8eecfdc540a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b78ed4d68107be1d4c723cd55bec8eecfdc540a/tokio/src/sync/oneshot.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:12 | inner: Some(inner.clone()),
};
let rx = Receiver { inner: Some(inner) };
(tx, rx)
}
impl<T> Sender<T> {
/// Attempts to send a value on this channel, returning it back if it could
/// not be sent.
///
/// This method consumes `self` as only one value may ever be sent on a oneshot
/// c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4b78ed4d68107be1d4c723cd55bec8eecfdc540a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b78ed4d68107be1d4c723cd55bec8eecfdc540a/tokio/src/sync/oneshot.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:17 | /// let (mut tx, mut rx) = oneshot::channel::<()>();
///
/// tokio::spawn(async move {
/// rx.close();
/// });
///
/// poll_fn(|cx| tx.poll_closed(cx)).await;
///
/// println!("the receiver dropped");
/// }
/// ```
pub fn poll_closed(&mut self, cx:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4b78ed4d68107be1d4c723cd55bec8eecfdc540a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b78ed4d68107be1d4c723cd55bec8eecfdc540a/tokio/src/sync/oneshot.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:18 | if !state.is_tx_task_set() {
// Attempt to set the task
unsafe {
inner.tx_task.set_task(cx);
}
// Update the state
state = State::set_tx_task(&inner.state);
if state.is_closed() {
coop.made_progress();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4b78ed4d68107be1d4c723cd55bec8eecfdc540a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b78ed4d68107be1d4c723cd55bec8eecfdc540a/tokio/src/sync/oneshot.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:21 | /// let (tx, mut rx) = oneshot::channel();
///
/// match rx.try_recv() {
/// // The channel is currently empty
/// Err(TryRecvError::Empty) => {}
/// _ => unreachable!(),
/// }
///
/// // Send a value
/// tx.send("hello").unwrap();
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4b78ed4d68107be1d4c723cd55bec8eecfdc540a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b78ed4d68107be1d4c723cd55bec8eecfdc540a/tokio/src/sync/oneshot.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:22 | if state.is_complete() {
match unsafe { inner.consume_value() } {
Some(value) => Ok(value),
None => Err(TryRecvError::Closed),
}
} else if state.is_closed() {
Err(TryRecvError::Closed)
} else {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4b78ed4d68107be1d4c723cd55bec8eecfdc540a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b78ed4d68107be1d4c723cd55bec8eecfdc540a/tokio/src/sync/oneshot.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:23 | self.inner = None;
Ready(Ok(ret))
}
}
impl<T> Inner<T> {
fn complete(&self) -> bool {
let prev = State::set_complete(&self.state);
if prev.is_closed() {
return false;
}
if prev.is_rx_task_set() {
// TODO: Consume waker?
unsafe {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4b78ed4d68107be1d4c723cd55bec8eecfdc540a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b78ed4d68107be1d4c723cd55bec8eecfdc540a/tokio/src/sync/oneshot.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:24 | if state.is_rx_task_set() {
let will_notify = unsafe { self.rx_task.will_wake(cx) };
// Check if the task is still the same
if !will_notify {
// Unset the task
state = State::unset_rx_task(&self.state);
if state... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4b78ed4d68107be1d4c723cd55bec8eecfdc540a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b78ed4d68107be1d4c723cd55bec8eecfdc540a/tokio/src/sync/oneshot.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:25 | } else {
Pending
}
}
}
/// Called by `Receiver` to indicate that the value will never be received.
fn close(&self) {
let prev = State::set_closed(&self.state);
if prev.is_tx_task_set() && !prev.is_complete() {
unsafe {
self.tx... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4b78ed4d68107be1d4c723cd55bec8eecfdc540a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b78ed4d68107be1d4c723cd55bec8eecfdc540a/tokio/src/sync/oneshot.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:26 | if state.is_tx_task_set() {
unsafe {
self.tx_task.drop_task();
}
}
}
}
impl<T: fmt::Debug> fmt::Debug for Inner<T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
use std::sync::atomic::Ordering::Relaxed;
fmt.debug_struct("Inner")
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 4b78ed4d68107be1d4c723cd55bec8eecfdc540a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b78ed4d68107be1d4c723cd55bec8eecfdc540a/tokio/src/sync/oneshot.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:26 | if state.is_tx_task_set() {
unsafe {
self.tx_task.drop_task();
}
}
}
}
impl<T: fmt::Debug> fmt::Debug for Inner<T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
use std::sync::atomic::Ordering::Relaxed;
fmt.debug_struct("Inner")
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/oneshot.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:8 | /// let (send, mut recv) = oneshot::channel();
/// let mut interval = interval(Duration::from_millis(100));
///
/// # let handle =
/// tokio::spawn(async move {
/// sleep(Duration::from_secs(1)).await;
/// send.send("shut down").unwrap();
/// });
///
/// loop {
/// tokio:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f0cb360d7031313fb8bd74dc8a377da2de980df9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f0cb360d7031313fb8bd74dc8a377da2de980df9/tokio/src/sync/oneshot.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:9 | /// The send half of the channel was dropped without sending a value.
Closed,
}
// ===== impl RecvError =====
impl fmt::Display for RecvError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "channel closed")
}
}
impl std::error::Error... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f0cb360d7031313fb8bd74dc8a377da2de980df9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f0cb360d7031313fb8bd74dc8a377da2de980df9/tokio/src/sync/oneshot.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:10 | tx_task: Task,
/// The task to notify when the value is sent.
rx_task: Task,
}
struct Task(UnsafeCell<MaybeUninit<Waker>>);
impl Task {
unsafe fn will_wake(&self, cx: &mut Context<'_>) -> bool {
self.with_task(|w| w.will_wake(cx.waker()))
}
unsafe fn with_task<F, R>(&self, f: F) -> R
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f0cb360d7031313fb8bd74dc8a377da2de980df9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f0cb360d7031313fb8bd74dc8a377da2de980df9/tokio/src/sync/oneshot.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:11 | /// Create a new one-shot channel for sending single values across asynchronous
/// tasks.
///
/// The function returns separate "send" and "receive" handles. The `Sender`
/// handle is used by the producer to send the value. The `Receiver` handle is
/// used by the consumer to receive the value.
///
/// Each handle ca... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f0cb360d7031313fb8bd74dc8a377da2de980df9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f0cb360d7031313fb8bd74dc8a377da2de980df9/tokio/src/sync/oneshot.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:2 | //! async fn main() {
//! let (tx, rx) = oneshot::channel::<u32>();
//!
//! tokio::spawn(async move {
//! drop(tx);
//! });
//!
//! match rx.await {
//! Ok(_) => panic!("This doesn't happen"),
//! Err(_) => println!("the sender dropped"),
//! }
//! }
//! ```
use crate::loom:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:4 | /// }
/// ```
#[derive(Debug)]
pub struct Receiver<T> {
inner: Option<Arc<Inner<T>>>,
}
pub mod error {
//! Oneshot error types
use std::fmt;
/// Error returned by the `Future` implementation for `Receiver`.
#[derive(Debug, Eq, PartialEq)]
pub struct RecvError(pub(super) ());
/// Error r... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:5 | match self {
TryRecvError::Empty => write!(fmt, "channel empty"),
TryRecvError::Closed => write!(fmt, "channel closed"),
}
}
}
impl std::error::Error for TryRecvError {}
}
use self::error::*;
struct Inner<T> {
/// Manages the state of the inner cell
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:6 | f(&*waker)
})
}
unsafe fn drop_task(&self) {
self.0.with_mut(|ptr| {
let ptr: *mut Waker = (&mut *ptr).as_mut_ptr();
ptr.drop_in_place();
});
}
unsafe fn set_task(&self, cx: &mut Context<'_>) {
self.0.with_mut(|ptr| {
let ptr: *mut Wa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:7 | /// tokio::spawn(async move {
/// if let Err(_) = tx.send(3) {
/// println!("the receiver dropped");
/// }
/// });
///
/// match rx.await {
/// Ok(v) => println!("got = {:?}", v),
/// Err(_) => println!("the sender dropped"),
/// }
/// }
/// ```
pub fn channel... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:12 | /// to the most recent call will be scheduled to receive a wakeup.
///
/// [`Receiver`]: struct@crate::sync::oneshot::Receiver
/// [`close`]: fn@crate::sync::oneshot::Receiver::close
///
/// # Return value
///
/// This function returns:
///
/// * `Poll::Pending` if the channel is st... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:13 | if state.is_closed() {
coop.made_progress();
return Poll::Ready(());
}
if state.is_tx_task_set() {
let will_notify = unsafe { inner.tx_task.will_wake(cx) };
if !will_notify {
state = State::unset_tx_task(&inner.state);
if... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:17 | ///
/// ```
/// use tokio::sync::oneshot;
/// use tokio::sync::oneshot::error::TryRecvError;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx) = oneshot::channel::<()>();
///
/// drop(tx);
///
/// match rx.try_recv() {
/// // The channe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:18 | }
impl<T> Drop for Receiver<T> {
fn drop(&mut self) {
if let Some(inner) = self.inner.as_ref() {
inner.close();
}
}
}
impl<T> Future for Receiver<T> {
type Output = Result<T, RecvError>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:19 | true
}
fn poll_recv(&self, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> {
// Keep track of task budget
let coop = ready!(crate::coop::poll_proceed(cx));
// Load the state
let mut state = State::load(&self.state, Acquire);
if state.is_complete() {
coo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:20 | }
}
if !state.is_rx_task_set() {
// Attempt to set the task
unsafe {
self.rx_task.set_task(cx);
}
// Update the state
state = State::set_rx_task(&self.state);
if state.is_comple... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:21 | self.value.with_mut(|ptr| (*ptr).take())
}
}
unsafe impl<T: Send> Send for Inner<T> {}
unsafe impl<T: Send> Sync for Inner<T> {}
fn mut_load(this: &mut AtomicUsize) -> usize {
this.with_mut(|v| *v)
}
impl<T> Drop for Inner<T> {
fn drop(&mut self) {
let state = State(mut_load(&mut self.state));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:22 | const VALUE_SENT: usize = 0b00010;
const CLOSED: usize = 0b00100;
const TX_TASK_SET: usize = 0b01000;
impl State {
fn new() -> State {
State(0)
}
fn is_complete(self) -> bool {
self.0 & VALUE_SENT == VALUE_SENT
}
fn set_complete(cell: &AtomicUsize) -> State {
// TODO: This... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:23 | // Acquire because we want all later writes (attempting to poll) to be
// ordered after this.
let val = cell.fetch_or(CLOSED, Acquire);
State(val)
}
fn set_tx_task(cell: &AtomicUsize) -> State {
let val = cell.fetch_or(TX_TASK_SET, AcqRel);
State(val | TX_TASK_SET)
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f93bc9bad1e1a92328c62947e00e93c92e3b7614 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f93bc9bad1e1a92328c62947e00e93c92e3b7614/tokio/src/sync/oneshot.rs | 881 | 920 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:17 | ///
/// ```
/// use tokio::sync::oneshot;
/// use tokio::sync::oneshot::error::TryRecvError;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx) = oneshot::channel::<()>();
///
/// drop(tx);
///
/// match rx.try_recv() {
/// // The channe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | f70b9b84f7ac9c18b9b64ca52d3b4b594333b8e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f70b9b84f7ac9c18b9b64ca52d3b4b594333b8e3/tokio/src/sync/oneshot.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:1 | #![cfg_attr(not(feature = "sync"), allow(dead_code, unreachable_pub))]
//! A channel for sending a single message between asynchronous tasks.
use crate::loom::cell::UnsafeCell;
use crate::loom::sync::atomic::AtomicUsize;
use crate::loom::sync::Arc;
use std::fmt;
use std::future::Future;
use std::mem::MaybeUninit;
us... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 112e160b623e3bef1603bf522abbdaacbc6c94e5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/112e160b623e3bef1603bf522abbdaacbc6c94e5/tokio/src/sync/oneshot.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:2 | /// Error returned by the `try_recv` function on `Receiver`.
#[derive(Debug, Eq, PartialEq)]
pub enum TryRecvError {
/// The send half of the channel has not yet sent a value.
Empty,
/// The send half of the channel was dropped without sending a value.
Closed,
}
// ====... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 112e160b623e3bef1603bf522abbdaacbc6c94e5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/112e160b623e3bef1603bf522abbdaacbc6c94e5/tokio/src/sync/oneshot.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:3 | /// The value. This is set by `Sender` and read by `Receiver`. The state of
/// the cell is tracked by `state`.
value: UnsafeCell<Option<T>>,
/// The task to notify when the receiver drops without consuming the value.
tx_task: Task,
/// The task to notify when the value is sent.
rx_task: Task,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 112e160b623e3bef1603bf522abbdaacbc6c94e5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/112e160b623e3bef1603bf522abbdaacbc6c94e5/tokio/src/sync/oneshot.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:4 | });
}
}
#[derive(Clone, Copy)]
struct State(usize);
/// Create a new one-shot channel for sending single values across asynchronous
/// tasks.
///
/// The function returns separate "send" and "receive" handles. The `Sender`
/// handle is used by the producer to send the value. The `Receiver` handle is
/// used by... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 112e160b623e3bef1603bf522abbdaacbc6c94e5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/112e160b623e3bef1603bf522abbdaacbc6c94e5/tokio/src/sync/oneshot.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/oneshot.rs:5 | value: UnsafeCell::new(None),
tx_task: Task(UnsafeCell::new(MaybeUninit::uninit())),
rx_task: Task(UnsafeCell::new(MaybeUninit::uninit())),
});
let tx = Sender {
inner: Some(inner.clone()),
};
let rx = Receiver { inner: Some(inner) };
(tx, rx)
}
impl<T> Sender<T> {
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/oneshot.rs | MIT | 112e160b623e3bef1603bf522abbdaacbc6c94e5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/112e160b623e3bef1603bf522abbdaacbc6c94e5/tokio/src/sync/oneshot.rs | 161 | 220 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.