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/broadcast.rs:32 | Err(TryRecvError::Lagged(..)) => {}
// Can't be empty
Err(TryRecvError::Empty) => panic!("unexpected empty broadcast channel"),
}
}
}
}
impl<'a, T> Recv<'a, T> {
fn new(receiver: &'a mut Receiver<T>) -> Recv<'a, T> {
Recv {
receiver,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | dd9471d13a88733097c4643c2ea3a17fb8c238ae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dd9471d13a88733097c4643c2ea3a17fb8c238ae/tokio/src/sync/broadcast.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:33 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> {
let (receiver, waiter) = self.project();
let guard = match receiver.recv_ref(Some((waiter, cx.waker()))) {
Ok(value) => value,
Err(TryRecvError::Empty) => return Poll::Pending,
Err(Tr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | dd9471d13a88733097c4643c2ea3a17fb8c238ae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dd9471d13a88733097c4643c2ea3a17fb8c238ae/tokio/src/sync/broadcast.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34 | unsafe impl linked_list::Link for Waiter {
type Handle = NonNull<Waiter>;
type Target = Waiter;
fn as_raw(handle: &NonNull<Waiter>) -> NonNull<Waiter> {
*handle
}
unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> {
ptr
}
unsafe fn pointers(target: NonNull<Waiter>... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | dd9471d13a88733097c4643c2ea3a17fb8c238ae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dd9471d13a88733097c4643c2ea3a17fb8c238ae/tokio/src/sync/broadcast.rs | 1,321 | 1,369 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:30 | /// `Err(TryRecvError::Closed)` is returned when all `Sender` halves have
/// dropped, indicating that no further values can be sent on the channel.
///
/// If the [`Receiver`] handle falls behind, once the channel is full, newly
/// sent values will overwrite old values. At this point, a call to [`recv... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8497f379b5c57d37db82db5dd74833998ae847a1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8497f379b5c57d37db82db5dd74833998ae847a1/tokio/src/sync/broadcast.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:31 | let mut tail = self.shared.tail.lock();
tail.rx_cnt -= 1;
let until = tail.pos;
drop(tail);
while self.next < until {
match self.recv_ref(None) {
Ok(_) => {}
// The channel is closed
Err(TryRecvError::Closed) => break,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8497f379b5c57d37db82db5dd74833998ae847a1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8497f379b5c57d37db82db5dd74833998ae847a1/tokio/src/sync/broadcast.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:32 | let me = self.get_unchecked_mut();
(me.receiver, &me.waiter)
}
}
}
impl<'a, T> Future for Recv<'a, T>
where
T: Clone,
{
type Output = Result<T, RecvError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> {
let (receiver, waiter) = self.proj... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8497f379b5c57d37db82db5dd74833998ae847a1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8497f379b5c57d37db82db5dd74833998ae847a1/tokio/src/sync/broadcast.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:33 | // the list.
unsafe {
self.waiter.with_mut(|ptr| {
tail.waiters.remove((&mut *ptr).into());
});
}
}
}
}
/// # Safety
///
/// `Waiter` is forced to be !Unpin.
unsafe impl linked_list::Link for Waiter {
type Handle = NonNull<Wait... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8497f379b5c57d37db82db5dd74833998ae847a1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8497f379b5c57d37db82db5dd74833998ae847a1/tokio/src/sync/broadcast.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34 | }
impl<'a, T> RecvGuard<'a, T> {
fn clone_value(&self) -> Option<T>
where
T: Clone,
{
self.slot.val.with(|ptr| unsafe { (*ptr).clone() })
}
}
impl<'a, T> Drop for RecvGuard<'a, T> {
fn drop(&mut self) {
// Decrement the remaining counter
if 1 == self.slot.rem.fetch_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8497f379b5c57d37db82db5dd74833998ae847a1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8497f379b5c57d37db82db5dd74833998ae847a1/tokio/src/sync/broadcast.rs | 1,321 | 1,342 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:6 | /// ```
///
/// [`broadcast`]: crate::sync::broadcast
pub struct Receiver<T> {
/// State shared with all receivers and senders.
shared: Arc<Shared<T>>,
/// Next position to read from
next: u64,
}
pub mod error {
//! Broadcast error types
use std::fmt;
/// Error returned by from the [`sen... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8 | /// Attempting to receive again will return the oldest message still
/// retained by the channel.
///
/// Includes the number of skipped messages.
Lagged(u64),
}
impl fmt::Display for TryRecvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
m... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:9 | pos: u64,
/// Number of active receivers.
rx_cnt: usize,
/// True if the channel is closed.
closed: bool,
/// Receivers waiting for a value.
waiters: LinkedList<Waiter, <Waiter as linked_list::Link>::Target>,
}
/// Slot in the buffer.
struct Slot<T> {
/// Remaining number of receivers th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:10 | /// Intrusive linked-list pointers.
pointers: linked_list::Pointers<Waiter>,
/// Should not be `Unpin`.
_p: PhantomPinned,
}
generate_addr_of_methods! {
impl<> Waiter {
unsafe fn addr_of_pointers(self: NonNull<Self>) -> NonNull<linked_list::Pointers<Waiter>> {
&self.pointers
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12 | /// # Panics
///
/// This will panic if `capacity` is equal to `0` or larger
/// than `usize::MAX / 2`.
#[track_caller]
pub fn channel<T: Clone>(mut capacity: usize) -> (Sender<T>, Receiver<T>) {
assert!(capacity > 0, "capacity is empty");
assert!(capacity <= usize::MAX >> 1, "requested capacity too large");
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:14 | /// use tokio::sync::broadcast;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx1) = broadcast::channel(16);
/// let mut rx2 = tx.subscribe();
///
/// tokio::spawn(async move {
/// assert_eq!(rx1.recv().await.unwrap(), 10);
/// assert_eq!(r... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19 | /// ```
/// use tokio::sync::broadcast;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, _rx1) = broadcast::channel(16);
///
/// assert_eq!(1, tx.receiver_count());
///
/// let mut _rx2 = tx.subscribe();
///
/// assert_eq!(2, tx.receiver_count());
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20 | pub fn same_channel(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.shared, &other.shared)
}
fn close_channel(&self) {
let mut tail = self.shared.tail.lock();
tail.closed = true;
tail.notify_rx();
}
}
/// Create a new `Receiver` which reads starting from the tail.
fn new_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21 | }
}
}
impl<T> Clone for Sender<T> {
fn clone(&self) -> Sender<T> {
let shared = self.shared.clone();
shared.num_tx.fetch_add(1, SeqCst);
Sender { shared }
}
}
impl<T> Drop for Sender<T> {
fn drop(&mut self) {
if 1 == self.shared.num_tx.fetch_sub(1, SeqCst) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23 | /// assert_eq!(rx1.recv().await.unwrap(), 10);
/// assert_eq!(rx1.recv().await.unwrap(), 20);
/// assert!(rx1.is_empty());
/// }
/// ```
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Returns `true` if receivers belong to the same channel.
///
/// # Examp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24 | let mut slot = self.shared.buffer[idx].read().unwrap();
if slot.pos != self.next {
// Release the `slot` lock before attempting to acquire the `tail`
// lock. This is required because `send2` acquires the tail lock
// first followed by the slot lock. Acquiring the locks in r... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25 | // receipt of a new value.
match (*ptr).waker {
Some(ref w) if w.will_wake(waker) => {}
_ => {
(*ptr).waker = Some(waker.clone());
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29 | /// (one for closed, one for an empty buffer, one for a lagging receiver).
///
/// `Err(TryRecvError::Closed)` is returned when all `Sender` halves have
/// dropped, indicating that no further values can be sent on the channel.
///
/// If the [`Receiver`] handle falls behind, once the channel is ful... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:30 | impl<T> Drop for Receiver<T> {
fn drop(&mut self) {
let mut tail = self.shared.tail.lock();
tail.rx_cnt -= 1;
let until = tail.pos;
drop(tail);
while self.next < until {
match self.recv_ref(None) {
Ok(_) => {}
// The channel is c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:31 | // Safety: Receiver is Unpin
is_unpin::<&mut Receiver<T>>();
let me = self.get_unchecked_mut();
(me.receiver, &me.waiter)
}
}
}
impl<'a, T> Future for Recv<'a, T>
where
T: Clone,
{
type Output = Result<T, RecvError>;
fn poll(self: Pin<&mut Self>, cx: &mut C... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:32 | //
// safety: tail lock is held and the wait node is verified to be in
// the list.
unsafe {
self.waiter.with_mut(|ptr| {
tail.waiters.remove((&mut *ptr).into());
});
}
}
}
}
/// # Safety
///
/// `Waiter` is... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:33 | write!(fmt, "broadcast::Receiver")
}
}
impl<'a, T> RecvGuard<'a, T> {
fn clone_value(&self) -> Option<T>
where
T: Clone,
{
self.slot.val.with(|ptr| unsafe { (*ptr).clone() })
}
}
impl<'a, T> Drop for RecvGuard<'a, T> {
fn drop(&mut self) {
// Decrement the remaining cou... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 03912b9cf7141a5e27612a0b283d266637d2088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03912b9cf7141a5e27612a0b283d266637d2088f/tokio/src/sync/broadcast.rs | 1,281 | 1,304 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19 | /// ```
/// use tokio::sync::broadcast;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, _rx1) = broadcast::channel(16);
///
/// assert_eq!(1, tx.receiver_count());
///
/// let mut _rx2 = tx.subscribe();
///
/// assert_eq!(2, tx.receiver_count());
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | c89406965ffb4a64936d781c556a2c48855dfbdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c89406965ffb4a64936d781c556a2c48855dfbdb/tokio/src/sync/broadcast.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20 | drop(tail);
Receiver { shared, next }
}
impl Tail {
fn notify_rx(&mut self) {
while let Some(mut waiter) = self.waiters.pop_back() {
// Safety: `waiters` lock is still held.
let waiter = unsafe { waiter.as_mut() };
assert!(waiter.queued);
waiter.queued ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | c89406965ffb4a64936d781c556a2c48855dfbdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c89406965ffb4a64936d781c556a2c48855dfbdb/tokio/src/sync/broadcast.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22 | /// [`Receiver]: create::sync::broadcast::Receiver
///
/// # Examples
///
/// ```
/// use tokio::sync::broadcast;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx1) = broadcast::channel(16);
///
/// assert!(rx1.is_empty());
///
/// tx.send(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | c89406965ffb4a64936d781c556a2c48855dfbdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c89406965ffb4a64936d781c556a2c48855dfbdb/tokio/src/sync/broadcast.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23 | // order here would result in a potential deadlock: `recv_ref`
// acquires the `slot` lock and attempts to acquire the `tail` lock
// while `send2` acquired the `tail` lock and attempts to acquire
// the slot lock.
drop(slot);
let mut tail = self.shared.tail.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | c89406965ffb4a64936d781c556a2c48855dfbdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c89406965ffb4a64936d781c556a2c48855dfbdb/tokio/src/sync/broadcast.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24 | }
if !(*ptr).queued {
(*ptr).queued = true;
tail.waiters.push_front(NonNull::new_unchecked(&mut *ptr));
}
});
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | c89406965ffb4a64936d781c556a2c48855dfbdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c89406965ffb4a64936d781c556a2c48855dfbdb/tokio/src/sync/broadcast.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28 | /// sent values will overwrite old values. At this point, a call to [`recv`]
/// will return with `Err(TryRecvError::Lagged)` and the [`Receiver`]'s
/// internal cursor is updated to point to the oldest value still held by
/// the channel. A subsequent call to [`try_recv`] will return this value
/// **u... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | c89406965ffb4a64936d781c556a2c48855dfbdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c89406965ffb4a64936d781c556a2c48855dfbdb/tokio/src/sync/broadcast.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29 | drop(tail);
while self.next < until {
match self.recv_ref(None) {
Ok(_) => {}
// The channel is closed
Err(TryRecvError::Closed) => break,
// Ignore lagging, we will catch up
Err(TryRecvError::Lagged(..)) => {}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | c89406965ffb4a64936d781c556a2c48855dfbdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c89406965ffb4a64936d781c556a2c48855dfbdb/tokio/src/sync/broadcast.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:30 | }
}
impl<'a, T> Future for Recv<'a, T>
where
T: Clone,
{
type Output = Result<T, RecvError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> {
let (receiver, waiter) = self.project();
let guard = match receiver.recv_ref(Some((waiter, cx.waker()))) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | c89406965ffb4a64936d781c556a2c48855dfbdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c89406965ffb4a64936d781c556a2c48855dfbdb/tokio/src/sync/broadcast.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:31 | });
}
}
}
}
/// # Safety
///
/// `Waiter` is forced to be !Unpin.
unsafe impl linked_list::Link for Waiter {
type Handle = NonNull<Waiter>;
type Target = Waiter;
fn as_raw(handle: &NonNull<Waiter>) -> NonNull<Waiter> {
*handle
}
unsafe fn from_raw(ptr: NonNull<Wait... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | c89406965ffb4a64936d781c556a2c48855dfbdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c89406965ffb4a64936d781c556a2c48855dfbdb/tokio/src/sync/broadcast.rs | 1,201 | 1,258 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:32 | where
T: Clone,
{
self.slot.val.with(|ptr| unsafe { (*ptr).clone() })
}
}
impl<'a, T> Drop for RecvGuard<'a, T> {
fn drop(&mut self) {
// Decrement the remaining counter
if 1 == self.slot.rem.fetch_sub(1, SeqCst) {
// Safety: Last receiver, drop the value
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | c89406965ffb4a64936d781c556a2c48855dfbdb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c89406965ffb4a64936d781c556a2c48855dfbdb/tokio/src/sync/broadcast.rs | 1,241 | 1,258 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:6 | /// State shared with all receivers and senders.
shared: Arc<Shared<T>>,
/// Next position to read from
next: u64,
}
pub mod error {
//! Broadcast error types
use std::fmt;
/// Error returned by from the [`send`] function on a [`Sender`].
///
/// A **send** operation can only fail if... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:7 | /// The receiver lagged too far behind. Attempting to receive again will
/// return the oldest message still retained by the channel.
///
/// Includes the number of skipped messages.
Lagged(u64),
}
impl fmt::Display for RecvError {
fn fmt(&self, f: &mut fmt::Formatter<'_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8 | Lagged(u64),
}
impl fmt::Display for TryRecvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TryRecvError::Empty => write!(f, "channel empty"),
TryRecvError::Closed => write!(f, "channel closed"),
TryRecvError::L... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:9 | /// True if the channel is closed.
closed: bool,
/// Receivers waiting for a value.
waiters: LinkedList<Waiter, <Waiter as linked_list::Link>::Target>,
}
/// Slot in the buffer.
struct Slot<T> {
/// Remaining number of receivers that are expected to see this value.
///
/// When this goes to ze... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:10 | _p: PhantomPinned,
}
generate_addr_of_methods! {
impl<> Waiter {
unsafe fn addr_of_pointers(self: NonNull<Self>) -> NonNull<linked_list::Pointers<Waiter>> {
&self.pointers
}
}
}
struct RecvGuard<'a, T> {
slot: RwLockReadGuard<'a, Slot<T>>,
}
/// Receive a value future.
struct ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:11 | /// If all [`Receiver`] handles are dropped, the `send` method will return a
/// [`SendError`]. Similarly, if all [`Sender`] handles are dropped, the [`recv`]
/// method will return a [`RecvError`].
///
/// [`Sender`]: crate::sync::broadcast::Sender
/// [`Sender::subscribe`]: crate::sync::broadcast::Sender::subscribe
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12 | #[track_caller]
pub fn channel<T: Clone>(mut capacity: usize) -> (Sender<T>, Receiver<T>) {
assert!(capacity > 0, "capacity is empty");
assert!(capacity <= usize::MAX >> 1, "requested capacity too large");
// Round to a power of two
capacity = capacity.next_power_of_two();
let mut buffer = Vec::wi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:14 | /// let (tx, mut rx1) = broadcast::channel(16);
/// let mut rx2 = tx.subscribe();
///
/// tokio::spawn(async move {
/// assert_eq!(rx1.recv().await.unwrap(), 10);
/// assert_eq!(rx1.recv().await.unwrap(), 20);
/// });
///
/// tokio::spawn(async move {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16 | pub fn subscribe(&self) -> Receiver<T> {
let shared = self.shared.clone();
new_receiver(shared)
}
/// Returns the number of queued values.
///
/// A value is queued until it has either been seen by all receivers that were alive at the time
/// it was sent, or has been evicted from t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17 | /// }
/// ```
pub fn len(&self) -> usize {
let tail = self.shared.tail.lock();
let base_idx = (tail.pos & self.shared.mask as u64) as usize;
let mut low = 0;
let mut high = self.shared.buffer.len();
while low < high {
let mid = low + (high - low) / 2;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19 | /// async fn main() {
/// let (tx, _rx1) = broadcast::channel(16);
///
/// assert_eq!(1, tx.receiver_count());
///
/// let mut _rx2 = tx.subscribe();
///
/// assert_eq!(2, tx.receiver_count());
///
/// tx.send(10).unwrap();
/// }
/// ```
pub fn receive... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20 | }
impl Tail {
fn notify_rx(&mut self) {
while let Some(mut waiter) = self.waiters.pop_back() {
// Safety: `waiters` lock is still held.
let waiter = unsafe { waiter.as_mut() };
assert!(waiter.queued);
waiter.queued = false;
let waker = waiter.wa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22 | /// ```
/// use tokio::sync::broadcast;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx1) = broadcast::channel(16);
///
/// assert!(rx1.is_empty());
///
/// tx.send(10).unwrap();
/// tx.send(20).unwrap();
///
/// assert!(!rx1.is_empty(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23 | drop(slot);
let mut tail = self.shared.tail.lock();
// Acquire slot lock again
slot = self.shared.buffer[idx].read().unwrap();
// Make sure the position did not change. This could happen in the
// unlikely event that the buffer is wrapped between dropping t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24 | tail.waiters.push_front(NonNull::new_unchecked(&mut *ptr));
}
});
}
}
return Err(TryRecvError::Empty);
}
// At this point, the receiver has lagged behind the send... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28 | /// **unless** it has been since overwritten. If there are no values to
/// receive, `Err(TryRecvError::Empty)` is returned.
///
/// [`recv`]: crate::sync::broadcast::Receiver::recv
/// [`try_recv`]: crate::sync::broadcast::Receiver::try_recv
/// [`Receiver`]: crate::sync::broadcast::Receiver
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29 | match self.recv_ref(None) {
Ok(_) => {}
// The channel is closed
Err(TryRecvError::Closed) => break,
// Ignore lagging, we will catch up
Err(TryRecvError::Lagged(..)) => {}
// Can't be empty
Err(TryRecvError:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:30 | where
T: Clone,
{
type Output = Result<T, RecvError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> {
let (receiver, waiter) = self.project();
let guard = match receiver.recv_ref(Some((waiter, cx.waker()))) {
Ok(value) => value,
E... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:31 | }
/// # Safety
///
/// `Waiter` is forced to be !Unpin.
unsafe impl linked_list::Link for Waiter {
type Handle = NonNull<Waiter>;
type Target = Waiter;
fn as_raw(handle: &NonNull<Waiter>) -> NonNull<Waiter> {
*handle
}
unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 1,201 | 1,254 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:32 | }
}
impl<'a, T> Drop for RecvGuard<'a, T> {
fn drop(&mut self) {
// Decrement the remaining counter
if 1 == self.slot.rem.fetch_sub(1, SeqCst) {
// Safety: Last receiver, drop the value
self.slot.val.with_mut(|ptr| unsafe { *ptr = None });
}
}
}
fn is_unpin<T: U... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eca24068f718f3edbdbb6615fb1523b4578a7ecb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eca24068f718f3edbdbb6615fb1523b4578a7ecb/tokio/src/sync/broadcast.rs | 1,241 | 1,254 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16 | pub fn subscribe(&self) -> Receiver<T> {
let shared = self.shared.clone();
new_receiver(shared)
}
/// Returns the number of active receivers
///
/// An active receiver is a [`Receiver`] handle returned from [`channel`] or
/// [`subscribe`]. These are the handles that will receive va... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8d58dc85b5fbd7509fb4b44874043565e69f9dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8d58dc85b5fbd7509fb4b44874043565e69f9dee/tokio/src/sync/broadcast.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17 | /// ```
pub fn receiver_count(&self) -> usize {
let tail = self.shared.tail.lock();
tail.rx_cnt
}
fn close_channel(&self) {
let mut tail = self.shared.tail.lock();
tail.closed = true;
tail.notify_rx();
}
}
/// Create a new `Receiver` which reads starting from t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8d58dc85b5fbd7509fb4b44874043565e69f9dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8d58dc85b5fbd7509fb4b44874043565e69f9dee/tokio/src/sync/broadcast.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18 | let waker = waiter.waker.take().unwrap();
waker.wake();
}
}
}
impl<T> Clone for Sender<T> {
fn clone(&self) -> Sender<T> {
let shared = self.shared.clone();
shared.num_tx.fetch_add(1, SeqCst);
Sender { shared }
}
}
impl<T> Drop for Sender<T> {
fn drop(&mut ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8d58dc85b5fbd7509fb4b44874043565e69f9dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8d58dc85b5fbd7509fb4b44874043565e69f9dee/tokio/src/sync/broadcast.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20 | ///
/// assert!(!rx1.is_empty());
/// assert_eq!(rx1.recv().await.unwrap(), 10);
/// assert_eq!(rx1.recv().await.unwrap(), 20);
/// assert!(rx1.is_empty());
/// }
/// ```
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Locks the next value if there is ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8d58dc85b5fbd7509fb4b44874043565e69f9dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8d58dc85b5fbd7509fb4b44874043565e69f9dee/tokio/src/sync/broadcast.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21 | let next_pos = slot.pos.wrapping_add(self.shared.buffer.len() as u64);
if next_pos == self.next {
// At this point the channel is empty for *this* receiver. If
// it's been closed, then that's what we return, otherwise we
// set a waker and re... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8d58dc85b5fbd7509fb4b44874043565e69f9dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8d58dc85b5fbd7509fb4b44874043565e69f9dee/tokio/src/sync/broadcast.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22 | // catch up by skipping dropped messages and setting the
// internal cursor to the **oldest** message stored by the
// channel.
let next = tail.pos.wrapping_sub(self.shared.buffer.len() as u64);
let missed = next.wrapping_sub(self.next);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8d58dc85b5fbd7509fb4b44874043565e69f9dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8d58dc85b5fbd7509fb4b44874043565e69f9dee/tokio/src/sync/broadcast.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26 | ///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx) = broadcast::channel(16);
///
/// assert!(rx.try_recv().is_err());
///
/// tx.send(10).unwrap();
///
/// let value = rx.try_recv().unwrap();
/// assert_eq!(10, value);
/// }
/// ```
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8d58dc85b5fbd7509fb4b44874043565e69f9dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8d58dc85b5fbd7509fb4b44874043565e69f9dee/tokio/src/sync/broadcast.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27 | }
impl<'a, T> Recv<'a, T> {
fn new(receiver: &'a mut Receiver<T>) -> Recv<'a, T> {
Recv {
receiver,
waiter: UnsafeCell::new(Waiter {
queued: false,
waker: None,
pointers: linked_list::Pointers::new(),
_p: PhantomPinned,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8d58dc85b5fbd7509fb4b44874043565e69f9dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8d58dc85b5fbd7509fb4b44874043565e69f9dee/tokio/src/sync/broadcast.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28 | Err(TryRecvError::Lagged(n)) => return Poll::Ready(Err(RecvError::Lagged(n))),
Err(TryRecvError::Closed) => return Poll::Ready(Err(RecvError::Closed)),
};
Poll::Ready(guard.clone_value().ok_or(RecvError::Closed))
}
}
impl<'a, T> Drop for Recv<'a, T> {
fn drop(&mut self) {
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8d58dc85b5fbd7509fb4b44874043565e69f9dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8d58dc85b5fbd7509fb4b44874043565e69f9dee/tokio/src/sync/broadcast.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29 | }
unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> {
ptr
}
unsafe fn pointers(target: NonNull<Waiter>) -> NonNull<linked_list::Pointers<Waiter>> {
Waiter::addr_of_pointers(target)
}
}
impl<T> fmt::Debug for Sender<T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 8d58dc85b5fbd7509fb4b44874043565e69f9dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8d58dc85b5fbd7509fb4b44874043565e69f9dee/tokio/src/sync/broadcast.rs | 1,121 | 1,163 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:6 | /// Next position to read from
next: u64,
}
pub mod error {
//! Broadcast error types
use std::fmt;
/// Error returned by from the [`send`] function on a [`Sender`].
///
/// A **send** operation can only fail if there are no active receivers,
/// implying that the message could never be r... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:7 | ///
/// Includes the number of skipped messages.
Lagged(u64),
}
impl fmt::Display for RecvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RecvError::Closed => write!(f, "channel closed"),
RecvError::Lagged(amt) ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8 | impl fmt::Display for TryRecvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TryRecvError::Empty => write!(f, "channel empty"),
TryRecvError::Closed => write!(f, "channel closed"),
TryRecvError::Lagged(amt) => write!(f, ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:9 | /// Receivers waiting for a value.
waiters: LinkedList<Waiter, <Waiter as linked_list::Link>::Target>,
}
/// Slot in the buffer.
struct Slot<T> {
/// Remaining number of receivers that are expected to see this value.
///
/// When this goes to zero, the value is released.
///
/// An atomic is us... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:10 | generate_addr_of_methods! {
impl<> Waiter {
unsafe fn addr_of_pointers(self: NonNull<Self>) -> NonNull<linked_list::Pointers<Waiter>> {
&self.pointers
}
}
}
struct RecvGuard<'a, T> {
slot: RwLockReadGuard<'a, Slot<T>>,
}
/// Receive a value future.
struct Recv<'a, T> {
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:11 | ///
/// [`Sender`]: crate::sync::broadcast::Sender
/// [`Sender::subscribe`]: crate::sync::broadcast::Sender::subscribe
/// [`Receiver`]: crate::sync::broadcast::Receiver
/// [`recv`]: crate::sync::broadcast::Receiver::recv
/// [`SendError`]: crate::sync::broadcast::error::SendError
/// [`RecvError`]: crate::sync::broa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12 | assert!(capacity <= usize::MAX >> 1, "requested capacity too large");
// Round to a power of two
capacity = capacity.next_power_of_two();
let mut buffer = Vec::with_capacity(capacity);
for i in 0..capacity {
buffer.push(RwLock::new(Slot {
rem: AtomicUsize::new(0),
pos:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:14 | /// tokio::spawn(async move {
/// assert_eq!(rx1.recv().await.unwrap(), 10);
/// assert_eq!(rx1.recv().await.unwrap(), 20);
/// });
///
/// tokio::spawn(async move {
/// assert_eq!(rx2.recv().await.unwrap(), 10);
/// assert_eq!(rx2.recv().await.unw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16 | }
/// Returns the number of active receivers
///
/// An active receiver is a [`Receiver`] handle returned from [`channel`] or
/// [`subscribe`]. These are the handles that will receive values sent on
/// this [`Sender`].
///
/// # Note
///
/// It is not guaranteed that a sent messag... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17 | tail.rx_cnt
}
fn close_channel(&self) {
let mut tail = self.shared.tail.lock();
tail.closed = true;
tail.notify_rx();
}
}
/// Create a new `Receiver` which reads starting from the tail.
fn new_receiver<T>(shared: Arc<Shared<T>>) -> Receiver<T> {
let mut tail = shared.tail.lock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18 | }
}
impl<T> Clone for Sender<T> {
fn clone(&self) -> Sender<T> {
let shared = self.shared.clone();
shared.num_tx.fetch_add(1, SeqCst);
Sender { shared }
}
}
impl<T> Drop for Sender<T> {
fn drop(&mut self) {
if 1 == self.shared.num_tx.fetch_sub(1, SeqCst) {
self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19 | /// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx1) = broadcast::channel(16);
///
/// tx.send(10).unwrap();
/// tx.send(20).unwrap();
///
/// assert_eq!(rx1.len(), 2);
/// assert_eq!(rx1.recv().await.unwrap(), 10);
/// assert_eq!(rx1.len(), 1);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20 | /// assert_eq!(rx1.recv().await.unwrap(), 20);
/// assert!(rx1.is_empty());
/// }
/// ```
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Locks the next value if there is one.
fn recv_ref(
&mut self,
waiter: Option<(&UnsafeCell<Waiter>, &Waker)>,
)... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21 | // At this point the channel is empty for *this* receiver. If
// it's been closed, then that's what we return, otherwise we
// set a waker and return empty.
if tail.closed {
return Err(TryRecvError::Closed);
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22 | let next = tail.pos.wrapping_sub(self.shared.buffer.len() as u64);
let missed = next.wrapping_sub(self.next);
drop(tail);
// The receiver is slow but no values have been missed
if missed == 0 {
self.next = self.next.wrapping_add(1);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26 | /// let (tx, mut rx) = broadcast::channel(16);
///
/// assert!(rx.try_recv().is_err());
///
/// tx.send(10).unwrap();
///
/// let value = rx.try_recv().unwrap();
/// assert_eq!(10, value);
/// }
/// ```
pub fn try_recv(&mut self) -> Result<T, TryRecvError> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27 | fn new(receiver: &'a mut Receiver<T>) -> Recv<'a, T> {
Recv {
receiver,
waiter: UnsafeCell::new(Waiter {
queued: false,
waker: None,
pointers: linked_list::Pointers::new(),
_p: PhantomPinned,
}),
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28 | Poll::Ready(guard.clone_value().ok_or(RecvError::Closed))
}
}
impl<'a, T> Drop for Recv<'a, T> {
fn drop(&mut self) {
// Acquire the tail lock. This is required for safety before accessing
// the waiter node.
let mut tail = self.receiver.shared.tail.lock();
// safety: tail lock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29 | ptr
}
unsafe fn pointers(target: NonNull<Waiter>) -> NonNull<linked_list::Pointers<Waiter>> {
Waiter::addr_of_pointers(target)
}
}
impl<T> fmt::Debug for Sender<T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "broadcast::Sender")
}
}
impl<T> fmt::Debu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/src/sync/broadcast.rs | 1,121 | 1,160 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:6 | /// Next position to read from
next: u64,
}
pub mod error {
//! Broadcast error types
use std::fmt;
/// Error returned by from the [`send`] function on a [`Sender`].
///
/// A **send** operation can only fail if there are no active receivers,
/// implying that the message could never be r... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 9d9488db67136651f85d839efcb5f61aba8531c9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d9488db67136651f85d839efcb5f61aba8531c9/tokio/src/sync/broadcast.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:7 | ///
/// Includes the number of skipped messages.
Lagged(u64),
}
impl fmt::Display for RecvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RecvError::Closed => write!(f, "channel closed"),
RecvError::Lagged(amt) ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 9d9488db67136651f85d839efcb5f61aba8531c9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d9488db67136651f85d839efcb5f61aba8531c9/tokio/src/sync/broadcast.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8 | impl fmt::Display for TryRecvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TryRecvError::Empty => write!(f, "channel empty"),
TryRecvError::Closed => write!(f, "channel closed"),
TryRecvError::Lagged(amt) => write!(f, ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:9 | /// Receivers waiting for a value.
waiters: LinkedList<Waiter, <Waiter as linked_list::Link>::Target>,
}
/// Slot in the buffer.
struct Slot<T> {
/// Remaining number of receivers that are expected to see this value.
///
/// When this goes to zero, the value is released.
///
/// An atomic is us... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:11 | /// If all [`Receiver`] handles are dropped, the `send` method will return a
/// [`SendError`]. Similarly, if all [`Sender`] handles are dropped, the [`recv`]
/// method will return a [`RecvError`].
///
/// [`Sender`]: crate::sync::broadcast::Sender
/// [`Sender::subscribe`]: crate::sync::broadcast::Sender::subscribe
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12 | #[track_caller]
pub fn channel<T: Clone>(mut capacity: usize) -> (Sender<T>, Receiver<T>) {
assert!(capacity > 0, "capacity is empty");
assert!(capacity <= usize::MAX >> 1, "requested capacity too large");
// Round to a power of two
capacity = capacity.next_power_of_two();
let mut buffer = Vec::wi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16 | /// let mut _rx2 = tx.subscribe();
///
/// assert_eq!(2, tx.receiver_count());
///
/// tx.send(10).unwrap();
/// }
/// ```
pub fn receiver_count(&self) -> usize {
let tail = self.shared.tail.lock();
tail.rx_cnt
}
fn send2(&self, value: Option<T>) -> Resul... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17 | } else {
slot.val.with_mut(|ptr| unsafe { *ptr = value });
}
// Release the slot lock before notifying the receivers.
drop(slot);
tail.notify_rx();
// Release the mutex. This must happen after the slot lock is released,
// otherwise the writer lock bit coul... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18 | assert!(waiter.queued);
waiter.queued = false;
let waker = waiter.waker.take().unwrap();
waker.wake();
}
}
}
impl<T> Clone for Sender<T> {
fn clone(&self) -> Sender<T> {
let shared = self.shared.clone();
shared.num_tx.fetch_add(1, SeqCst);
S... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20 | /// assert!(rx1.is_empty());
///
/// tx.send(10).unwrap();
/// tx.send(20).unwrap();
///
/// assert!(!rx1.is_empty());
/// assert_eq!(rx1.recv().await.unwrap(), 10);
/// assert_eq!(rx1.recv().await.unwrap(), 20);
/// assert!(rx1.is_empty());
/// }
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21 | // the slot lock.
drop(slot);
let mut tail = self.shared.tail.lock();
// Acquire slot lock again
slot = self.shared.buffer[idx].read().unwrap();
// Make sure the position did not change. This could happen in the
// unlikely event that the buffer... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22 | return Err(TryRecvError::Empty);
}
// At this point, the receiver has lagged behind the sender by
// more than the channel capacity. The receiver will attempt to
// catch up by skipping dropped messages and setting the
// internal cursor t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26 | /// await on a receiver.
///
/// Compared with [`recv`], this function has three failure cases instead of two
/// (one for closed, one for an empty buffer, one for a lagging receiver).
///
/// `Err(TryRecvError::Closed)` is returned when all `Sender` halves have
/// dropped, indicating that no f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27 | }
}
impl<T> Drop for Receiver<T> {
fn drop(&mut self) {
let mut tail = self.shared.tail.lock();
tail.rx_cnt -= 1;
let until = tail.pos;
drop(tail);
while self.next < until {
match self.recv_ref(None) {
Ok(_) => {}
// The channel... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28 | /// as a custom drop implementation is needed.
fn project(self: Pin<&mut Self>) -> (&mut Receiver<T>, &UnsafeCell<Waiter>) {
unsafe {
// Safety: Receiver is Unpin
is_unpin::<&mut Receiver<T>>();
let me = self.get_unchecked_mut();
(me.receiver, &me.waiter)
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29 | if queued {
// Remove the node
//
// safety: tail lock is held and the wait node is verified to be in
// the list.
unsafe {
self.waiter.with_mut(|ptr| {
tail.waiters.remove((&mut *ptr).into());
});
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6f048ca954aa5f285f1cf6310d447e7c079c1c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f048ca954aa5f285f1cf6310d447e7c079c1c3d/tokio/src/sync/broadcast.rs | 1,121 | 1,180 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.