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:18 | ///
/// // The len is still 3 since rx2 hasn't seen the first value yet.
/// assert_eq!(tx.len(), 3);
///
/// rx2.recv().await.unwrap();
///
/// assert_eq!(tx.len(), 2);
/// }
/// ```
pub fn len(&self) -> usize {
let tail = self.shared.tail.lock();
le... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f5ca423bf1587a17f9c0f02b75d6ad5860b9c029 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f5ca423bf1587a17f9c0f02b75d6ad5860b9c029/tokio/src/sync/broadcast.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27 | ///
/// assert!(rx.same_channel(&rx2));
///
/// let (_tx3, rx3) = broadcast::channel::<()>(16);
///
/// assert!(!rx3.same_channel(&rx2));
/// }
/// ```
pub fn same_channel(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.shared, &other.shared)
}
/// Locks the... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f5ca423bf1587a17f9c0f02b75d6ad5860b9c029 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f5ca423bf1587a17f9c0f02b75d6ad5860b9c029/tokio/src/sync/broadcast.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34 | ///
/// # Examples
/// ```
/// use std::thread;
/// use tokio::sync::broadcast;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx) = broadcast::channel(16);
///
/// let sync_code = thread::spawn(move || {
/// assert_eq!(rx.blocking_recv(), Ok(10... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f5ca423bf1587a17f9c0f02b75d6ad5860b9c029 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f5ca423bf1587a17f9c0f02b75d6ad5860b9c029/tokio/src/sync/broadcast.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:35 | 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,
waiter: UnsafeCell::new(Waiter {
queued: AtomicBool::new(false)... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f5ca423bf1587a17f9c0f02b75d6ad5860b9c029 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f5ca423bf1587a17f9c0f02b75d6ad5860b9c029/tokio/src/sync/broadcast.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:36 | 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(TryRecvError::Lagged(n)) => return Poll::Ready(Err(RecvError::Lagged(n))),
Err(Try... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f5ca423bf1587a17f9c0f02b75d6ad5860b9c029 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f5ca423bf1587a17f9c0f02b75d6ad5860b9c029/tokio/src/sync/broadcast.rs | 1,401 | 1,460 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:37 | // 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());
});
}
}
}
}
}
/// # Saf... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f5ca423bf1587a17f9c0f02b75d6ad5860b9c029 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f5ca423bf1587a17f9c0f02b75d6ad5860b9c029/tokio/src/sync/broadcast.rs | 1,441 | 1,500 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:38 | 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 | f5ca423bf1587a17f9c0f02b75d6ad5860b9c029 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f5ca423bf1587a17f9c0f02b75d6ad5860b9c029/tokio/src/sync/broadcast.rs | 1,481 | 1,540 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:4 | use crate::loom::sync::{Arc, Mutex, MutexGuard, RwLock, RwLockReadGuard};
use crate::util::linked_list::{self, GuardedLinkedList, LinkedList};
use crate::util::WakeList;
use std::fmt;
use std::future::Future;
use std::marker::PhantomPinned;
use std::pin::Pin;
use std::ptr::NonNull;
use std::sync::atomic::Ordering::Seq... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:9 | /// Next position to write to.
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> {
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/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,
}
impl Waiter {
fn new() -> Self {
Self {
queued: false,
waker: None,
pointers: linked_list::Pointers::new(),
_p: PhantomPi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22 | fn drop(&mut self) {
// If the list is not empty, we unlink all waiters from it.
// We do not wake the waiters to avoid double panics.
if !self.is_empty {
let _lock_guard = self.shared.tail.lock();
while self.list.pop_back().is_some() {}
}
}
}
impl<'a, T> Wai... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23 | // It is critical for `GuardedLinkedList` safety that the guard node is
// pinned in memory and is not dropped until the guarded list is dropped.
let guard = Waiter::new();
pin!(guard);
// We move all waiters to a secondary list. It uses a `GuardedLinkedList`
// underneath to al... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24 | // some waiters may remove themselves from the list and new waiters
// may be added. This is fine since at worst we will unnecessarily
// wake up waiters which will then queue themselves again.
wakers.wake_all();
// Acquire the lock again.
tail = self.tail.l... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27 | /// ```
pub fn same_channel(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.shared, &other.shared)
}
/// Locks the next value if there is one.
fn recv_ref(
&mut self,
waiter: Option<(&UnsafeCell<Waiter>, &Waker)>,
) -> Result<RecvGuard<'_, T>, TryRecvError> {
let id... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28 | // 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);
}
// Store the waker
if let Some((waiter, waker))... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29 | }
// 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 to the **oldest** message stored by the
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:33 | /// # Examples
///
/// ```
/// use tokio::sync::broadcast;
///
/// #[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_rec... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34 | /// });
///
/// let _ = tx.send(10);
/// sync_code.join().unwrap();
/// }
/// ```
pub fn blocking_recv(&mut self) -> Result<T, RecvError> {
crate::future::block_on(self.recv())
}
}
impl<T> Drop for Receiver<T> {
fn drop(&mut self) {
let mut tail = self.shared... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:35 | waker: None,
pointers: linked_list::Pointers::new(),
_p: PhantomPinned,
}),
}
}
/// A custom `project` implementation is used in place of `pin-project-lite`
/// as a custom drop implementation is needed.
fn project(self: Pin<&mut Self>) -> (&mut Recei... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:36 | }
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 is held
let queued = self.waiter.with(|ptr| unsafe { (*... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 1,401 | 1,460 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:37 | 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::Debug for Receiver<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 1,441 | 1,500 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:38 | mod tests {
use super::*;
#[test]
fn receiver_count_on_sender_constructor() {
let sender = Sender::<i32>::new(16);
assert_eq!(sender.receiver_count(), 0);
let rx_1 = sender.subscribe();
assert_eq!(sender.receiver_count(), 1);
let rx_2 = rx_1.resubscribe();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3991f9f9a4967b76b6850df0dce11521978ec043 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3991f9f9a4967b76b6850df0dce11521978ec043/tokio/src/sync/broadcast.rs | 1,481 | 1,515 |
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | bc48a6fa8d29f25641ecaaf50070cebcc43b74bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/bc48a6fa8d29f25641ecaaf50070cebcc43b74bc/tokio/src/sync/broadcast.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12 | /// 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.unwrap(), 20);
/// });
///
/// tx.send(10).unwrap();
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/broadcast.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13 | /// [`broadcast`]: crate::sync::broadcast
/// [`broadcast::channel`]: crate::sync::broadcast
#[track_caller]
pub fn new(capacity: usize) -> Self {
// SAFETY: We don't create extra receivers, so there are 0.
unsafe { Self::new_with_receiver_count(0, capacity) }
}
/// Creates the send... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/sync/broadcast.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8 | /// The receiver lagged too far behind and has been forcibly disconnected.
/// 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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f306bd02c3e8bbc4b6e79e68cb547709c5c5596b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f306bd02c3e8bbc4b6e79e68cb547709c5c5596b/tokio/src/sync/broadcast.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20 | ///
/// # Examples
///
/// ```
/// 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();
///
/// asse... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f306bd02c3e8bbc4b6e79e68cb547709c5c5596b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f306bd02c3e8bbc4b6e79e68cb547709c5c5596b/tokio/src/sync/broadcast.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21 | /// assert!(!tx3.same_channel(&tx2));
/// }
/// ```
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;
self.shared.notify_rx(tail);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f306bd02c3e8bbc4b6e79e68cb547709c5c5596b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f306bd02c3e8bbc4b6e79e68cb547709c5c5596b/tokio/src/sync/broadcast.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22 | impl<'a, T> Drop for WaitersList<'a, T> {
fn drop(&mut self) {
// If the list is not empty, we unlink all waiters from it.
// We do not wake the waiters to avoid double panics.
if !self.is_empty {
let _lock_guard = self.shared.tail.lock();
while self.list.pop_back().i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f306bd02c3e8bbc4b6e79e68cb547709c5c5596b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f306bd02c3e8bbc4b6e79e68cb547709c5c5596b/tokio/src/sync/broadcast.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23 | impl<T> Shared<T> {
fn notify_rx<'a, 'b: 'a>(&'b self, mut tail: MutexGuard<'a, Tail>) {
// It is critical for `GuardedLinkedList` safety that the guard node is
// pinned in memory and is not dropped until the guarded list is dropped.
let guard = Waiter::new();
pin!(guard);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f306bd02c3e8bbc4b6e79e68cb547709c5c5596b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f306bd02c3e8bbc4b6e79e68cb547709c5c5596b/tokio/src/sync/broadcast.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24 | // Before we acquire the lock again all sorts of things can happen:
// some waiters may remove themselves from the list and new waiters
// may be added. This is fine since at worst we will unnecessarily
// wake up waiters which will then queue themselves again.
wakers.wa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f306bd02c3e8bbc4b6e79e68cb547709c5c5596b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f306bd02c3e8bbc4b6e79e68cb547709c5c5596b/tokio/src/sync/broadcast.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27 | /// assert!(!rx3.same_channel(&rx2));
/// }
/// ```
pub fn same_channel(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.shared, &other.shared)
}
/// 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 | f306bd02c3e8bbc4b6e79e68cb547709c5c5596b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f306bd02c3e8bbc4b6e79e68cb547709c5c5596b/tokio/src/sync/broadcast.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28 | 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 return empty.
if tail.closed {
return Err(TryR... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f306bd02c3e8bbc4b6e79e68cb547709c5c5596b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f306bd02c3e8bbc4b6e79e68cb547709c5c5596b/tokio/src/sync/broadcast.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29 | 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 | f306bd02c3e8bbc4b6e79e68cb547709c5c5596b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f306bd02c3e8bbc4b6e79e68cb547709c5c5596b/tokio/src/sync/broadcast.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34 | /// let sync_code = thread::spawn(move || {
/// assert_eq!(rx.blocking_recv(), Ok(10));
/// });
///
/// let _ = tx.send(10);
/// sync_code.join().unwrap();
/// }
/// ```
pub fn blocking_recv(&mut self) -> Result<T, RecvError> {
crate::future::block_on(self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f306bd02c3e8bbc4b6e79e68cb547709c5c5596b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f306bd02c3e8bbc4b6e79e68cb547709c5c5596b/tokio/src/sync/broadcast.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:35 | waiter: UnsafeCell::new(Waiter {
queued: false,
waker: None,
pointers: linked_list::Pointers::new(),
_p: PhantomPinned,
}),
}
}
/// A custom `project` implementation is used in place of `pin-project-lite`
/// as a custom dr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f306bd02c3e8bbc4b6e79e68cb547709c5c5596b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f306bd02c3e8bbc4b6e79e68cb547709c5c5596b/tokio/src/sync/broadcast.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:36 | 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 | f306bd02c3e8bbc4b6e79e68cb547709c5c5596b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f306bd02c3e8bbc4b6e79e68cb547709c5c5596b/tokio/src/sync/broadcast.rs | 1,401 | 1,460 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:37 | }
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::Debug for Re... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | f306bd02c3e8bbc4b6e79e68cb547709c5c5596b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f306bd02c3e8bbc4b6e79e68cb547709c5c5596b/tokio/src/sync/broadcast.rs | 1,441 | 1,500 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:33 | /// [`Receiver`]: crate::sync::broadcast::Receiver
///
/// # Examples
///
/// ```
/// use tokio::sync::broadcast;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx) = broadcast::channel(16);
///
/// assert!(rx.try_recv().is_err());
///
/// t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eaba9712e8a4b35a1a2cdeb3b27845d6239c12ea | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eaba9712e8a4b35a1a2cdeb3b27845d6239c12ea/tokio/src/sync/broadcast.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34 | /// let sync_code = thread::spawn(move || {
/// assert_eq!(rx.blocking_recv(), Ok(10));
/// });
///
/// let _ = tx.send(10);
/// sync_code.join().unwrap();
/// }
pub fn blocking_recv(&mut self) -> Result<T, RecvError> {
crate::future::block_on(self.recv())
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eaba9712e8a4b35a1a2cdeb3b27845d6239c12ea | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eaba9712e8a4b35a1a2cdeb3b27845d6239c12ea/tokio/src/sync/broadcast.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:35 | queued: false,
waker: None,
pointers: linked_list::Pointers::new(),
_p: PhantomPinned,
}),
}
}
/// A custom `project` implementation is used in place of `pin-project-lite`
/// as a custom drop implementation is needed.
fn project(self:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eaba9712e8a4b35a1a2cdeb3b27845d6239c12ea | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eaba9712e8a4b35a1a2cdeb3b27845d6239c12ea/tokio/src/sync/broadcast.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:36 | }
}
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 is held
let queued = self.waiter.with(|ptr| unsafe { ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eaba9712e8a4b35a1a2cdeb3b27845d6239c12ea | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eaba9712e8a4b35a1a2cdeb3b27845d6239c12ea/tokio/src/sync/broadcast.rs | 1,401 | 1,460 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:37 | 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::Debug for Receiver<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | eaba9712e8a4b35a1a2cdeb3b27845d6239c12ea | github | async-runtime | https://github.com/tokio-rs/tokio/blob/eaba9712e8a4b35a1a2cdeb3b27845d6239c12ea/tokio/src/sync/broadcast.rs | 1,441 | 1,500 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:10 | /// Intrusive linked-list pointers.
pointers: linked_list::Pointers<Waiter>,
/// Should not be `Unpin`.
_p: PhantomPinned,
}
impl Waiter {
fn new() -> Self {
Self {
queued: false,
waker: None,
pointers: linked_list::Pointers::new(),
_p: PhantomPi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12 | /// });
///
/// tokio::spawn(async move {
/// assert_eq!(rx2.recv().await.unwrap(), 10);
/// assert_eq!(rx2.recv().await.unwrap(), 20);
/// });
///
/// tx.send(10).unwrap();
/// tx.send(20).unwrap();
/// }
/// ```
///
/// # Panics
///
/// This will panic if `capacity` is equal to `0`... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13 | #[track_caller]
pub fn new(capacity: usize) -> Self {
// SAFETY: We don't create extra receivers, so there are 0.
unsafe { Self::new_with_receiver_count(0, capacity) }
}
/// Creates the sending-half of the [`broadcast`](self) channel, and provide the receiver
/// count.
///
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15 | /// # Examples
///
/// ```
/// 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.unwr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17 | ///
/// let value = rx.recv().await.unwrap();
/// assert_eq!(20, value);
/// }
/// ```
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 i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18 | /// assert_eq!(tx.len(), 3);
///
/// rx2.recv().await.unwrap();
///
/// assert_eq!(tx.len(), 2);
/// }
/// ```
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;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20 | ///
/// ```
/// 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 | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21 | /// ```
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;
self.shared.notify_rx(tail);
}
}
/// Create a new `Receiver` which reads starting... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:33 | /// # Examples
///
/// ```
/// use tokio::sync::broadcast;
///
/// #[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_rec... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34 | /// });
///
/// let _ = tx.send(10);
/// sync_code.join().unwrap();
/// }
pub fn blocking_recv(&mut self) -> Result<T, RecvError> {
crate::future::block_on(self.recv())
}
}
impl<T> Drop for Receiver<T> {
fn drop(&mut self) {
let mut tail = self.shared.tail.lock()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:35 | pointers: linked_list::Pointers::new(),
_p: PhantomPinned,
}),
}
}
/// A custom `project` implementation is used in place of `pin-project-lite`
/// as a custom drop implementation is needed.
fn project(self: Pin<&mut Self>) -> (&mut Receiver<T>, &UnsafeCell<Waiter>) ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:36 | 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 is held
let queued = self.waiter.with(|ptr| unsafe { (*ptr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 1,401 | 1,460 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:37 | 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::Debug for Receiver<T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "broad... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 1,441 | 1,500 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:38 | use super::*;
#[test]
fn receiver_count_on_sender_constructor() {
let sender = Sender::<i32>::new(16);
assert_eq!(sender.receiver_count(), 0);
let rx_1 = sender.subscribe();
assert_eq!(sender.receiver_count(), 1);
let rx_2 = rx_1.resubscribe();
assert_eq!(sende... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3dd5f7ae2e6e7bb78de4ffb6469b96603293d2bb/tokio/src/sync/broadcast.rs | 1,481 | 1,514 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:4 | use crate::loom::sync::{Arc, Mutex, MutexGuard, RwLock, RwLockReadGuard};
use crate::util::linked_list::{self, LinkedList};
use crate::util::WakeList;
use std::fmt;
use std::future::Future;
use std::marker::PhantomPinned;
use std::pin::Pin;
use std::ptr::NonNull;
use std::sync::atomic::Ordering::SeqCst;
use std::task:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/tokio/src/sync/broadcast.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:9 | /// Next position to write to.
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> {
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/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 | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/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>(capacity: usize) -> (Sender<T>, Receiver<T>) {
// SAFETY: In the line below we are creating one extra receiver, so there will be 1 in total.
let tx = unsafe { Send... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/tokio/src/sync/broadcast.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13 | ///
/// # Safety:
///
/// The caller must ensure that the amount of receivers for this Sender is correct before
/// the channel functionalities are used, the count is zero by default, as this function
/// does not create any receivers by itself.
#[track_caller]
unsafe fn new_with_receiver_co... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/tokio/src/sync/broadcast.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15 | /// 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.unwrap(), 20);
/// });
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/tokio/src/sync/broadcast.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17 | ///
/// 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 the queue by subsequent sends that exceeded the
/// queue's capacity.
///
/// # Note
///
/// In contrast to [`Receiver::len`], this method only repor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/tokio/src/sync/broadcast.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18 | let mut low = 0;
let mut high = self.shared.buffer.len();
while low < high {
let mid = low + (high - low) / 2;
let idx = base_idx.wrapping_add(mid) & self.shared.mask;
if self.shared.buffer[idx].read().unwrap().rem.load(SeqCst) == 0 {
low = mid + 1;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/tokio/src/sync/broadcast.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20 | ///
/// 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
}
/// Returns `true` if senders belong to the same channel.
///
/// # Examples
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/tokio/src/sync/broadcast.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21 | }
/// 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();
if tail.rx_cnt == MAX_RECEIVERS {
panic!("max receivers");
}
tail.rx_cnt = tail.rx_cnt.checked_add(1).expect("overflow");
let n... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/tokio/src/sync/broadcast.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26 | // read lock and acquiring the tail lock.
if slot.pos != self.next {
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'... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/tokio/src/sync/broadcast.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27 | // Drop the old waker after releasing the locks.
drop(slot);
drop(tail);
drop(old_waker);
return Err(TryRecvError::Empty);
}
// At this point, the receiver has lagged behind the sender by
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/tokio/src/sync/broadcast.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:32 | /// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx) = broadcast::channel(16);
///
/// let sync_code = thread::spawn(move || {
/// assert_eq!(rx.blocking_recv(), Ok(10));
/// });
///
/// let _ = tx.send(10);
/// sync_code.join().unwrap();
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/tokio/src/sync/broadcast.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:33 | 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 | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/tokio/src/sync/broadcast.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34 | 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) {
// Acquire the tail lock. This is required for safety before accessing
// the waiter... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | e52d56e807af663aa9cbcdb1c2946df87eae29bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e52d56e807af663aa9cbcdb1c2946df87eae29bf/tokio/src/sync/broadcast.rs | 1,321 | 1,380 |
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 | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/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);
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/tokio/src/sync/broadcast.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16 | /// let value = rx.recv().await.unwrap();
/// assert_eq!(20, value);
/// }
/// ```
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 ei... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/tokio/src/sync/broadcast.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17 | ///
/// rx2.recv().await.unwrap();
///
/// assert_eq!(tx.len(), 2);
/// }
/// ```
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.bu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/tokio/src/sync/broadcast.rs | 641 | 700 |
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 | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/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;
self.shared.notify_rx(tail);
}
}
/// Create a new `Receiver` which reads starting from the ta... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/tokio/src/sync/broadcast.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21 | waiter.queued = false;
if let Some(waker) = waiter.waker.take() {
wakers.push(waker);
}
}
None => {
break 'outer;
}
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/tokio/src/sync/broadcast.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24 | /// # Examples
///
/// ```
/// use tokio::sync::broadcast;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, rx) = broadcast::channel::<()>(16);
/// let rx2 = tx.subscribe();
///
/// assert!(rx.same_channel(&rx2));
///
/// let (_tx3, rx3) = broadca... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/tokio/src/sync/broadcast.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25 | let mut old_waker = None;
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 betw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/tokio/src/sync/broadcast.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26 | }
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 | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/tokio/src/sync/broadcast.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:31 | /// # Panics
///
/// This function panics if called within an asynchronous execution
/// context.
///
/// # Examples
/// ```
/// use std::thread;
/// use tokio::sync::broadcast;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx) = broadcast::channel(16)... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/tokio/src/sync/broadcast.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:32 | // Ignore lagging, we will catch up
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/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>> {
ready!(crate::trace::trace_leaf(cx));
let (receiver, waiter) = self.project();
let guard = match receiver.recv_ref(Some((waiter, cx.waker()))) {
Ok(value) => value,
Err(TryRecvError::Emp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/tokio/src/sync/broadcast.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34 | /// # 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> {
ptr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/tokio/src/sync/broadcast.rs | 1,321 | 1,372 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:35 | 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: Unpin>... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 0d382faa4e557d0f6e281485cfb14a4934461c41 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d382faa4e557d0f6e281485cfb14a4934461c41/tokio/src/sync/broadcast.rs | 1,361 | 1,372 |
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);
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/broadcast.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16 | /// assert_eq!(20, value);
/// }
/// ```
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/broadcast.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17 | /// rx2.recv().await.unwrap();
///
/// assert_eq!(tx.len(), 2);
/// }
/// ```
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/broadcast.rs | 641 | 700 |
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 | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/broadcast.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20 | Arc::ptr_eq(&self.shared, &other.shared)
}
fn close_channel(&self) {
let mut tail = self.shared.tail.lock();
tail.closed = true;
self.shared.notify_rx(tail);
}
}
/// Create a new `Receiver` which reads starting from the tail.
fn new_receiver<T>(shared: Arc<Shared<T>>) -> Receiver<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/broadcast.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21 | if let Some(waker) = waiter.waker.take() {
wakers.push(waker);
}
}
None => {
break 'outer;
}
}
}
// Release the lock before waking.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/broadcast.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24 | ///
/// ```
/// use tokio::sync::broadcast;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, rx) = broadcast::channel::<()>(16);
/// let rx2 = tx.subscribe();
///
/// assert!(rx.same_channel(&rx2));
///
/// let (_tx3, rx3) = broadcast::channel::<()>(1... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/broadcast.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25 | let mut old_waker = None;
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 betw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/broadcast.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26 | if !(*ptr).queued {
(*ptr).queued = true;
tail.waiters.push_front(NonNull::new_unchecked(&mut *ptr));
}
});
}
}
// Drop the... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/broadcast.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:31 | ///
/// This function panics if called within an asynchronous execution
/// context.
///
/// # Examples
/// ```
/// use std::thread;
/// use tokio::sync::broadcast;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx) = broadcast::channel(16);
///
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/broadcast.rs | 1,201 | 1,260 |
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 | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/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>> {
ready!(crate::trace::trace_leaf(cx));
let (receiver, waiter) = self.project();
let guard = match receiver.recv_ref(Some((waiter, cx.waker()))) {
Ok(value) => value,
Err(TryRecvError::Emp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/broadcast.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34 | ///
/// `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> {
ptr
}
u... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/sync/broadcast.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/sync/broadcast.rs | 1,321 | 1,371 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.