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:10
/// tx.send(20).unwrap(); /// } /// ``` pub fn channel<T>(mut capacity: usize) -> (Sender<T>, Receiver<T>) { assert!(capacity > 0, "capacity is empty"); assert!(capacity <= usize::MAX >> 1, "requested capacity too large"); // Round to a power of two capacity = capacity.next_power_of_two(); let...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
cc8a6625982b5fc0694d05b4e9fb7d6a592702a1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cc8a6625982b5fc0694d05b4e9fb7d6a592702a1/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
/// let (tx, _rx) = broadcast::channel(16); /// /// // Will not be seen /// tx.send(10).unwrap(); /// /// let mut rx = tx.subscribe(); /// /// tx.send(20).unwrap(); /// /// let value = rx.recv().await.unwrap(); /// assert_eq!(20, value); /// } ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
cc8a6625982b5fc0694d05b4e9fb7d6a592702a1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cc8a6625982b5fc0694d05b4e9fb7d6a592702a1/tokio/src/sync/broadcast.rs
481
540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:14
/// An active receiver is a [`Receiver`] handle returned from [`channel`] or /// [`subscribe`]. These are the handles that will receive values sent on /// this [`Sender`]. /// /// # Note /// /// It is not guaranteed that a sent message will reach this number of /// receivers. Active receiver...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
cc8a6625982b5fc0694d05b4e9fb7d6a592702a1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cc8a6625982b5fc0694d05b4e9fb7d6a592702a1/tokio/src/sync/broadcast.rs
521
580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
let mut tail = self.shared.tail.lock().unwrap(); if tail.rx_cnt == 0 { return Err(SendError(value)); } // Position to write into let pos = tail.pos; let rem = tail.rx_cnt; let idx = (pos & self.shared.mask as u64) as usize; // Update the tail positi...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
cc8a6625982b5fc0694d05b4e9fb7d6a592702a1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cc8a6625982b5fc0694d05b4e9fb7d6a592702a1/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
self.notify_rx(); Ok(rem) } fn notify_rx(&self) { let mut curr = self.shared.wait_stack.swap(ptr::null_mut(), SeqCst) as *const WaitNode; while !curr.is_null() { let waiter = unsafe { Arc::from_raw(curr) }; // Update `curr` before toggling `queued` and waking ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
cc8a6625982b5fc0694d05b4e9fb7d6a592702a1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cc8a6625982b5fc0694d05b4e9fb7d6a592702a1/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
impl<T> Receiver<T> { /// Locks the next value if there is one. fn recv_ref(&mut self) -> Result<RecvGuard<'_, T>, TryRecvError> { let idx = (self.next & self.shared.mask as u64) as usize; // The slot holding the next value to read let mut slot = self.shared.buffer[idx].read().unwrap();...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
cc8a6625982b5fc0694d05b4e9fb7d6a592702a1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cc8a6625982b5fc0694d05b4e9fb7d6a592702a1/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
drop(tail); // 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
cc8a6625982b5fc0694d05b4e9fb7d6a592702a1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cc8a6625982b5fc0694d05b4e9fb7d6a592702a1/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
/// sent values will overwrite old values. At this point, a call to [`recv`] /// will return with `Err(TryRecvError::Lagged)` and the [`Receiver`]'s /// internal cursor is updated to point to the oldest value still held by /// the channel. A subsequent call to [`try_recv`] will return this value /// **u...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
cc8a6625982b5fc0694d05b4e9fb7d6a592702a1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cc8a6625982b5fc0694d05b4e9fb7d6a592702a1/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21
/// 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(); /// } /// ``` /// /// Handling lag /// /// ``` /...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
cc8a6625982b5fc0694d05b4e9fb7d6a592702a1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cc8a6625982b5fc0694d05b4e9fb7d6a592702a1/tokio/src/sync/broadcast.rs
801
860
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
if !self.wait.queued.load(SeqCst) { // Set `queued` before queuing. self.wait.queued.store(true, SeqCst); let mut curr = self.shared.wait_stack.load(SeqCst); // The ref count is decremented in `notify_rx` when all nodes are // removed from the waiter stack. ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
cc8a6625982b5fc0694d05b4e9fb7d6a592702a1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cc8a6625982b5fc0694d05b4e9fb7d6a592702a1/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
self.poll_recv(cx).map(|v| match v { Ok(v) => Some(Ok(v)), lag @ Err(RecvError::Lagged(_)) => Some(lag), Err(RecvError::Closed) => None, }) } } impl<T> Drop for Receiver<T> { fn drop(&mut self) { let mut tail = self.shared.tail.lock().unwrap(); tail....
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
cc8a6625982b5fc0694d05b4e9fb7d6a592702a1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cc8a6625982b5fc0694d05b4e9fb7d6a592702a1/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
} } impl<T> fmt::Debug for Sender<T> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "broadcast::Sender") } } impl<T> fmt::Debug for Receiver<T> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "broadcast::Receiver") } } impl<'a, T>...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
cc8a6625982b5fc0694d05b4e9fb7d6a592702a1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cc8a6625982b5fc0694d05b4e9fb7d6a592702a1/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
} } impl fmt::Display for RecvError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { RecvError::Closed => write!(f, "channel closed"), RecvError::Lagged(amt) => write!(f, "channel lagged by {}", amt), } } } impl std::error::Error for RecvError {...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
cc8a6625982b5fc0694d05b4e9fb7d6a592702a1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cc8a6625982b5fc0694d05b4e9fb7d6a592702a1/tokio/src/sync/broadcast.rs
961
985
tokio-rs/tokio:tokio/src/sync/broadcast.rs:6
/// /// A **send** operation can only fail if there are no active receivers, /// implying that the message could never be received. The error contains the /// message being sent as a payload so it can be recovered. #[derive(Debug)] pub struct SendError<T>(pub T); /// An error returned from the [`recv`] function on a [...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
201
260
tokio-rs/tokio:tokio/src/sync/broadcast.rs:7
/// retained by the channel. /// /// Includes the number of skipped messages. Lagged(u64), } /// Data shared between senders and receivers struct Shared<T> { /// slots in the channel buffer: Box<[Slot<T>]>, /// Mask a position -> index mask: usize, /// Tail of the queue tail: Mute...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
241
300
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8
struct Slot<T> { /// Remaining number of receivers that are expected to see this value. /// /// When this goes to zero, the value is released. rem: AtomicUsize, /// Used to lock the `write` field. lock: AtomicUsize, /// The value being broadcast /// /// Synchronized by `state` ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
281
340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:10
/// 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
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:11
closed: false, }), condvar: Condvar::new(), wait_stack: AtomicPtr::new(ptr::null_mut()), num_tx: AtomicUsize::new(1), }); let rx = Receiver { shared: shared.clone(), next: 0, wait: Arc::new(WaitNode { queued: AtomicBool::new(false), ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
401
460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
self.send2(Some(value)) .map_err(|SendError(maybe_v)| SendError(maybe_v.unwrap())) } /// Creates a new [`Receiver`] handle that will receive values sent **after** /// this call to `subscribe`. /// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// #[t...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
481
540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:14
Receiver { shared, next, wait: Arc::new(WaitNode { queued: AtomicBool::new(false), waker: AtomicWaker::new(), next: UnsafeCell::new(ptr::null()), }), } } /// Returns the number of active receivers /// ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
521
580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
/// /// let mut _rx2 = tx.subscribe(); /// /// assert_eq!(2, tx.receiver_count()); /// /// tx.send(10).unwrap(); /// } /// ``` pub fn receiver_count(&self) -> usize { let tail = self.shared.tail.lock().unwrap(); tail.rx_cnt } fn send2(&self, value: Op...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
if prev & WRITER == 0 { // The writer lock bit was cleared while this thread was // sleeping. This can only happen if a newer write happened on // this slot by another thread. Bail early as an optimization, // there is nothing left to do. r...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
fn notify_rx(&self) { let mut curr = self.shared.wait_stack.swap(ptr::null_mut(), SeqCst) as *const WaitNode; while !curr.is_null() { let waiter = unsafe { Arc::from_raw(curr) }; // Update `curr` before toggling `queued` and waking curr = waiter.next.with(|ptr| unsa...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
let idx = (self.next & self.shared.mask as u64) as usize; // The slot holding the next value to read let slot = &self.shared.buffer[idx]; // Lock the slot if !slot.try_rx_lock() { if spin { while !slot.try_rx_lock() { spin_loop_hint(); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
.pos .wrapping_sub(self.shared.buffer.len() as u64 + adjust); let missed = next.wrapping_sub(self.next); drop(tail); // The receiver is slow but no values have been missed if missed == 0 { self.next = self.next.wrapping_add(1); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20
/// /// This is useful for a flavor of "optimistic check" before deciding to /// await on a receiver. /// /// Compared with [`recv`], this function has three failure cases instead of one /// (one for closed, one for an empty buffer, one for a lagging receiver). /// /// `Err(TryRecvError::Clo...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
761
820
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21
guard.clone_value().ok_or(TryRecvError::Closed) } #[doc(hidden)] // TODO: document pub fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> { if let Some(value) = ok_empty(self.try_recv())? { return Poll::Ready(Ok(value)); } self.register_waker(cx...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
801
860
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
/// assert_eq!(30, rx.recv().await.unwrap()); /// } pub async fn recv(&mut self) -> Result<T, RecvError> { use crate::future::poll_fn; poll_fn(|cx| self.poll_recv(cx)).await } fn register_waker(&self, cx: &Waker) { self.wait.waker.register_by_ref(cx); if !self.wait...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
#[cfg(feature = "stream")] impl<T> crate::stream::Stream for Receiver<T> where T: Clone, { type Item = Result<T, RecvError>; fn poll_next( mut self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<T, RecvError>>> { self.poll_recv(cx).map(|v| match v { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
} impl<T> Drop for Shared<T> { fn drop(&mut self) { // Clear the wait stack let mut curr = self.wait_stack.with_mut(|ptr| *ptr as *const WaitNode); while !curr.is_null() { let waiter = unsafe { Arc::from_raw(curr) }; curr = waiter.next.with(|ptr| unsafe { *ptr }); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
let res = self .lock .compare_exchange(curr, curr + READER, SeqCst, SeqCst); match res { Ok(_) => return true, Err(actual) => curr = actual, } } } fn rx_unlock(&self, tail: &Mutex<Tail>, condvar: &Condvar, rem_dec:...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
1,001
1,060
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
} fn drop_no_rem_dec(self) { self.slot.rx_unlock(self.tail, self.condvar, false); mem::forget(self); } } impl<'a, T> Drop for RecvGuard<'a, T> { fn drop(&mut self) { self.slot.rx_unlock(self.tail, self.condvar, true) } } fn ok_empty<T>(res: Result<T, TryRecvError>) -> Result<...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a81958484941ddcc2f1955fb6873c827f694ec9b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a81958484941ddcc2f1955fb6873c827f694ec9b/tokio/src/sync/broadcast.rs
1,041
1,086
tokio-rs/tokio:tokio/src/sync/broadcast.rs:7
/// retained by the channel. /// /// Includes the number of skipped messages. Lagged(u64), } /// Data shared between senders and receivers struct Shared<T> { /// slots in the channel buffer: Box<[Slot<T>]>, /// Mask a position -> index mask: usize, /// Tail of the queue tail: Mute...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
241
300
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8
/// When this goes to zero, the value is released. rem: AtomicUsize, /// Used to lock the `write` field. lock: AtomicUsize, /// The value being broadcast /// /// Synchronized by `state` write: Write<T>, } /// A write in the buffer struct Write<T> { /// Uniquely identifies this write ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
281
340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:10
/// assert_eq!(rx2.recv().await.unwrap(), 10); /// assert_eq!(rx2.recv().await.unwrap(), 20); /// }); /// /// tx.send(10).unwrap(); /// tx.send(20).unwrap(); /// } /// ``` pub fn channel<T>(mut capacity: usize) -> (Sender<T>, Receiver<T>) { assert!(capacity > 0, "capacity is empty"); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:11
wait: Arc::new(WaitNode { queued: AtomicBool::new(false), waker: AtomicWaker::new(), next: UnsafeCell::new(ptr::null()), }), }; let tx = Sender { shared }; (tx, rx) } unsafe impl<T: Send> Send for Sender<T> {} unsafe impl<T: Send> Sync for Sender<T> {} unsafe ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
401
460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
/// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, _rx) = broadcast::channel(16); /// /// // Will not be seen /// tx.send(10).unwrap(); /// /// let mut rx = tx.subscribe(); /// /// tx.send(20).unwrap(); /// //...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
481
540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:14
} /// Returns the number of active receivers /// /// An active receiver is a [`Receiver`] handle returned from [`channel`] or /// [`subscribe`]. These are the handles that will receive values sent on /// this [`Sender`]. /// /// # Note /// /// It is not guaranteed that a sent messag...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
521
580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
tail.rx_cnt } fn send2(&self, value: Option<T>) -> Result<usize, SendError<Option<T>>> { let mut tail = self.shared.tail.lock().unwrap(); if tail.rx_cnt == 0 { return Err(SendError(value)); } // Position to write into let pos = tail.pos; let rem = t...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
// There is a newer pending write to the same slot. return Ok(rem); } // Slot lock acquired slot.write.pos.with_mut(|ptr| unsafe { *ptr = pos }); slot.write.val.with_mut(|ptr| unsafe { *ptr = value }); // Set remaining receivers slot.rem.store(rem, SeqCst); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
} } impl<T> Clone for Sender<T> { fn clone(&self) -> Sender<T> { let shared = self.shared.clone(); shared.num_tx.fetch_add(1, SeqCst); Sender { shared } } } impl<T> Drop for Sender<T> { fn drop(&mut self) { if 1 == self.shared.num_tx.fetch_sub(1, SeqCst) { let ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
let guard = RecvGuard { slot, tail: &self.shared.tail, condvar: &self.shared.condvar, }; if guard.pos() != self.next { let pos = guard.pos(); guard.drop_no_rem_dec(); if pos.wrapping_add(self.shared.buffer.len() as u64) == self.n...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
/// Attempts to return a pending value on this receiver without awaiting. /// /// This is useful for a flavor of "optimistic check" before deciding to /// await on a receiver. /// /// Compared with [`recv`], this function has three failure cases instead of one /// (one for closed, one for an emp...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20
let guard = self.recv_ref(false)?; guard.clone_value().ok_or(TryRecvError::Closed) } #[doc(hidden)] // TODO: document pub fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> { if let Some(value) = ok_empty(self.try_recv())? { return Poll::Ready(Ok(value))...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
761
820
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
/// assert_eq!(20, rx.recv().await.unwrap()); /// assert_eq!(30, rx.recv().await.unwrap()); /// } pub async fn recv(&mut self) -> Result<T, RecvError> { use crate::future::poll_fn; poll_fn(|cx| self.poll_recv(cx)).await } fn register_waker(&self, cx: &Waker) { self....
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
#[cfg(feature = "stream")] impl<T> crate::stream::Stream for Receiver<T> where T: Clone, { type Item = Result<T, RecvError>; fn poll_next( mut self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<T, RecvError>>> { self.poll_recv(cx).map(|v| match v { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
} } } impl<T> Drop for Shared<T> { fn drop(&mut self) { // Clear the wait stack let mut curr = self.wait_stack.with_mut(|ptr| *ptr as *const WaitNode); while !curr.is_null() { let waiter = unsafe { Arc::from_raw(curr) }; curr = waiter.next.with(|ptr| unsafe { *p...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
// Only increment (by 2) if the LSB "lock" bit is not set. let res = self.lock.compare_exchange(curr, curr + 2, SeqCst, SeqCst); match res { Ok(_) => return true, Err(actual) => curr = actual, } } } fn rx_unlock(&self, tail: &Mutex<Ta...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
5c71268bb88a1125e822f5a0a68ff996f6811736
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5c71268bb88a1125e822f5a0a68ff996f6811736/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:6
/// A **send** operation can only fail if there are no active receivers, /// implying that the message could never be received. The error contains the /// message being sent as a payload so it can be recovered. #[derive(Debug)] pub struct SendError<T>(pub T); /// An error returned from the [`recv`] function on a [`Rec...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
201
260
tokio-rs/tokio:tokio/src/sync/broadcast.rs:7
/// /// Includes the number of skipped messages. Lagged(u64), } /// Data shared between senders and receivers struct Shared<T> { /// slots in the channel buffer: Box<[Slot<T>]>, /// Mask a position -> index mask: usize, /// Tail of the queue tail: Mutex<Tail>, /// Notifies a send...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
241
300
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8
rem: AtomicUsize, /// Used to lock the `write` field. lock: AtomicUsize, /// The value being broadcast /// /// Synchronized by `state` write: Write<T>, } /// A write in the buffer struct Write<T> { /// Uniquely identifies this write pos: UnsafeCell<u64>, /// The written value ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
281
340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:10
/// assert_eq!(rx2.recv().await.unwrap(), 20); /// }); /// /// tx.send(10).unwrap(); /// tx.send(20).unwrap(); /// } /// ``` pub fn channel<T>(mut capacity: usize) -> (Sender<T>, Receiver<T>) { assert!(capacity > 0, "capacity is empty"); assert!(capacity <= usize::MAX >> 1, "requested capaci...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:11
queued: AtomicBool::new(false), waker: AtomicWaker::new(), next: UnsafeCell::new(ptr::null()), }), }; let tx = Sender { shared }; (tx, rx) } unsafe impl<T: Send> Send for Sender<T> {} unsafe impl<T: Send> Sync for Sender<T> {} unsafe impl<T: Send> Send for Receiver<T> {} ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
401
460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
/// /// #[tokio::main] /// async fn main() { /// let (tx, _rx) = broadcast::channel(16); /// /// // Will not be seen /// tx.send(10).unwrap(); /// /// let mut rx = tx.subscribe(); /// /// tx.send(20).unwrap(); /// /// let value = rx.recv().await.un...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
481
540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:14
/// Returns the number of active receivers /// /// An active receiver is a [`Receiver`] handle returned from [`channel`] or /// [`subscribe`]. These are the handles that will receive values sent on /// this [`Sender`]. /// /// # Note /// /// It is not guaranteed that a sent message will ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
521
580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
} fn send2(&self, value: Option<T>) -> Result<usize, SendError<Option<T>>> { let mut tail = self.shared.tail.lock().unwrap(); if tail.rx_cnt == 0 { return Err(SendError(value)); } // Position to write into let pos = tail.pos; let rem = tail.rx_cnt; ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
return Ok(rem); } // Slot lock acquired slot.write.pos.with_mut(|ptr| unsafe { *ptr = pos }); slot.write.val.with_mut(|ptr| unsafe { *ptr = value }); // Set remaining receivers slot.rem.store(rem, SeqCst); // Release the slot lock slot.lock.store(0, Seq...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
} impl<T> Clone for Sender<T> { fn clone(&self) -> Sender<T> { let shared = self.shared.clone(); shared.num_tx.fetch_add(1, SeqCst); Sender { shared } } } impl<T> Drop for Sender<T> { fn drop(&mut self) { if 1 == self.shared.num_tx.fetch_sub(1, SeqCst) { let _ ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
let guard = RecvGuard { slot, tail: &self.shared.tail, condvar: &self.shared.condvar, }; if guard.pos() != self.next { let pos = guard.pos(); guard.drop_no_rem_dec(); if pos.wrapping_add(self.shared.buffer.len() as u64) == self.n...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
#[cfg(feature = "stream")] impl<T> crate::stream::Stream for Receiver<T> where T: Clone, { type Item = Result<T, RecvError>; fn poll_next( mut self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<T, RecvError>>> { self.poll_recv(cx).map(|v| match v { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
} } impl<T> Drop for Shared<T> { fn drop(&mut self) { // Clear the wait stack let mut curr = self.wait_stack.with_mut(|ptr| *ptr as *const WaitNode); while !curr.is_null() { let waiter = unsafe { Arc::from_raw(curr) }; curr = waiter.next.with(|ptr| unsafe { *ptr });...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
// Only increment (by 2) if the LSB "lock" bit is not set. let res = self.lock.compare_exchange(curr, curr + 2, SeqCst, SeqCst); match res { Ok(_) => return true, Err(actual) => curr = actual, } } } fn rx_unlock(&self, tail: &Mutex<Ta...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
fn drop_no_rem_dec(self) { use std::mem; self.slot.rx_unlock(self.tail, self.condvar, false); mem::forget(self); } } impl<'a, T> Drop for RecvGuard<'a, T> { fn drop(&mut self) { self.slot.rx_unlock(self.tail, self.condvar, true) } } fn ok_empty<T>(res: Result<T, TryRecvEr...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/broadcast.rs
1,001
1,047
tokio-rs/tokio:tokio/src/sync/broadcast.rs:7
/// /// Includes the number of skipped messages. Lagged(u64), } /// Data shared between senders and receivers struct Shared<T> { /// slots in the channel buffer: Box<[Slot<T>]>, /// Mask a position -> index mask: usize, /// Tail of the queue tail: Mutex<Tail>, /// Notifies a send...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
826fc21abfd04779cde92e4cc33de2adb42cf327
github
async-runtime
https://github.com/tokio-rs/tokio/blob/826fc21abfd04779cde92e4cc33de2adb42cf327/tokio/src/sync/broadcast.rs
241
300
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8
rem: AtomicUsize, /// Used to lock the `write` field. lock: AtomicUsize, /// The value being broadcast /// /// Synchronized by `state` write: Write<T>, } /// A write in the buffer struct Write<T> { /// Uniquely identifies this write pos: CausalCell<u64>, /// The written value ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
826fc21abfd04779cde92e4cc33de2adb42cf327
github
async-runtime
https://github.com/tokio-rs/tokio/blob/826fc21abfd04779cde92e4cc33de2adb42cf327/tokio/src/sync/broadcast.rs
281
340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:10
/// assert_eq!(rx2.recv().await.unwrap(), 20); /// }); /// /// tx.send(10).unwrap(); /// tx.send(20).unwrap(); /// } /// ``` pub fn channel<T>(mut capacity: usize) -> (Sender<T>, Receiver<T>) { assert!(capacity > 0, "capacity is empty"); assert!(capacity <= usize::MAX >> 1, "requested capaci...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
826fc21abfd04779cde92e4cc33de2adb42cf327
github
async-runtime
https://github.com/tokio-rs/tokio/blob/826fc21abfd04779cde92e4cc33de2adb42cf327/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:11
queued: AtomicBool::new(false), waker: AtomicWaker::new(), next: CausalCell::new(ptr::null()), }), }; let tx = Sender { shared }; (tx, rx) } unsafe impl<T: Send> Send for Sender<T> {} unsafe impl<T: Send> Sync for Sender<T> {} unsafe impl<T: Send> Send for Receiver<T> {} ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
826fc21abfd04779cde92e4cc33de2adb42cf327
github
async-runtime
https://github.com/tokio-rs/tokio/blob/826fc21abfd04779cde92e4cc33de2adb42cf327/tokio/src/sync/broadcast.rs
401
460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
/// /// #[tokio::main] /// async fn main() { /// let (tx, _rx) = broadcast::channel(16); /// /// // Will not be seen /// tx.send(10).unwrap(); /// /// let mut rx = tx.subscribe(); /// /// tx.send(20).unwrap(); /// /// let value = rx.recv().await.un...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
826fc21abfd04779cde92e4cc33de2adb42cf327
github
async-runtime
https://github.com/tokio-rs/tokio/blob/826fc21abfd04779cde92e4cc33de2adb42cf327/tokio/src/sync/broadcast.rs
481
540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
#[cfg(feature = "stream")] impl<T> crate::stream::Stream for Receiver<T> where T: Clone, { type Item = Result<T, RecvError>; fn poll_next( mut self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<T, RecvError>>> { self.poll_recv(cx).map(|v| match v { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
826fc21abfd04779cde92e4cc33de2adb42cf327
github
async-runtime
https://github.com/tokio-rs/tokio/blob/826fc21abfd04779cde92e4cc33de2adb42cf327/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
} } impl<T> Drop for Shared<T> { fn drop(&mut self) { // Clear the wait stack let mut curr = *self.wait_stack.get_mut() as *const WaitNode; while !curr.is_null() { let waiter = unsafe { Arc::from_raw(curr) }; curr = waiter.next.with(|ptr| unsafe { *ptr }); }...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
826fc21abfd04779cde92e4cc33de2adb42cf327
github
async-runtime
https://github.com/tokio-rs/tokio/blob/826fc21abfd04779cde92e4cc33de2adb42cf327/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
// Only increment (by 2) if the LSB "lock" bit is not set. let res = self.lock.compare_exchange(curr, curr + 2, SeqCst, SeqCst); match res { Ok(_) => return true, Err(actual) => curr = actual, } } } fn rx_unlock(&self, tail: &Mutex<Ta...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f9ddb93604a830d106475bd4c4cae436fafcc0da
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8
rem: AtomicUsize, /// Used to lock the `write` field. lock: AtomicUsize, /// The value being broadcast /// /// Synchronized by `state` write: Write<T>, } /// A write in the buffer struct Write<T> { /// Uniquely identifies this write pos: CausalCell<u64>, /// The written value ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f9ea576ccae5beffeaa2f2c48c2c0d2f9449673b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f9ea576ccae5beffeaa2f2c48c2c0d2f9449673b/tokio/src/sync/broadcast.rs
281
340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
} impl<T> Clone for Sender<T> { fn clone(&self) -> Sender<T> { let shared = self.shared.clone(); shared.num_tx.fetch_add(1, SeqCst); Sender { shared } } } impl<T> Drop for Sender<T> { fn drop(&mut self) { if 1 == self.shared.num_tx.fetch_sub(1, SeqCst) { let _ ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f9ea576ccae5beffeaa2f2c48c2c0d2f9449673b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f9ea576ccae5beffeaa2f2c48c2c0d2f9449673b/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
/// /// This is useful for a flavor of "optimistic check" before deciding to /// await on a receiver. /// /// Compared with [`recv`], this function has three failure cases instead of one /// (one for closed, one for an empty buffer, one for a lagging receiver). /// /// `Err(TryRecvError::Clo...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f9ea576ccae5beffeaa2f2c48c2c0d2f9449673b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f9ea576ccae5beffeaa2f2c48c2c0d2f9449673b/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:20
guard.clone_value().ok_or(TryRecvError::Closed) } #[doc(hidden)] // TODO: document pub fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> { if let Some(value) = ok_empty(self.try_recv())? { return Poll::Ready(Ok(value)); } self.register_waker(cx...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f9ea576ccae5beffeaa2f2c48c2c0d2f9449673b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f9ea576ccae5beffeaa2f2c48c2c0d2f9449673b/tokio/src/sync/broadcast.rs
761
820
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
} } impl<T> Drop for Shared<T> { fn drop(&mut self) { // Clear the wait stack let mut curr = *self.wait_stack.get_mut() as *const WaitNode; while !curr.is_null() { let waiter = unsafe { Arc::from_raw(curr) }; curr = waiter.next.with(|ptr| unsafe { *ptr }); }...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
f9ea576ccae5beffeaa2f2c48c2c0d2f9449673b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/f9ea576ccae5beffeaa2f2c48c2c0d2f9449673b/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:6
/// A **send** operation can only fail if there are no active receivers, /// implying that the message could never be received. The error contains the /// message being sent as a payload so it can be recovered. #[derive(Debug)] pub struct SendError<T>(pub T); /// An error returned from the [`recv`] function on a [`Rec...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
201
260
tokio-rs/tokio:tokio/src/sync/broadcast.rs:7
/// retained by the channel. /// /// Includes the number of skipped messages. Lagged(u64), } /// Data shared between senders and receivers struct Shared<T> { /// slots in the channel buffer: Box<[Slot<T>]>, /// Mask a position -> index mask: usize, /// Tail of the queue tail: Mute...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
241
300
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8
/// When this goes to zero, the value is released. rem: AtomicUsize, /// Used to lock the `write` field. lock: AtomicUsize, /// The value being broadcast /// /// Synchronized by `state` write: Write<T>, } /// A write in the buffer struct Write<T> { /// Uniquely identifies this write ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
281
340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
} fn send2(&self, value: Option<T>) -> Result<usize, SendError<Option<T>>> { let mut tail = self.shared.tail.lock().unwrap(); if tail.rx_cnt == 0 { return Err(SendError(value)); } // Position to write into let pos = tail.pos; let rem = tail.rx_cnt; ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
// Release the slot lock slot.lock.store(0, SeqCst); // Notify waiting receivers self.notify_rx(); Ok(rem) } fn notify_rx(&self) { let mut curr = self.shared.wait_stack.swap(ptr::null_mut(), SeqCst) as *const WaitNode; while !curr.is_null() { let w...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
} } } impl<T> Receiver<T> { /// Lock the next value if there is one. /// /// The caller is responsible for unlocking fn recv_ref(&mut self, spin: bool) -> Result<RecvGuard<'_, T>, TryRecvError> { let idx = (self.next & self.shared.mask as u64) as usize; // The slot holding the next...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:18
// `tail.pos` points to the slot the **next** send writes to. // Because a receiver is lagging, this slot also holds the // oldest value. To make the positions match, we subtract the // capacity. let next = tail.pos.wrapping_sub(self.shared.buffer.len() as...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
681
740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
/// receive, `Err(TryRecvError::Empty)` is returned. /// /// [`recv`]: crate::sync::broadcast::Receiver::recv /// [`Receiver`]: crate::sync::broadcast::Receiver /// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { ///...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:21
/// tx.send(10).unwrap(); /// tx.send(20).unwrap(); /// } /// ``` /// /// Handling lag /// /// ``` /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, mut rx) = broadcast::channel(2); /// /// tx.send(10).unwrap...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
801
860
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
// The ref count is decremented in `notify_rx` when all nodes are // removed from the waiter stack. let node = Arc::into_raw(self.wait.clone()) as *mut _; loop { // Safety: `queued == false` means the caller has exclusive // access to `self.wait.next`...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
} } impl<T> Drop for Receiver<T> { fn drop(&mut self) { let mut tail = self.shared.tail.lock().unwrap(); tail.rx_cnt -= 1; let until = tail.pos; drop(tail); while self.next != until { match self.recv_ref(true) { // Ignore the value ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "broadcast::Sender") } } impl<T> fmt::Debug for Receiver<T> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "broadcast::Receiver") } } impl<T> Slot<T> { /// Try to lock the slot for a re...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
} } let prev = self.lock.fetch_sub(2, SeqCst); if prev & 1 == 1 { // Sender waiting for lock condvar.notify_one(); } } } impl<'a, T> RecvGuard<'a, T> { fn pos(&self) -> u64 { self.slot.write.pos.with(|ptr| unsafe { *ptr }) } fn clone_va...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
match res { Ok(value) => Ok(Some(value)), Err(TryRecvError::Empty) => Ok(None), Err(TryRecvError::Lagged(n)) => Err(RecvError::Lagged(n)), Err(TryRecvError::Closed) => Err(RecvError::Closed), } } impl fmt::Display for RecvError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt:...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
0bb17300f70ef74e335f4ada65706872451603b3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0bb17300f70ef74e335f4ada65706872451603b3/tokio/src/sync/broadcast.rs
1,001
1,030
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
} } let prev = self.lock.fetch_sub(2, SeqCst); if prev & 1 == 1 { // Sender waiting for lock condvar.notify_one(); } } } impl<'a, T> RecvGuard<'a, T> { fn pos(&self) -> u64 { self.slot.write.pos.with(|ptr| unsafe { *ptr }) } fn clone_va...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
84ff73e687932d77a1163167b938631b1104d54f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/84ff73e687932d77a1163167b938631b1104d54f/tokio/src/sync/broadcast.rs
961
1,007
tokio-rs/tokio:tokio/src/sync/broadcast.rs:6
/// implying that the message could never be received. The error contains the /// message being sent as a payload so it can be recovered. #[derive(Debug)] pub struct SendError<T>(pub T); /// An error returned from the [`recv`] function on a [`Receiver`]. /// /// [`recv`]: crate::sync::broadcast::Receiver::recv /// [`R...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a8540948254ec69c630bacd0b4a58a20d701b7ac
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a8540948254ec69c630bacd0b4a58a20d701b7ac/tokio/src/sync/broadcast.rs
201
260
tokio-rs/tokio:tokio/src/sync/broadcast.rs:7
/// /// Includes the number of skipped messages. Lagged(u64), } /// Data shared between senders and receivers struct Shared<T> { /// slots in the channel buffer: Box<[Slot<T>]>, /// Mask a position -> index mask: usize, /// Tail of the queue tail: Mutex<Tail>, /// Notifies a send...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a8540948254ec69c630bacd0b4a58a20d701b7ac
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a8540948254ec69c630bacd0b4a58a20d701b7ac/tokio/src/sync/broadcast.rs
241
300
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8
rem: AtomicUsize, /// Used to lock the `write` field. lock: AtomicUsize, /// The value being broadcast /// /// Synchronized by `state` write: Write<T>, } /// A write in the buffer struct Write<T> { /// Uniquely identifies this write pos: CausalCell<u64>, /// The written value ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a8540948254ec69c630bacd0b4a58a20d701b7ac
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a8540948254ec69c630bacd0b4a58a20d701b7ac/tokio/src/sync/broadcast.rs
281
340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:10
/// }); /// /// tx.send(10).unwrap(); /// tx.send(20).unwrap(); /// } /// ``` pub fn channel<T>(mut capacity: usize) -> (Sender<T>, Receiver<T>) { assert!(capacity > 0, "capacity is empty"); assert!(capacity <= usize::MAX >> 1, "requested capacity too large"); // Round to a power of two cap...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a8540948254ec69c630bacd0b4a58a20d701b7ac
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a8540948254ec69c630bacd0b4a58a20d701b7ac/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
/// #[tokio::main] /// async fn main() { /// let (tx, _rx) = broadcast::channel(16); /// /// // Will not be seen /// tx.send(10).unwrap(); /// /// let mut rx = tx.subscribe(); /// /// tx.send(20).unwrap(); /// /// let value = rx.recv().await.unwrap(); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a8540948254ec69c630bacd0b4a58a20d701b7ac
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a8540948254ec69c630bacd0b4a58a20d701b7ac/tokio/src/sync/broadcast.rs
481
540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:14
/// Returns the number of active receivers /// /// An active receiver is a [`Receiver`] handle returned from [`channel`] or /// [`subscribe`]. These are the handles that will receive values sent on /// this [`Sender`]. /// /// # Note /// /// It is not guaranteed that a sent message will ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a8540948254ec69c630bacd0b4a58a20d701b7ac
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a8540948254ec69c630bacd0b4a58a20d701b7ac/tokio/src/sync/broadcast.rs
521
580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
fn send2(&self, value: Option<T>) -> Result<usize, SendError<Option<T>>> { let mut tail = self.shared.tail.lock().unwrap(); if tail.rx_cnt == 0 { return Err(SendError(value)); } // Position to write into let pos = tail.pos; let rem = tail.rx_cnt; let...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a8540948254ec69c630bacd0b4a58a20d701b7ac
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a8540948254ec69c630bacd0b4a58a20d701b7ac/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
slot.lock.store(0, SeqCst); // Notify waiting receivers self.notify_rx(); Ok(rem) } fn notify_rx(&self) { let mut curr = self.shared.wait_stack.swap(ptr::null_mut(), SeqCst) as *const WaitNode; while !curr.is_null() { let waiter = unsafe { Arc::from_raw(cu...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a8540948254ec69c630bacd0b4a58a20d701b7ac
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a8540948254ec69c630bacd0b4a58a20d701b7ac/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
} } impl<T> Receiver<T> { /// Lock the next value if there is one. /// /// The caller is responsible for unlocking fn recv_ref(&mut self, spin: bool) -> Result<RecvGuard<'_, T>, TryRecvError> { let idx = (self.next & self.shared.mask as u64) as usize; // The slot holding the next value...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
a8540948254ec69c630bacd0b4a58a20d701b7ac
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a8540948254ec69c630bacd0b4a58a20d701b7ac/tokio/src/sync/broadcast.rs
641
700