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:30
impl<T> fmt::Debug for Receiver<T> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { 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() }) ...
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,161
1,187
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
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
321
380
tokio-rs/tokio:tokio/src/sync/broadcast.rs:11
/// [`SendError`]: crate::sync::broadcast::error::SendError /// [`RecvError`]: crate::sync::broadcast::error::RecvError /// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, mut rx1) = broadcast::channel(16); /// let mut rx2 = tx.subscribe(); //...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
401
460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12
let mut buffer = Vec::with_capacity(capacity); for i in 0..capacity { buffer.push(RwLock::new(Slot { rem: AtomicUsize::new(0), pos: (i as u64).wrapping_sub(capacity as u64), closed: false, val: UnsafeCell::new(None), })); } let shared = Arc::...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
441
500
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
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 values sent on /// this [`Sender`]. /// /// # Note /// /// It is not guar...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
let tail = self.shared.tail.lock(); tail.rx_cnt } fn send2(&self, value: Option<T>) -> Result<usize, SendError<Option<T>>> { let mut tail = self.shared.tail.lock(); if tail.rx_cnt == 0 { return Err(SendError(value)); } // Position to write into let ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
// Release the mutex. This must happen after the slot lock is released, // otherwise the writer lock bit could be cleared while another thread // is in the critical section. drop(tail); Ok(rem) } } /// Create a new `Receiver` which reads starting from the tail. fn new_receiver<T>(s...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/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) { let _ ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
/// 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); /// assert_eq!(rx1....
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs: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)>, ) -> Result<RecvGuard<'_, T>, TryRecvError> { le...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
761
820
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21
// Make sure the position did not change. This could happen in the // unlikely event that the buffer is wrapped between dropping the // read lock and acquiring the tail lock. if slot.pos != self.next { let next_pos = slot.pos.wrapping_add(self.shared.buffer.len() as u...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
801
860
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
// // However, finding the oldest position is a bit more // complicated than `tail-position - buffer-size`. When // the channel is closed, the tail position is incremented to // signal a new `None` message, but `None` is not stored in the /...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
/// 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`] /// will return with `Err(TryRecvError::Lagged)` and the [`Receiver`]'s /// internal cursor is updated to point to the oldest value still held by /// ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
1,001
1,060
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
let until = tail.pos; 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(TryRecvEr...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
1,041
1,100
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28
} } } 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
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
1,081
1,140
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29
tail.waiters.remove((&mut *ptr).into()); }); } } } } /// # 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> { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
1,121
1,179
tokio-rs/tokio:tokio/src/sync/broadcast.rs:30
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_sub(1, SeqCst) { // Safety...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4daeea8cad1ce8e67946bc0e17d499ab304b5ca2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4daeea8cad1ce8e67946bc0e17d499ab304b5ca2/tokio/src/sync/broadcast.rs
1,161
1,179
tokio-rs/tokio:tokio/src/sync/broadcast.rs:11
/// [`SendError`]: crate::sync::broadcast::error::SendError /// [`RecvError`]: crate::sync::broadcast::error::RecvError /// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, mut rx1) = broadcast::channel(16); /// let mut rx2 = tx.subscribe(); //...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f6c0405084cc7efbbf10202d44aaf8885fd3f84f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f6c0405084cc7efbbf10202d44aaf8885fd3f84f/tokio/src/sync/broadcast.rs
401
460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12
for i in 0..capacity { buffer.push(RwLock::new(Slot { rem: AtomicUsize::new(0), pos: (i as u64).wrapping_sub(capacity as u64), closed: false, val: UnsafeCell::new(None), })); } let shared = Arc::new(Shared { buffer: buffer.into_boxed_slice...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f6c0405084cc7efbbf10202d44aaf8885fd3f84f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f6c0405084cc7efbbf10202d44aaf8885fd3f84f/tokio/src/sync/broadcast.rs
441
500
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
} /// 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
f6c0405084cc7efbbf10202d44aaf8885fd3f84f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f6c0405084cc7efbbf10202d44aaf8885fd3f84f/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
tail.rx_cnt } fn send2(&self, value: Option<T>) -> Result<usize, SendError<Option<T>>> { let mut tail = self.shared.tail.lock(); if tail.rx_cnt == 0 { return Err(SendError(value)); } // Position to write into let pos = tail.pos; let rem = tail.rx_cn...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f6c0405084cc7efbbf10202d44aaf8885fd3f84f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f6c0405084cc7efbbf10202d44aaf8885fd3f84f/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
// Release the mutex. This must happen after the slot lock is released, // otherwise the writer lock bit could be cleared while another thread // is in the critical section. drop(tail); Ok(rem) } } /// Create a new `Receiver` which reads starting from the tail. fn new_receiver<T>(s...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f6c0405084cc7efbbf10202d44aaf8885fd3f84f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f6c0405084cc7efbbf10202d44aaf8885fd3f84f/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) { let _ = s...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f6c0405084cc7efbbf10202d44aaf8885fd3f84f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f6c0405084cc7efbbf10202d44aaf8885fd3f84f/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
/// 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); /// assert_eq!(rx1.recv().await.unwrap(), 20)...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f6c0405084cc7efbbf10202d44aaf8885fd3f84f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f6c0405084cc7efbbf10202d44aaf8885fd3f84f/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20
/// } /// ``` 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)>, ) -> Result<RecvGuard<'_, T>, TryRecvError> { let idx = (self.next & self.shared.mask...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f6c0405084cc7efbbf10202d44aaf8885fd3f84f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f6c0405084cc7efbbf10202d44aaf8885fd3f84f/tokio/src/sync/broadcast.rs
761
820
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21
// unlikely event that the buffer is wrapped between dropping the // 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 { // Store t...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f6c0405084cc7efbbf10202d44aaf8885fd3f84f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f6c0405084cc7efbbf10202d44aaf8885fd3f84f/tokio/src/sync/broadcast.rs
801
860
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
// However, finding the oldest position is a bit more // complicated than `tail-position - buffer-size`. When // the channel is closed, the tail position is incremented to // signal a new `None` message, but `None` is not stored in the // channel itself (s...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f6c0405084cc7efbbf10202d44aaf8885fd3f84f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f6c0405084cc7efbbf10202d44aaf8885fd3f84f/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29
}); } } } } /// # 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
f6c0405084cc7efbbf10202d44aaf8885fd3f84f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f6c0405084cc7efbbf10202d44aaf8885fd3f84f/tokio/src/sync/broadcast.rs
1,121
1,178
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
tail.rx_cnt } fn send2(&self, value: Option<T>) -> Result<usize, SendError<Option<T>>> { let mut tail = self.shared.tail.lock(); if tail.rx_cnt == 0 { return Err(SendError(value)); } // Position to write into let pos = tail.pos; let rem = tail.rx_cn...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
2fe49a68a4463acc5a4129228acd852dff6a7178
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2fe49a68a4463acc5a4129228acd852dff6a7178/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
// Release the mutex. This must happen after the slot lock is released, // otherwise the writer lock bit could be cleared while another thread // is in the critical section. drop(tail); Ok(rem) } } fn new_receiver<T>(shared: Arc<Shared<T>>) -> Receiver<T> { let mut tail = share...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
2fe49a68a4463acc5a4129228acd852dff6a7178
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2fe49a68a4463acc5a4129228acd852dff6a7178/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) { let _ = s...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
2fe49a68a4463acc5a4129228acd852dff6a7178
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2fe49a68a4463acc5a4129228acd852dff6a7178/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
/// /// 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); /// assert_eq!(rx1.recv().await.unwrap(), 20); /// assert_eq!(rx1.len(), 0); /// } //...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
2fe49a68a4463acc5a4129228acd852dff6a7178
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2fe49a68a4463acc5a4129228acd852dff6a7178/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20
/// ``` 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)>, ) -> Result<RecvGuard<'_, T>, TryRecvError> { let idx = (self.next & self.shared.mask as u64) a...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
2fe49a68a4463acc5a4129228acd852dff6a7178
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2fe49a68a4463acc5a4129228acd852dff6a7178/tokio/src/sync/broadcast.rs
761
820
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21
// 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 { // Store the waker if let Some((waiter, waker)) = waiter { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
2fe49a68a4463acc5a4129228acd852dff6a7178
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2fe49a68a4463acc5a4129228acd852dff6a7178/tokio/src/sync/broadcast.rs
801
860
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
// complicated than `tail-position - buffer-size`. When // the channel is closed, the tail position is incremented to // signal a new `None` message, but `None` is not stored in the // channel itself (see issue #2425 for why). // // To acco...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
2fe49a68a4463acc5a4129228acd852dff6a7178
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2fe49a68a4463acc5a4129228acd852dff6a7178/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
/// Attempts to return a pending value on this receiver without awaiting. /// /// This is useful for a flavor of "optimistic check" before deciding to /// await on a receiver. /// /// Compared with [`recv`], this function has three failure cases instead of two /// (one for closed, one for an emp...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
2fe49a68a4463acc5a4129228acd852dff6a7178
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2fe49a68a4463acc5a4129228acd852dff6a7178/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
pub fn try_recv(&mut self) -> Result<T, TryRecvError> { let guard = self.recv_ref(None)?; guard.clone_value().ok_or(TryRecvError::Closed) } } impl<T> Drop for Receiver<T> { fn drop(&mut self) { let mut tail = self.shared.tail.lock(); tail.rx_cnt -= 1; let until = tail.p...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
2fe49a68a4463acc5a4129228acd852dff6a7178
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2fe49a68a4463acc5a4129228acd852dff6a7178/tokio/src/sync/broadcast.rs
1,001
1,060
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
} /// 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>) { unsafe { // Safety: Receiver is Unpin is_unpin::<&mut Receiver<T>>(); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
2fe49a68a4463acc5a4129228acd852dff6a7178
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2fe49a68a4463acc5a4129228acd852dff6a7178/tokio/src/sync/broadcast.rs
1,041
1,100
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28
// safety: tail lock is held let queued = self.waiter.with(|ptr| unsafe { (*ptr).queued }); if queued { // Remove the node // // safety: tail lock is held and the wait node is verified to be in // the list. unsafe { self.waiter...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
2fe49a68a4463acc5a4129228acd852dff6a7178
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2fe49a68a4463acc5a4129228acd852dff6a7178/tokio/src/sync/broadcast.rs
1,081
1,140
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29
write!(fmt, "broadcast::Sender") } } impl<T> fmt::Debug for Receiver<T> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "broadcast::Receiver") } } impl<'a, T> RecvGuard<'a, T> { fn clone_value(&self) -> Option<T> where T: Clone, { self.slot.va...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
2fe49a68a4463acc5a4129228acd852dff6a7178
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2fe49a68a4463acc5a4129228acd852dff6a7178/tokio/src/sync/broadcast.rs
1,121
1,150
tokio-rs/tokio:tokio/src/sync/broadcast.rs:11
/// [`SendError`]: crate::sync::broadcast::error::SendError /// [`RecvError`]: crate::sync::broadcast::error::RecvError /// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, mut rx1) = broadcast::channel(16); /// let mut rx2 = tx.subscribe(); //...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
401
460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12
closed: false, val: UnsafeCell::new(None), })); } let shared = Arc::new(Shared { buffer: buffer.into_boxed_slice(), mask: capacity - 1, tail: Mutex::new(Tail { pos: 0, rx_cnt: 1, closed: false, waiters: LinkedList::new(...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
441
500
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
/// [`subscribe`]. These are the handles that will receive values sent on /// this [`Sender`]. /// /// # Note /// /// It is not guaranteed that a sent message will reach this number of /// receivers. Active receivers may never call [`recv`] again before /// dropping. /// /// [`recv`]...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
if tail.rx_cnt == 0 { return Err(SendError(value)); } // Position to write into let pos = tail.pos; let rem = tail.rx_cnt; let idx = (pos & self.shared.mask as u64) as usize; // Update the tail position tail.pos = tail.pos.wrapping_add(1); /...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
Ok(rem) } } 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 next = tail.pos; drop(tail); Receiver { s...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
Sender { shared } } } impl<T> Drop for Sender<T> { fn drop(&mut self) { if 1 == self.shared.num_tx.fetch_sub(1, SeqCst) { let _ = self.send2(None); } } } impl<T> Receiver<T> { /// Returns the number of messages that were sent into the channel and that /// this [`Receive...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
/// assert_eq!(rx1.recv().await.unwrap(), 10); /// assert_eq!(rx1.len(), 1); /// assert_eq!(rx1.recv().await.unwrap(), 20); /// assert_eq!(rx1.len(), 0); /// } /// ``` pub fn len(&self) -> usize { let next_send_pos = self.shared.tail.lock().pos; (next_send_pos - s...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20
/// Locks the next value if there is one. fn recv_ref( &mut self, waiter: Option<(&UnsafeCell<Waiter>, &Waker)>, ) -> Result<RecvGuard<'_, T>, TryRecvError> { let idx = (self.next & self.shared.mask as u64) as usize; // The slot holding the next value to read let mut slo...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
761
820
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21
// Store the waker if let Some((waiter, waker)) = waiter { // Safety: called while locked. unsafe { // Only queue if not already queued waiter.with_mut(|ptr| { // I...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
801
860
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
// To account for this, if the channel is closed, the tail // position is decremented by `buffer-size + 1`. let mut adjust = 0; if tail.closed { adjust = 1 } let next = tail .pos ....
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
/// 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 further values can be sent on the chan...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
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
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
1,001
1,060
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
unsafe { // 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<&...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
1,041
1,100
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28
// 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
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
1,081
1,140
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { 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,...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
3652f71ade9caa07378ac0225a198e83207f4213
github
async-runtime
https://github.com/tokio-rs/tokio/blob/3652f71ade9caa07378ac0225a198e83207f4213/tokio/src/sync/broadcast.rs
1,121
1,145
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
2f944dfa1be67411f54f625674fb8f5f14927825
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2f944dfa1be67411f54f625674fb8f5f14927825/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
2f944dfa1be67411f54f625674fb8f5f14927825
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2f944dfa1be67411f54f625674fb8f5f14927825/tokio/src/sync/broadcast.rs
241
300
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
Ok(rem) } } 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 next = tail.pos; drop(tail); Receiver { s...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
03969cdae7674681d1b10926e6a56fbb8908dbb8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
Sender { shared } } } impl<T> Drop for Sender<T> { fn drop(&mut self) { if 1 == self.shared.num_tx.fetch_sub(1, SeqCst) { let _ = self.send2(None); } } } impl<T> Receiver<T> { /// Locks the next value if there is one. fn recv_ref( &mut self, waiter: Opti...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
03969cdae7674681d1b10926e6a56fbb8908dbb8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
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 the // read lo...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
03969cdae7674681d1b10926e6a56fbb8908dbb8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20
// 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 // channel. ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
03969cdae7674681d1b10926e6a56fbb8908dbb8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/broadcast.rs
761
820
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
/// assert_eq!(30, rx.recv().await.unwrap()); /// } /// ``` pub async fn recv(&mut self) -> Result<T, RecvError> { let fut = Recv::new(self); fut.await } /// Attempts to return a pending value on this receiver without awaiting. /// /// This is useful for a flavor of "opt...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
03969cdae7674681d1b10926e6a56fbb8908dbb8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
/// 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> { let guard = self.recv_ref(None)?; guard.clone_va...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
03969cdae7674681d1b10926e6a56fbb8908dbb8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
receiver, 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` ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
03969cdae7674681d1b10926e6a56fbb8908dbb8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
} } 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
03969cdae7674681d1b10926e6a56fbb8908dbb8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/broadcast.rs
1,001
1,060
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
unsafe fn pointers(mut target: NonNull<Waiter>) -> NonNull<linked_list::Pointers<Waiter>> { NonNull::from(&mut target.as_mut().pointers) } } impl<T> fmt::Debug for Sender<T> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "broadcast::Sender") } } impl<T> fmt::Deb...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
03969cdae7674681d1b10926e6a56fbb8908dbb8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/sync/broadcast.rs
1,041
1,078
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
b521cc26895c6331c8ced6be72f8b3d9947a9fb3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/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
b521cc26895c6331c8ced6be72f8b3d9947a9fb3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/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 used...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
b521cc26895c6331c8ced6be72f8b3d9947a9fb3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b521cc26895c6331c8ced6be72f8b3d9947a9fb3/tokio/src/sync/broadcast.rs
321
380
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
/// Attempts to return a pending value on this receiver without awaiting. /// /// This is useful for a flavor of "optimistic check" before deciding to /// await on a receiver. /// /// Compared with [`recv`], this function has three failure cases instead of two /// (one for closed, one for an emp...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0a04954d5ca74693cf7adbe2dd3a18de2987c519
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0a04954d5ca74693cf7adbe2dd3a18de2987c519/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
/// ``` pub fn try_recv(&mut self) -> Result<T, TryRecvError> { let guard = self.recv_ref(None)?; guard.clone_value().ok_or(TryRecvError::Closed) } } impl<T> Drop for Receiver<T> { fn drop(&mut self) { let mut tail = self.shared.tail.lock(); tail.rx_cnt -= 1; let un...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0a04954d5ca74693cf7adbe2dd3a18de2987c519
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0a04954d5ca74693cf7adbe2dd3a18de2987c519/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
} } /// 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>) { unsafe { // Safety: Receiver is Unpin is_unpin::<&mut Receiver<T>...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0a04954d5ca74693cf7adbe2dd3a18de2987c519
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0a04954d5ca74693cf7adbe2dd3a18de2987c519/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
let mut tail = self.receiver.shared.tail.lock(); // safety: tail lock is held let queued = self.waiter.with(|ptr| unsafe { (*ptr).queued }); if queued { // Remove the node // // safety: tail lock is held and the wait node is verified to be in // ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0a04954d5ca74693cf7adbe2dd3a18de2987c519
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0a04954d5ca74693cf7adbe2dd3a18de2987c519/tokio/src/sync/broadcast.rs
1,001
1,060
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
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, "broadcast::Receiver") } } impl<'a, T> RecvGuard<'a, T> { fn clone_value(&self...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0a04954d5ca74693cf7adbe2dd3a18de2987c519
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0a04954d5ca74693cf7adbe2dd3a18de2987c519/tokio/src/sync/broadcast.rs
1,041
1,071
tokio-rs/tokio:tokio/src/sync/broadcast.rs:5
/// Receiving-half of the [`broadcast`] channel. /// /// Must not be used concurrently. Messages may be retrieved using /// [`recv`][Receiver::recv]. /// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, mut rx1) = broadcast::channel(16); /// le...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
161
220
tokio-rs/tokio:tokio/src/sync/broadcast.rs:6
//! 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 received. The error contains the /// message being sent as a paylo...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
201
260
tokio-rs/tokio:tokio/src/sync/broadcast.rs:7
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) => write!(f, "channel lagged by {}", amt), } } } impl std::e...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
241
300
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8
TryRecvError::Lagged(amt) => write!(f, "channel lagged by {}", amt), } } } impl std::error::Error for TryRecvError {} } use self::error::*; /// Data shared between senders and receivers struct Shared<T> { /// slots in the channel buffer: Box<[RwLock<Slot<T>>]>, /// Mask a pos...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
281
340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:9
/// 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 used as it is mutated concurrently with the slot read lock /// acquired. rem: AtomicUsize, /// Uniqu...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
321
380
tokio-rs/tokio:tokio/src/sync/broadcast.rs:11
/// ``` /// 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!(rx1.recv().await.unwrap(), 20...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
401
460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12
let shared = Arc::new(Shared { buffer: buffer.into_boxed_slice(), mask: capacity - 1, tail: Mutex::new(Tail { pos: 0, rx_cnt: 1, closed: false, waiters: LinkedList::new(), }), num_tx: AtomicUsize::new(1), }); let rx = Recei...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
441
500
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
/// It is not guaranteed that a sent message will reach this number of /// receivers. Active receivers may never call [`recv`] again before /// dropping. /// /// [`recv`]: crate::sync::broadcast::Receiver::recv /// [`Receiver`]: crate::sync::broadcast::Receiver /// [`Sender`]: crate::sync::broad...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
// Position to write into let pos = tail.pos; let rem = tail.rx_cnt; let idx = (pos & self.shared.mask as u64) as usize; // Update the tail position tail.pos = tail.pos.wrapping_add(1); // Get the slot let mut slot = self.shared.buffer[idx].write().unwrap(); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
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 next = tail.pos; drop(tail); Receiver { shared, next } } impl Tail { fn notify_rx(&mut self) { while let Some...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
fn drop(&mut self) { if 1 == self.shared.num_tx.fetch_sub(1, SeqCst) { let _ = self.send2(None); } } } impl<T> Receiver<T> { /// Locks the next value if there is one. fn recv_ref( &mut self, waiter: Option<(&UnsafeCell<Waiter>, &Waker)>, ) -> Result<RecvGuard...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
// Make sure the position did not change. This could happen in the // unlikely event that the buffer is wrapped between dropping the // read lock and acquiring the tail lock. if slot.pos != self.next { let next_pos = slot.pos.wrapping_add(self.shared.buffer.len() as u...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20
// channel. // // However, finding the oldest position is a bit more // complicated than `tail-position - buffer-size`. When // the channel is closed, the tail position is incremented to // signal a new `None` message, but `None` is not sto...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
761
820
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
/// /// 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 further values can be sent on ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
} 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 i...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
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) } } } impl<'a, T> Future for Recv<'a, T> ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
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
7d5b12c50947929326bdfaadb78155ee6593f209
github
async-runtime
https://github.com/tokio-rs/tokio/blob/7d5b12c50947929326bdfaadb78155ee6593f209/tokio/src/sync/broadcast.rs
1,001
1,060
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
/// /// 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 further values can be sent on ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
53707f5d9dd271615c9191bf70cb2f68f1e500c8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/53707f5d9dd271615c9191bf70cb2f68f1e500c8/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
} 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
53707f5d9dd271615c9191bf70cb2f68f1e500c8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/53707f5d9dd271615c9191bf70cb2f68f1e500c8/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:9
/// 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 used as it is mutated concurrently with the slot read lock /// acquired. rem: AtomicUsize, /// Uniqu...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
8efa62013b551d5130791c3a79ce8ab5cb0b5abf
github
async-runtime
https://github.com/tokio-rs/tokio/blob/8efa62013b551d5130791c3a79ce8ab5cb0b5abf/tokio/src/sync/broadcast.rs
321
380
tokio-rs/tokio:tokio/src/sync/broadcast.rs:10
} /// Receive a value future struct Recv<R, T> where R: AsMut<Receiver<T>>, { /// Receiver being waited on receiver: R, /// Entry in the waiter `LinkedList` waiter: UnsafeCell<Waiter>, _p: std::marker::PhantomData<T>, } /// `AsMut<T>` is not implemented for `T` (coherence). Explicitly implem...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
8efa62013b551d5130791c3a79ce8ab5cb0b5abf
github
async-runtime
https://github.com/tokio-rs/tokio/blob/8efa62013b551d5130791c3a79ce8ab5cb0b5abf/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12
/// tx.send(10).unwrap(); /// tx.send(20).unwrap(); /// } /// ``` 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 = c...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
8efa62013b551d5130791c3a79ce8ab5cb0b5abf
github
async-runtime
https://github.com/tokio-rs/tokio/blob/8efa62013b551d5130791c3a79ce8ab5cb0b5abf/tokio/src/sync/broadcast.rs
441
500
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
/// /// assert_eq!(1, tx.receiver_count()); /// /// 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(); t...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
8efa62013b551d5130791c3a79ce8ab5cb0b5abf
github
async-runtime
https://github.com/tokio-rs/tokio/blob/8efa62013b551d5130791c3a79ce8ab5cb0b5abf/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
if value.is_none() { tail.closed = true; slot.closed = true; } 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. Th...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
8efa62013b551d5130791c3a79ce8ab5cb0b5abf
github
async-runtime
https://github.com/tokio-rs/tokio/blob/8efa62013b551d5130791c3a79ce8ab5cb0b5abf/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
// Safety: `waiters` lock is still held. let waiter = unsafe { waiter.as_mut() }; assert!(waiter.queued); waiter.queued = false; let waker = waiter.waker.take().unwrap(); waker.wake(); } } } impl<T> Clone for Sender<T> { fn clone(&self) -> S...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
8efa62013b551d5130791c3a79ce8ab5cb0b5abf
github
async-runtime
https://github.com/tokio-rs/tokio/blob/8efa62013b551d5130791c3a79ce8ab5cb0b5abf/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
if slot.pos != self.next { let next_pos = slot.pos.wrapping_add(self.shared.buffer.len() as u64); // The receiver has read all current values in the channel and there // is no waiter to register if waiter.is_none() && next_pos == self.next { return Err(Tr...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
8efa62013b551d5130791c3a79ce8ab5cb0b5abf
github
async-runtime
https://github.com/tokio-rs/tokio/blob/8efa62013b551d5130791c3a79ce8ab5cb0b5abf/tokio/src/sync/broadcast.rs
721
780