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:25
} } impl<'a, T> WaitersList<'a, T> { fn new( unguarded_list: LinkedList<Waiter, <Waiter as linked_list::Link>::Target>, guard: Pin<&'a Waiter>, shared: &'a Shared<T>, ) -> Self { let guard_ptr = NonNull::from(guard.get_ref()); let list = unguarded_list.into_guarded(guard...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
// // * This list will be still guarded by the `waiters` lock. // `NotifyWaitersList` wrapper makes sure we hold the lock to modify it. // * This wrapper will empty the list on drop. It is critical for safety // that we will not leave any list entry with a pointer to the local ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
1,001
1,060
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
// 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
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
1,041
1,100
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28
pub fn upgrade(&self) -> Option<Sender<T>> { let mut tx_count = self.shared.num_tx.load(Acquire); loop { if tx_count == 0 { // channel is closed so this WeakSender can not be upgraded return None; } match self .shared ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
1,081
1,140
tokio-rs/tokio:tokio/src/sync/broadcast.rs:31
/// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// # #[tokio::main(flavor = "current_thread")] /// # async fn main() { /// let (tx, rx) = broadcast::channel::<()>(16); /// let rx2 = tx.subscribe(); /// /// assert!(rx.same_channel(&rx2)); /// /// let (_tx3,...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
1,201
1,260
tokio-rs/tokio:tokio/src/sync/broadcast.rs:32
let mut old_waker = None; let mut tail = self.shared.tail.lock(); // Acquire slot lock again slot = self.shared.buffer[idx].lock(); // Make sure the position did not change. This could happen in the // unlikely event that the buffer is wrapped between dropp...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
1,241
1,300
tokio-rs/tokio:tokio/src/sync/broadcast.rs:33
// `Relaxed` order suffices: we have synchronized with // all writers through the tail lock that we hold. if !(*ptr).queued.load(Relaxed) { // `Relaxed` order suffices: all the readers will ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
1,281
1,340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34
return Err(TryRecvError::Lagged(missed)); } } self.next = self.next.wrapping_add(1); Ok(RecvGuard { slot }) } /// Returns the number of [`Sender`] handles. pub fn sender_strong_count(&self) -> usize { self.shared.num_tx.load(Acquire) } /// Returns the ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
1,321
1,380
tokio-rs/tokio:tokio/src/sync/broadcast.rs:39
/// context. /// /// # Examples /// ``` /// # #[cfg(not(target_family = "wasm"))] /// # { /// use std::thread; /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, mut rx) = broadcast::channel(16); /// /// let sync_code = t...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
1,521
1,580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:40
drop(tail); while self.next < until { match self.recv_ref(None) { Ok(_) => {} // The channel is closed Err(TryRecvError::Closed) => break, // Ignore lagging, we will catch up Err(TryRecvError::Lagged(..)) => {} ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
1,561
1,620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:41
} 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>> { ready!(crate::trace::trace_leaf(cx)); let (receiver, waiter) = self.project(); let guard = match receiver...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
1,601
1,660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:42
let mut tail = self.receiver.shared.tail.lock(); // Safety: tail lock is held. // `Relaxed` order suffices because we hold the tail lock. let queued = self .waiter .0 .with_mut(|ptr| unsafe { (*ptr).queued.load(Relaxed) }); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
1,641
1,700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:43
unsafe { 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 WeakSender<T> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
1,681
1,740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:44
fn is_unpin<T: Unpin>() {} #[cfg(not(loom))] #[cfg(test)] 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_co...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
1,721
1,759
tokio-rs/tokio:tokio/src/sync/broadcast.rs:4
use crate::loom::sync::{Arc, Mutex, MutexGuard}; use crate::runtime::coop::cooperative; 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:...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
121
180
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 the [`se...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
201
260
tokio-rs/tokio:tokio/src/sync/broadcast.rs:7
#[derive(Debug, PartialEq, Eq, Clone)] pub enum RecvError { /// There are no more active senders implying no further messages will ever /// be sent. Closed, /// The receiver lagged too far behind. Attempting to receive again will /// return the oldest message still retained ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
241
300
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
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
281
340
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
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/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: AtomicBool::new(false), waker: None, pointers: linked_list::Pointers::new(), ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12
/// let (tx, mut rx1) = broadcast::channel(16); /// let mut rx2 = tx.subscribe(); /// /// tokio::spawn(async move { /// assert_eq!(rx1.recv().await.unwrap(), 10); /// assert_eq!(rx1.recv().await.unwrap(), 20); /// }); /// /// tokio::spawn(async move { /// assert_eq!(rx2.recv(...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/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
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/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
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/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
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/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
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/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
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/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
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
801
860
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
// 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> WaitersList<'a, T> { fn new( unguarded_list: LinkedList<Waiter, <Waiter as linked_list::...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
let guard = Waiter::new(); pin!(guard); // We move all waiters to a secondary list. It uses a `GuardedLinkedList` // underneath to allow every waiter to safely remove itself from it. // // * This list will be still guarded by the `waiters` lock. // `NotifyWaitersList` ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
// Release the lock before waking. drop(tail); // 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 u...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
/// /// 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 next value if there is one. fn recv_ref( ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
1,041
1,100
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28
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's been closed, then that's what we return, otherwise w...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
1,081
1,140
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29
}); } } // Drop the old waker after releasing the locks. drop(slot); drop(tail); drop(old_waker); return Err(TryRecvError::Empty); } // At th...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
1,121
1,180
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34
/// 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
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
1,321
1,380
tokio-rs/tokio:tokio/src/sync/broadcast.rs:35
} } impl<'a, T> Recv<'a, T> { fn new(receiver: &'a mut Receiver<T>) -> Recv<'a, T> { Recv { receiver, waiter: WaiterCell(UnsafeCell::new(Waiter { queued: AtomicBool::new(false), waker: None, pointers: linked_list::Pointers::new(), ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
1,361
1,420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:36
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(TryRecvError::Closed) => return Poll::Ready(Err(RecvE...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
1,401
1,460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:37
// the list. unsafe { self.waiter.0.with_mut(|ptr| { tail.waiters.remove((&mut *ptr).into()); }); } } } } } /// # Safety /// /// `Waiter` is forced to be !Unpin. unsafe impl linked_list::Link for Wai...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
1,441
1,500
tokio-rs/tokio:tokio/src/sync/broadcast.rs:38
} } impl<'a, T> RecvGuard<'a, T> { fn clone_value(&self) -> Option<T> where T: Clone, { self.slot.val.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) { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
1,481
1,540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:39
assert_eq!(sender.receiver_count(), 3); drop(rx_3); drop(rx_1); assert_eq!(sender.receiver_count(), 1); drop(rx_2); assert_eq!(sender.receiver_count(), 0); } #[cfg(not(loom))] #[test] fn receiver_count_on_channel_constructor() { let (sender, rx) = chann...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400
github
async-runtime
https://github.com/tokio-rs/tokio/blob/da292dfb66ef34fdfbb6aa1f23c3b2456ca4d400/tokio/src/sync/broadcast.rs
1,521
1,540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:42
let mut tail = self.receiver.shared.tail.lock(); // Safety: tail lock is held. // `Relaxed` order suffices because we hold the tail lock. let queued = self .waiter .0 .with_mut(|ptr| unsafe { (*ptr).queued.load(Relaxed) }); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
95edd8515ee863ac550849af0a741c889ebdf314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/95edd8515ee863ac550849af0a741c889ebdf314/tokio/src/sync/broadcast.rs
1,641
1,700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:43
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 WeakSender<T> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "bro...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
95edd8515ee863ac550849af0a741c889ebdf314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/95edd8515ee863ac550849af0a741c889ebdf314/tokio/src/sync/broadcast.rs
1,681
1,740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:4
use crate::loom::sync::{Arc, Mutex, MutexGuard}; use crate::task::coop::cooperative; 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::Or...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
121
180
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
/// #[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); /// }); /// /// tokio::spawn(asyn...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
481
540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
} let shared = Arc::new(Shared { buffer: buffer.into_boxed_slice(), mask: capacity - 1, tail: Mutex::new(Tail { pos: 0, rx_cnt: receiver_count, closed: receiver_count == 0, waiters: LinkedList::new(), ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
/// will fail. New [`Receiver`] handles may be created by calling /// [`subscribe`]. /// /// [`Receiver`]: crate::sync::broadcast::Receiver /// [`subscribe`]: crate::sync::broadcast::Sender::subscribe /// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// #[to...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
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].lock(); // Track the position slot.pos = pos; // Set remaining receivers slot.re...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/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, mut rx1) = broadcast::channel(16); /// let mut rx2 = tx.subscribe(); /// /// tx.send(10).unwrap(); /// tx.send(20).unwrap(); /// tx.send(30).unwrap(); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
/// drop(rx1); /// assert!(tx.closed().now_or_never().is_none()); /// /// assert_eq!(rx2.recv().await.unwrap(), 10); /// drop(rx2); /// assert!(tx.closed().now_or_never().is_some()); /// } /// ``` pub async fn closed(&self) { loop { let notified = ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:31
/// # 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
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
1,201
1,260
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34
return Err(TryRecvError::Lagged(missed)); } } self.next = self.next.wrapping_add(1); Ok(RecvGuard { slot }) } /// Returns the number of [`Sender`] handles. pub fn sender_strong_count(&self) -> usize { self.shared.num_tx.load(Acquire) } /// Returns the ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
1,321
1,380
tokio-rs/tokio:tokio/src/sync/broadcast.rs:39
/// context. /// /// # 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.block...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
1,521
1,580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:40
match self.recv_ref(None) { Ok(_) => {} // The channel is closed Err(TryRecvError::Closed) => break, // Ignore lagging, we will catch up Err(TryRecvError::Lagged(..)) => {} // Can't be empty Err(TryRecvError:...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
1,561
1,620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:41
where T: Clone, { type Output = Result<T, RecvError>; 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()))) ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
1,601
1,660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:42
// `Relaxed` order suffices because we hold the tail lock. let queued = self .waiter .0 .with_mut(|ptr| unsafe { (*ptr).queued.load(Relaxed) }); if queued { // Remove the node // // safety: tail lock...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
1,641
1,700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:43
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 WeakSender<T> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "broadcast::WeakSender") } } impl<T> fmt:...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
1,681
1,740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:44
#[cfg(test)] 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.resubscrib...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
6d1ae6286880c828c13efb5f11b60c18fb94f947
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d1ae6286880c828c13efb5f11b60c18fb94f947/tokio/src/sync/broadcast.rs
1,721
1,756
tokio-rs/tokio:tokio/src/sync/broadcast.rs:14
/// See the documentation of [`broadcast::channel`] for more information on this method. /// /// [`broadcast`]: crate::sync::broadcast /// [`broadcast::channel`]: crate::sync::broadcast::channel #[track_caller] pub fn new(capacity: usize) -> Self { // SAFETY: We don't create extra receivers,...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
8efd04e38284f2da2d1b3abc8496a511e131d1ce
github
async-runtime
https://github.com/tokio-rs/tokio/blob/8efd04e38284f2da2d1b3abc8496a511e131d1ce/tokio/src/sync/broadcast.rs
521
580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
} let shared = Arc::new(Shared { buffer: buffer.into_boxed_slice(), mask: capacity - 1, tail: Mutex::new(Tail { pos: 0, rx_cnt: receiver_count, closed: false, waiters: LinkedList::new(), }), ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
8efd04e38284f2da2d1b3abc8496a511e131d1ce
github
async-runtime
https://github.com/tokio-rs/tokio/blob/8efd04e38284f2da2d1b3abc8496a511e131d1ce/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
/// #[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); /// }); /// /// tokio::spawn(asyn...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a7896d07f1d3093524c7a190b57570dad3767c7a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a7896d07f1d3093524c7a190b57570dad3767c7a/tokio/src/sync/broadcast.rs
481
540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:32
let mut old_waker = None; let mut tail = self.shared.tail.lock(); // Acquire slot lock again slot = self.shared.buffer[idx].lock(); // Make sure the position did not change. This could happen in the // unlikely event that the buffer is wrapped between dropp...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d7d4f7d08bf75daf23bec676b03cb4c88993e5d0
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d7d4f7d08bf75daf23bec676b03cb4c88993e5d0/tokio/src/sync/broadcast.rs
1,241
1,300
tokio-rs/tokio:tokio/src/sync/broadcast.rs:33
} // If the waiter is not already queued, enqueue it. // `Relaxed` order suffices: we have synchronized with // all writers through the tail lock that we hold. if !(*ptr).queued.load(Relaxed)...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d7d4f7d08bf75daf23bec676b03cb4c88993e5d0
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d7d4f7d08bf75daf23bec676b03cb4c88993e5d0/tokio/src/sync/broadcast.rs
1,281
1,340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34
self.next = next; return Err(TryRecvError::Lagged(missed)); } } self.next = self.next.wrapping_add(1); Ok(RecvGuard { slot }) } /// Returns the number of [`Sender`] handles. pub fn sender_strong_count(&self) -> usize { self.shared.num_tx.load(A...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d7d4f7d08bf75daf23bec676b03cb4c88993e5d0
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d7d4f7d08bf75daf23bec676b03cb4c88993e5d0/tokio/src/sync/broadcast.rs
1,321
1,380
tokio-rs/tokio:tokio/src/sync/broadcast.rs:39
/// # 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
d7d4f7d08bf75daf23bec676b03cb4c88993e5d0
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d7d4f7d08bf75daf23bec676b03cb4c88993e5d0/tokio/src/sync/broadcast.rs
1,521
1,580
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 the [`send`] f...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
201
260
tokio-rs/tokio:tokio/src/sync/broadcast.rs:7
pub enum RecvError { /// There are no more active senders implying no further messages will ever /// be sent. Closed, /// The receiver lagged too far behind. Attempting to receive again will /// return the oldest message still retained by the channel. /// /// Inc...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
241
300
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8
/// Attempting to receive again will return the oldest message still /// retained by the channel. /// /// Includes the number of skipped messages. Lagged(u64), } impl fmt::Display for TryRecvError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { m...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
281
340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:9
pos: u64, /// Number of active receivers. rx_cnt: usize, /// True if the channel is closed. closed: bool, /// Receivers waiting for a value. waiters: LinkedList<Waiter, <Waiter as linked_list::Link>::Target>, } /// Slot in the buffer. struct Slot<T> { /// Remaining number of receivers th...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/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: AtomicBool::new(false), waker: None, pointers: linked_list::Pointers::new(), ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12
/// let mut rx2 = tx.subscribe(); /// /// tokio::spawn(async move { /// assert_eq!(rx1.recv().await.unwrap(), 10); /// assert_eq!(rx1.recv().await.unwrap(), 20); /// }); /// /// tokio::spawn(async move { /// assert_eq!(rx2.recv().await.unwrap(), 10); /// assert_eq!(rx2.re...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
441
500
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
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. /// /// See the documentatio...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
481
540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
/// /// ``` /// 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
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/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 it has ei...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
/// /// 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
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/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
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/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 from the ta...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
801
860
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
if !self.is_empty { let _lock_guard = self.shared.tail.lock(); while self.list.pop_back().is_some() {} } } } impl<'a, T> WaitersList<'a, T> { fn new( unguarded_list: LinkedList<Waiter, <Waiter as linked_list::Link>::Target>, guard: Pin<&'a Waiter>, shared...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
pin!(guard); // We move all waiters to a secondary list. It uses a `GuardedLinkedList` // underneath to allow every waiter to safely remove itself from it. // // * This list will be still guarded by the `waiters` lock. // `NotifyWaitersList` wrapper makes sure we hold the lock...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
// Release the lock before waking. drop(tail); // 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 u...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
/// 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 next value if there is one. fn recv_ref( &mut s...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
1,041
1,100
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28
let next_pos = slot.pos.wrapping_add(self.shared.buffer.len() as u64); if next_pos == self.next { // At this point the channel is empty for *this* receiver. If // it's been closed, then that's what we return, otherwise we // set a waker and re...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
1,081
1,140
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29
} } // 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 l...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4b174ce2c95fe1d1a217917db93fcc935e17e0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4b174ce2c95fe1d1a217917db93fcc935e17e0da/tokio/src/sync/broadcast.rs
1,121
1,180
tokio-rs/tokio:tokio/src/sync/broadcast.rs:4
use crate::loom::sync::{Arc, Mutex, MutexGuard, RwLock, RwLockReadGuard}; use crate::task::coop::cooperative; 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; ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
121
180
tokio-rs/tokio:tokio/src/sync/broadcast.rs:9
} 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) => wri...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
321
380
tokio-rs/tokio:tokio/src/sync/broadcast.rs:10
/// Next position to write a value. struct Tail { /// 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>::Targ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:11
/// Task waiting on the broadcast channel. waker: Option<Waker>, /// Intrusive linked-list pointers. pointers: linked_list::Pointers<Waiter>, /// Should not be `Unpin`. _p: PhantomPinned, } impl Waiter { fn new() -> Self { Self { queued: AtomicBool::new(false), ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
401
460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
/// /// tokio::spawn(async move { /// assert_eq!(rx1.recv().await.unwrap(), 10); /// assert_eq!(rx1.recv().await.unwrap(), 20); /// }); /// /// tokio::spawn(async move { /// assert_eq!(rx2.recv().await.unwrap(), 10); /// assert_eq!(rx2.recv().await.unwrap(), 20); /// }); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
481
540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:14
impl<T> Sender<T> { /// Creates the sending-half of the [`broadcast`] channel. /// /// See the documentation of [`broadcast::channel`] for more information on this method. /// /// [`broadcast`]: crate::sync::broadcast /// [`broadcast::channel`]: crate::sync::broadcast::channel #[track_caller...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
521
580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
pos: (i as u64).wrapping_sub(capacity as u64), 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:...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
/// handles may be dropped before receiving the sent message. /// /// A return value of `Err` **does not** mean that future calls to `send` /// will fail. New [`Receiver`] handles may be created by calling /// [`subscribe`]. /// /// [`Receiver`]: crate::sync::broadcast::Receiver /// [`subscr...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
// 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(); // ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
/// have been evicted from the queue before being seen by all receivers. /// /// # 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
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
/// let _ = tx.send(10); /// /// assert_eq!(rx1.recv().await.unwrap(), 10); /// drop(rx1); /// assert!(tx.closed().now_or_never().is_none()); /// /// assert_eq!(rx2.recv().await.unwrap(), 10); /// drop(rx2); /// assert!(tx.closed().now_or_never().is_some()); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
pub fn weak_count(&self) -> usize { self.shared.num_weak_tx.load(Acquire) } } /// 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(); assert!(tail.rx_cnt != MAX_RECEIVERS, "max receivers"); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
let _lock_guard = self.shared.tail.lock(); while self.list.pop_back().is_some() {} } } } impl<'a, T> WaitersList<'a, T> { fn new( unguarded_list: LinkedList<Waiter, <Waiter as linked_list::Link>::Target>, guard: Pin<&'a Waiter>, shared: &'a Shared<T>, ) -> Self {...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
// We move all waiters to a secondary list. It uses a `GuardedLinkedList` // underneath to allow every waiter to safely remove itself from it. // // * This list will be still guarded by the `waiters` lock. // `NotifyWaitersList` wrapper makes sure we hold the lock to modify it. ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
1,001
1,060
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
drop(tail); // 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 agai...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
1,041
1,100
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28
/// This will return `Some` if there are other `Sender` instances alive and /// the channel wasn't previously dropped, otherwise `None` is returned. #[must_use] pub fn upgrade(&self) -> Option<Sender<T>> { let mut tx_count = self.shared.num_tx.load(Acquire); loop { if tx_count =...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
1,081
1,140
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29
let shared = self.shared.clone(); shared.num_weak_tx.fetch_add(1, Relaxed); Self { shared } } } impl<T> Drop for WeakSender<T> { fn drop(&mut self) { self.shared.num_weak_tx.fetch_sub(1, AcqRel); } } impl<T> Receiver<T> { /// Returns the number of messages that were sent into ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
1,121
1,180
tokio-rs/tokio:tokio/src/sync/broadcast.rs:31
/// Returns `true` if receivers belong to the same channel. /// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, rx) = broadcast::channel::<()>(16); /// let rx2 = tx.subscribe(); /// /// asser...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
1,201
1,260
tokio-rs/tokio:tokio/src/sync/broadcast.rs:32
// while `send2` acquired the `tail` lock and attempts to acquire // the slot lock. drop(slot); let mut old_waker = None; let mut tail = self.shared.tail.lock(); // Acquire slot lock again slot = self.shared.buffer[idx].read(); // M...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
4380c3d821e661ee193f11e1cedc8287f354f6fb
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4380c3d821e661ee193f11e1cedc8287f354f6fb/tokio/src/sync/broadcast.rs
1,241
1,300