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:33
Some(waker.clone()), ); } } // If the waiter is not already queued, enqueue it. // `Relaxed` order suffices: we have synchronized with ...
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,281
1,340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34
return Ok(RecvGuard { slot }); } 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 sende...
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,321
1,380
tokio-rs/tokio:tokio/src/sync/broadcast.rs:39
/// Blocking receive to call outside of asynchronous contexts. /// /// # Panics /// /// This function panics if called within an asynchronous execution /// context. /// /// # Examples /// ``` /// use std::thread; /// use tokio::sync::broadcast; /// /// #[tokio::main] ...
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,521
1,580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:40
tail.closed = true; } 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(T...
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,561
1,620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:41
(me.receiver, &me.waiter) } } } impl<'a, T> Future for Recv<'a, T> where T: Clone, { type Output = Result<T, RecvError>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> { ready!(crate::trace::trace_leaf(cx)); let (receiver, waiter) = self.proj...
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,601
1,660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:42
// 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. // `Relaxed` order suffices because we hold the tail lock. let queued = 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
1,641
1,700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:43
unsafe fn pointers(target: NonNull<Waiter>) -> NonNull<linked_list::Pointers<Waiter>> { Waiter::addr_of_pointers(target) } } impl<T> fmt::Debug for Sender<T> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "broadcast::Sender") } } impl<T> fmt::Debug for WeakSende...
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,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...
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,721
1,761
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
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
121
180
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
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
281
340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:9
notify_last_rx_drop: Notify, } /// 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, <Wa...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
321
380
tokio-rs/tokio:tokio/src/sync/broadcast.rs:10
/// True if queued. queued: AtomicBool, /// 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 { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12
/// 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(async move { /// ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
441
500
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
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
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
481
540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:14
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
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
521
580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
/// /// 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 /// [`subscribe`]: crate::sync::broadcast::Sender::subscribe /// /// #...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
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(); // Track the position slot.po...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
/// tx.send(20).unwrap(); /// tx.send(30).unwrap(); /// /// assert_eq!(tx.len(), 3); /// /// rx1.recv().await.unwrap(); /// /// // The len is still 3 since rx2 hasn't seen the first value yet. /// assert_eq!(tx.len(), 3); /// /// rx2.recv().await.unwra...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21
/// let tx2 = tx.clone(); /// /// assert!(tx.same_channel(&tx2)); /// /// let (tx3, _rx3) = broadcast::channel::<()>(16); /// /// assert!(!tx3.same_channel(&tx2)); /// } /// ``` pub fn same_channel(&self, other: &Self) -> bool { Arc::ptr_eq(&self.shared, &othe...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
801
860
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
let notified = self.shared.notify_last_rx_drop.notified(); { // Ensure the lock drops if the channel isn't closed let tail = self.shared.tail.lock(); if tail.closed { return; } } notified.await; ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
Receiver { shared, next } } /// List used in `Shared::notify_rx`. It wraps a guarded linked list /// and gates the access to it on the `Shared.tail` mutex. It also empties /// the list on drop. struct WaitersList<'a, T> { list: GuardedLinkedList<Waiter, <Waiter as linked_list::Link>::Target>, is_empty: bool, ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
fn pop_back_locked(&mut self, _tail: &mut Tail) -> Option<NonNull<Waiter>> { let result = self.list.pop_back(); if result.is_none() { // Save information about emptiness to avoid waiting for lock // in the destructor. self.is_empty = true; } result ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
// Safety: `queued` is atomic. let queued = &(*waiter.as_ptr()).queued; // `Relaxed` suffices because the tail lock is held. assert!(queued.load(Relaxed)); // `Release` is needed to synchronize with `Recv::dr...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
shared.num_tx.fetch_add(1, SeqCst); Sender { shared } } } impl<T> Drop for Sender<T> { fn drop(&mut self) { if 1 == self.shared.num_tx.fetch_sub(1, SeqCst) { self.close_channel(); } } } impl<T> Receiver<T> { /// Returns the number of messages that were sent into th...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
1,001
1,060
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28
} /// 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(); /// /// ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
1,081
1,140
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29
// acquires the `slot` lock and attempts to acquire the `tail` lock // while `send2` acquired the `tail` lock and attempts to acquire // the slot lock. drop(slot); let mut old_waker = None; let mut tail = self.shared.tail.lock(); // Acquire slot...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
1,121
1,180
tokio-rs/tokio:tokio/src/sync/broadcast.rs:30
&mut (*ptr).waker, Some(waker.clone()), ); } } // If the waiter is not already queued, enqueue it. // `...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
1,161
1,220
tokio-rs/tokio:tokio/src/sync/broadcast.rs:31
self.next = self.next.wrapping_add(1); return Ok(RecvGuard { slot }); } self.next = next; return Err(TryRecvError::Lagged(missed)); } } self.next = self.next.wrapping_add(1); Ok(RecvGuard { slot }) } } impl...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
1,201
1,260
tokio-rs/tokio:tokio/src/sync/broadcast.rs:35
/// ``` pub fn try_recv(&mut self) -> Result<T, TryRecvError> { let guard = self.recv_ref(None)?; guard.clone_value().ok_or(TryRecvError::Closed) } /// Blocking receive to call outside of asynchronous contexts. /// /// # Panics /// /// This function panics if called within a...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
1,361
1,420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:36
let until = tail.pos; let remaining_rx = tail.rx_cnt; if remaining_rx == 0 { self.shared.notify_last_rx_drop.notify_waiters(); tail.closed = true; } drop(tail); while self.next < until { match self.recv_ref(None) { Ok(_) => {...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
1,401
1,460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:37
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
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
1,441
1,500
tokio-rs/tokio:tokio/src/sync/broadcast.rs:38
// If the waiter is queued, we need to unlink it from the waiters list. // If not, no further synchronization is required, since the waiter // is not in the list and, as such, is not shared with any other threads. if queued { // Acquire the tail lock. This is required for safety befo...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
1,481
1,540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:39
unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> { ptr } unsafe fn pointers(target: NonNull<Waiter>) -> NonNull<linked_list::Pointers<Waiter>> { Waiter::addr_of_pointers(target) } } impl<T> fmt::Debug for Sender<T> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/broadcast.rs
1,521
1,580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:4
use crate::loom::sync::{Arc, Mutex, MutexGuard, RwLock, RwLockReadGuard}; 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::NonNul...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
435e39001b04f5846d1e9db1b243e6b81982f654
github
async-runtime
https://github.com/tokio-rs/tokio/blob/435e39001b04f5846d1e9db1b243e6b81982f654/tokio/src/sync/broadcast.rs
121
180
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21
/// let tx2 = tx.clone(); /// /// assert!(tx.same_channel(&tx2)); /// /// let (tx3, _rx3) = broadcast::channel::<()>(16); /// /// assert!(!tx3.same_channel(&tx2)); /// } /// ``` pub fn same_channel(&self, other: &Self) -> bool { Arc::ptr_eq(&self.shared, &othe...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
801
860
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
/// ``` pub async fn closed(&self) { loop { let notified = self.shared.notify_last_rx_drop.notified(); { // Ensure the lock drops if the channel isn't closed let tail = self.shared.tail.lock(); if tail.closed { retu...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
drop(tail); Receiver { shared, next } } /// List used in `Shared::notify_rx`. It wraps a guarded linked list /// and gates the access to it on the `Shared.tail` mutex. It also empties /// the list on drop. struct WaitersList<'a, T> { list: GuardedLinkedList<Waiter, <Waiter as linked_list::Link>::Target>, ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
/// Removes the last element from the guarded list. Modifying this list /// requires an exclusive access to the main list in `Notify`. fn pop_back_locked(&mut self, _tail: &mut Tail) -> Option<NonNull<Waiter>> { let result = self.list.pop_back(); if result.is_none() { // Save informa...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
wakers.push(waker); } // Safety: `queued` is atomic. let queued = &(*waiter.as_ptr()).queued; // `Relaxed` suffices because the tail lock is held. assert!(queued.load(Relaxed)); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
impl<T> Clone for Sender<T> { fn clone(&self) -> Sender<T> { let shared = self.shared.clone(); shared.num_tx.fetch_add(1, SeqCst); Sender { shared } } } impl<T> Drop for Sender<T> { fn drop(&mut self) { if 1 == self.shared.num_tx.fetch_sub(1, SeqCst) { self.clos...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
1,001
1,060
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28
/// ``` pub fn is_empty(&self) -> bool { self.len() == 0 } /// Returns `true` if receivers belong to the same channel. /// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, rx) = broadcast::ch...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
1,081
1,140
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29
// lock. This is required because `send2` acquires the tail lock // first followed by the slot lock. Acquiring the locks in reverse // order here would result in a potential deadlock: `recv_ref` // acquires the `slot` lock and attempts to acquire the `tail` lock // while ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
1,121
1,180
tokio-rs/tokio:tokio/src/sync/broadcast.rs:30
Some(ref w) if w.will_wake(waker) => {} _ => { old_waker = std::mem::replace( &mut (*ptr).waker, Some(waker.clone()), ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
1,161
1,220
tokio-rs/tokio:tokio/src/sync/broadcast.rs:31
// The receiver is slow but no values have been missed if missed == 0 { self.next = self.next.wrapping_add(1); return Ok(RecvGuard { slot }); } self.next = next; return Err(TryRecvError::Lagged(missed)); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
1,201
1,260
tokio-rs/tokio:tokio/src/sync/broadcast.rs:35
/// 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_value().ok_or(TryRecvError::Closed) } /// Blocking receive to call outside of asynchrono...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
1,361
1,420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:36
let mut tail = self.shared.tail.lock(); tail.rx_cnt -= 1; let until = tail.pos; let remaining_rx = tail.rx_cnt; if remaining_rx == 0 { self.shared.notify_last_rx_drop.notify_waiters(); tail.closed = true; } drop(tail); while self.next <...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
1,401
1,460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:37
/// 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
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
1,441
1,500
tokio-rs/tokio:tokio/src/sync/broadcast.rs:38
let queued = self .waiter .with(|ptr| unsafe { (*ptr).queued.load(Acquire) }); // If the waiter is queued, we need to unlink it from the waiters list. // If not, no further synchronization is required, since the waiter // is not in the list and, as such, is not shared wi...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
1,481
1,540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:39
fn as_raw(handle: &NonNull<Waiter>) -> NonNull<Waiter> { *handle } unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> { ptr } unsafe fn pointers(target: NonNull<Waiter>) -> NonNull<linked_list::Pointers<Waiter>> { Waiter::addr_of_pointers(target) } } impl<T> fmt::...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
1,521
1,580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:40
} } } 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....
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c8cd33820b029ebc8263c461fe03a2cc7f87577
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c8cd33820b029ebc8263c461fe03a2cc7f87577/tokio/src/sync/broadcast.rs
1,561
1,603
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
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/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
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/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
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12
/// assert_eq!(rx1.recv().await.unwrap(), 10); /// assert_eq!(rx1.recv().await.unwrap(), 20); /// }); /// /// tokio::spawn(async move { /// assert_eq!(rx2.recv().await.unwrap(), 10); /// assert_eq!(rx2.recv().await.unwrap(), 20); /// }); /// /// tx.send(10).unwrap(); /// ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
441
500
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
/// [`broadcast`]: crate::sync::broadcast /// [`broadcast::channel`]: crate::sync::broadcast::channel #[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...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
481
540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
/// [`subscribe`]: crate::sync::broadcast::Sender::subscribe /// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, mut rx1) = broadcast::channel(16); /// let mut rx2 = tx.subscribe(); /// /// t...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
// Get the slot let mut slot = self.shared.buffer[idx].write(); // Track the position slot.pos = pos; // Set remaining receivers slot.rem.with_mut(|v| *v = rem); // Write the value slot.val = UnsafeCell::new(Some(value)); // Release the slot lock befor...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
/// /// tx.send(20).unwrap(); /// /// 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....
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
/// /// // The len is still 3 since rx2 hasn't seen the first value yet. /// assert_eq!(tx.len(), 3); /// /// rx2.recv().await.unwrap(); /// /// assert_eq!(tx.len(), 2); /// } /// ``` pub fn len(&self) -> usize { let tail = self.shared.tail.lock(); le...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20
/// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, _rx1) = broadcast::channel(16); /// /// assert_eq!(1, tx.receiver_count()); /// /// let mut _rx2 = tx.subscribe(); /// /// asse...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
761
820
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21
/// assert!(!tx3.same_channel(&tx2)); /// } /// ``` pub fn same_channel(&self, other: &Self) -> bool { Arc::ptr_eq(&self.shared, &other.shared) } fn close_channel(&self) { let mut tail = self.shared.tail.lock(); tail.closed = true; self.shared.notify_rx(tail); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
801
860
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
fn drop(&mut self) { // If the list is not empty, we unlink all waiters from it. // We do not wake the waiters to avoid double panics. if !self.is_empty { let _lock_guard = self.shared.tail.lock(); while self.list.pop_back().is_some() {} } } } impl<'a, T> Wai...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
// It is critical for `GuardedLinkedList` safety that the guard node is // pinned in memory and is not dropped until the guarded list is dropped. let guard = Waiter::new(); pin!(guard); // We move all waiters to a secondary list. It uses a `GuardedLinkedList` // underneath to al...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/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 unnece...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
/// /// assert!(rx.same_channel(&rx2)); /// /// let (_tx3, rx3) = broadcast::channel::<()>(16); /// /// assert!(!rx3.same_channel(&rx2)); /// } /// ``` pub fn same_channel(&self, other: &Self) -> bool { Arc::ptr_eq(&self.shared, &other.shared) } /// Locks the...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
1,041
1,100
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28
// 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 { // At this...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
1,081
1,140
tokio-rs/tokio:tokio/src/sync/broadcast.rs:29
tail.waiters.push_front(NonNull::new_unchecked(&mut *ptr)); } }); } } // Drop the old waker after releasing the locks. drop(slot); drop(tail); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
1,121
1,180
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34
/// # Examples /// ``` /// use std::thread; /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, mut rx) = broadcast::channel(16); /// /// let sync_code = thread::spawn(move || { /// assert_eq!(rx.blocking_recv(), Ok(10)); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/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: 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
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
1,361
1,420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:36
let (receiver, waiter) = self.project(); let guard = match receiver.recv_ref(Some((waiter, cx.waker()))) { Ok(value) => value, Err(TryRecvError::Empty) => return Poll::Pending, Err(TryRecvError::Lagged(n)) => return Poll::Ready(Err(RecvError::Lagged(n))), Err(Try...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
1,401
1,460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:37
// the list. unsafe { self.waiter.with_mut(|ptr| { tail.waiters.remove((&mut *ptr).into()); }); } } } } } /// # Safety /// /// `Waiter` is forced to be !Unpin. unsafe impl linked_list::Link for Waite...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/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.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.fetc...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
1,481
1,540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:39
let rx_3 = sender.subscribe(); 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_construct...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
d4178cf34924d14fca4ecf551c97b8953376f25a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/d4178cf34924d14fca4ecf551c97b8953376f25a/tokio/src/sync/broadcast.rs
1,521
1,541
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
21df16d7595880247642c4fb38f1c365a49de75b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/21df16d7595880247642c4fb38f1c365a49de75b/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
21df16d7595880247642c4fb38f1c365a49de75b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/21df16d7595880247642c4fb38f1c365a49de75b/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
21df16d7595880247642c4fb38f1c365a49de75b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/21df16d7595880247642c4fb38f1c365a49de75b/tokio/src/sync/broadcast.rs
281
340
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
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/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
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/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
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:12
/// assert_eq!(rx1.recv().await.unwrap(), 20); /// }); /// /// tokio::spawn(async move { /// assert_eq!(rx2.recv().await.unwrap(), 10); /// assert_eq!(rx2.recv().await.unwrap(), 20); /// }); /// /// tx.send(10).unwrap(); /// tx.send(20).unwrap(); /// } /// ``` /// /// # Panic...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/broadcast.rs
441
500
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
/// [`broadcast::channel`]: crate::sync::broadcast::channel #[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) c...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/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().aw...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
/// tx.send(20).unwrap(); /// /// 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. ///...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
/// // The len is still 3 since rx2 hasn't seen the first value yet. /// assert_eq!(tx.len(), 3); /// /// rx2.recv().await.unwrap(); /// /// assert_eq!(tx.len(), 2); /// } /// ``` pub fn len(&self) -> usize { let tail = self.shared.tail.lock(); let base_i...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20
/// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, _rx1) = broadcast::channel(16); /// /// assert_eq!(1, tx.receiver_count()); /// /// let mut _rx2 = tx.subscribe(); /// /// assert_eq!(2...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/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 read...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/broadcast.rs
801
860
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
// If the list is not empty, we unlink all waiters from it. // We do not wake the waiters to avoid double panics. if !self.is_empty { let _lock_guard = self.shared.tail.lock(); while self.list.pop_back().is_some() {} } } } impl<'a, T> WaitersList<'a, T> { fn new(...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
// pinned in memory and is not dropped until the guarded list is dropped. let guard = Waiter::new(); pin!(guard); // We move all waiters to a secondary list. It uses a `GuardedLinkedList` // underneath to allow every waiter to safely remove itself from it. // // * This l...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/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 ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
/// assert!(rx.same_channel(&rx2)); /// /// let (_tx3, rx3) = broadcast::channel::<()>(16); /// /// assert!(!rx3.same_channel(&rx2)); /// } /// ``` pub fn same_channel(&self, other: &Self) -> bool { Arc::ptr_eq(&self.shared, &other.shared) } /// Locks the next va...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/broadcast.rs
1,041
1,100
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28
// read lock and acquiring the tail lock. if slot.pos != self.next { let next_pos = slot.pos.wrapping_add(self.shared.buffer.len() as u64); if next_pos == self.next { // At this point the channel is empty for *this* receiver. If // it'...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/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); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/broadcast.rs
1,121
1,180
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().aw...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
11f66f43a09169b893212b854c6c49985ff2224f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
/// tx.send(20).unwrap(); /// /// 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. ///...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
11f66f43a09169b893212b854c6c49985ff2224f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
/// // The len is still 3 since rx2 hasn't seen the first value yet. /// assert_eq!(tx.len(), 3); /// /// rx2.recv().await.unwrap(); /// /// assert_eq!(tx.len(), 2); /// } /// ``` pub fn len(&self) -> usize { let tail = self.shared.tail.lock(); let base_i...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
11f66f43a09169b893212b854c6c49985ff2224f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
/// assert!(rx.same_channel(&rx2)); /// /// let (_tx3, rx3) = broadcast::channel::<()>(16); /// /// assert!(!rx3.same_channel(&rx2)); /// } /// ``` pub fn same_channel(&self, other: &Self) -> bool { Arc::ptr_eq(&self.shared, &other.shared) } /// Locks the next va...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
11f66f43a09169b893212b854c6c49985ff2224f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/11f66f43a09169b893212b854c6c49985ff2224f/tokio/src/sync/broadcast.rs
1,041
1,100
tokio-rs/tokio:tokio/src/sync/broadcast.rs:4
use crate::loom::sync::{Arc, Mutex, MutexGuard, RwLock, RwLockReadGuard}; use crate::util::linked_list::{self, GuardedLinkedList, LinkedList}; use crate::util::WakeList; use std::fmt; use std::future::Future; use std::marker::PhantomPinned; use std::pin::Pin; use std::ptr::NonNull; use std::sync::atomic::Ordering::{Ac...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f5ca423bf1587a17f9c0f02b75d6ad5860b9c029
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f5ca423bf1587a17f9c0f02b75d6ad5860b9c029/tokio/src/sync/broadcast.rs
121
180
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
/// [`subscribe`]: crate::sync::broadcast::Sender::subscribe /// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, mut rx1) = broadcast::channel(16); /// let mut rx2 = tx.subscribe(); /// /// t...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f5ca423bf1587a17f9c0f02b75d6ad5860b9c029
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f5ca423bf1587a17f9c0f02b75d6ad5860b9c029/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
// Get the slot let mut slot = self.shared.buffer[idx].write().unwrap(); // Track the position slot.pos = pos; // Set remaining receivers slot.rem.with_mut(|v| *v = rem); // Write the value slot.val = UnsafeCell::new(Some(value)); // Release the slot l...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f5ca423bf1587a17f9c0f02b75d6ad5860b9c029
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f5ca423bf1587a17f9c0f02b75d6ad5860b9c029/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
/// /// tx.send(20).unwrap(); /// /// 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....
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f5ca423bf1587a17f9c0f02b75d6ad5860b9c029
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f5ca423bf1587a17f9c0f02b75d6ad5860b9c029/tokio/src/sync/broadcast.rs
641
700