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/batch_semaphore.rs:13
// a `Waiter`, which, in turn, contains an `UnsafeCell`. However, the // `UnsafeCell` is only accessed when the future is borrowed mutably (either in // `poll` or in `drop`). Therefore, it is safe (although not particularly // _useful_) for the future to be borrowed immutably across threads. unsafe impl Sync for Acquir...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
c344aac9252c34fcce196200a99529734b5cb9e8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c344aac9252c34fcce196200a99529734b5cb9e8/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14
_ => false, } } } impl fmt::Display for TryAcquireError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match self { TryAcquireError::Closed => write!(fmt, "semaphore closed"), TryAcquireError::NoPermits => write!(fmt, "no permits available"), } ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
c344aac9252c34fcce196200a99529734b5cb9e8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c344aac9252c34fcce196200a99529734b5cb9e8/tokio/src/sync/batch_semaphore.rs
521
561
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:1
//! # Implementation Details //! //! The semaphore is implemented using an intrusive linked list of waiters. An //! atomic counter tracks the number of available permits. If the semaphore does //! not contain the required number of permits, the task attempting to acquire //! permits places its waker at the end of a que...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
1
60
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:2
} /// Error returned by `Semaphore::try_acquire`. #[derive(Debug)] pub(crate) enum TryAcquireError { Closed, NoPermits, } /// Error returned by `Semaphore::acquire`. #[derive(Debug)] pub(crate) struct AcquireError(()); pub(crate) struct Acquire<'a> { node: Waiter, semaphore: &'a Semaphore, num_per...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
41
100
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:3
/// TODO: Ideally, we would be able to use loom to enforce that /// this isn't accessed concurrently. However, it is difficult to /// use a `UnsafeCell` here, since the `Link` trait requires _returning_ /// references to `Pointers`, and `UnsafeCell` requires that checked access /// take place inside a c...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
81
140
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4
/// Returns the current number of available permits pub(crate) fn available_permits(&self) -> usize { self.permits.load(Acquire) >> Self::PERMIT_SHIFT } /// Adds `added` new permits to the semaphore. /// /// The maximum number of permits is `usize::MAX >> 3`, and this function will panic if...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
121
180
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5
pub(crate) fn try_acquire(&self, num_permits: u16) -> Result<(), TryAcquireError> { let mut curr = self.permits.load(Acquire); let num_permits = (num_permits as usize) << Self::PERMIT_SHIFT; loop { // Has the semaphore closed?git if curr & Self::CLOSED > 0 { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
161
220
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6
// Was the waiter assigned enough permits to wake it? match waiters.queue.last() { Some(waiter) => { if !waiter.assign_permits(&mut rem) { break 'inner; } } None => { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
201
260
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7
.for_each(Waker::wake); } assert_eq!(rem, 0); } fn poll_acquire( &self, cx: &mut Context<'_>, num_permits: u16, node: Pin<&mut Waiter>, queued: bool, ) -> Poll<Result<(), AcquireError>> { let mut acquired = 0; let needed = if queued ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
241
300
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8
(0, curr >> Self::PERMIT_SHIFT) }; if remaining > 0 && lock.is_none() { // No permits were immediately available, so this permit will // (probably) need to wait. We'll need to acquire a lock on the // wait queue before continuing. We need to do th...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
281
340
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9
// Otherwise, register the waker & enqueue the node. node.waker.with_mut(|waker| { // Safety: the wait list is locked, so we may modify the waker. let waker = unsafe { &mut *waker }; // Do we need to register the new waker? if waker .as_ref() ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
321
380
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10
waker: UnsafeCell::new(None), state: AtomicUsize::new(num_permits as usize), pointers: linked_list::Pointers::new(), _p: PhantomPinned, } } /// Assign permits to the waiter. /// /// Returns `true` if the waiter should be removed from the queue fn assign_p...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
361
420
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11
Ready(r) => { coop.made_progress(); r?; *queued = false; Ready(Ok(())) } } } } impl<'a> Acquire<'a> { fn new(semaphore: &'a Semaphore, num_permits: u16) -> Self { Self { node: Waiter::new(num_permits), ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
401
460
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
impl Drop for Acquire<'_> { fn drop(&mut self) { // If the future is completed, there is no node in the wait list, so we // can skip acquiring the lock. if !self.queued { return; } // This is where we ensure safety. The future is being dropped, // which m...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
441
500
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
impl AcquireError { fn closed() -> AcquireError { AcquireError(()) } } impl fmt::Display for AcquireError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "semaphore closed") } } impl std::error::Error for AcquireError {} // ===== impl TryAcquireError ===== ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14
match self { TryAcquireError::Closed => write!(fmt, "semaphore closed"), TryAcquireError::NoPermits => write!(fmt, "no permits available"), } } } impl std::error::Error for TryAcquireError {} /// # Safety /// /// `Waiter` is forced to be !Unpin. unsafe impl linked_list::Link for Wa...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
4010335c84517571e9b2d13f66f7c72170493622
github
async-runtime
https://github.com/tokio-rs/tokio/blob/4010335c84517571e9b2d13f66f7c72170493622/tokio/src/sync/batch_semaphore.rs
521
554
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
impl AcquireError { fn closed() -> AcquireError { AcquireError(()) } } impl fmt::Display for AcquireError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "semaphore closed") } } impl std::error::Error for AcquireError {} // ===== impl TryAcquireError ===== ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
9f63911adc5b809fd3df7cfbb736897a86895e0c
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9f63911adc5b809fd3df7cfbb736897a86895e0c/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14
match self { TryAcquireError::Closed => write!(fmt, "{}", "semaphore closed"), TryAcquireError::NoPermits => write!(fmt, "{}", "no permits available"), } } } impl std::error::Error for TryAcquireError {} /// # Safety /// /// `Waiter` is forced to be !Unpin. unsafe impl linked_list:...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
9f63911adc5b809fd3df7cfbb736897a86895e0c
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9f63911adc5b809fd3df7cfbb736897a86895e0c/tokio/src/sync/batch_semaphore.rs
521
554
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10
waker: UnsafeCell::new(None), state: AtomicUsize::new(num_permits as usize), pointers: linked_list::Pointers::new(), _p: PhantomPinned, } } /// Assign permits to the waiter. /// /// Returns `true` if the waiter should be removed from the queue fn assign_p...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a5c1a7de0399625792b476666ea1326cb8bcd75c
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a5c1a7de0399625792b476666ea1326cb8bcd75c/tokio/src/sync/batch_semaphore.rs
361
420
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11
Ready(r) => { r?; *queued = false; Ready(Ok(())) } } } } impl<'a> Acquire<'a> { fn new(semaphore: &'a Semaphore, num_permits: u16) -> Self { Self { node: Waiter::new(num_permits), semaphore, num_perm...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a5c1a7de0399625792b476666ea1326cb8bcd75c
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a5c1a7de0399625792b476666ea1326cb8bcd75c/tokio/src/sync/batch_semaphore.rs
401
460
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
fn drop(&mut self) { // If the future is completed, there is no node in the wait list, so we // can skip acquiring the lock. if !self.queued { return; } // This is where we ensure safety. The future is being dropped, // which means we must ensure that the wai...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a5c1a7de0399625792b476666ea1326cb8bcd75c
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a5c1a7de0399625792b476666ea1326cb8bcd75c/tokio/src/sync/batch_semaphore.rs
441
500
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
impl AcquireError { fn closed() -> AcquireError { AcquireError(()) } } impl fmt::Display for AcquireError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "semaphore closed") } } impl std::error::Error for AcquireError {} // ===== impl TryAcquireError ===== ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a5c1a7de0399625792b476666ea1326cb8bcd75c
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a5c1a7de0399625792b476666ea1326cb8bcd75c/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14
TryAcquireError::Closed => write!(fmt, "{}", "semaphore closed"), TryAcquireError::NoPermits => write!(fmt, "{}", "no permits available"), } } } impl std::error::Error for TryAcquireError {} /// # Safety /// /// `Waiter` is forced to be !Unpin. unsafe impl linked_list::Link for Waiter { //...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a5c1a7de0399625792b476666ea1326cb8bcd75c
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a5c1a7de0399625792b476666ea1326cb8bcd75c/tokio/src/sync/batch_semaphore.rs
521
553
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:3
/// TODO: Ideally, we would be able to use loom to enforce that /// this isn't accessed concurrently. However, it is difficult to /// use a `UnsafeCell` here, since the `Link` trait requires _returning_ /// references to `Pointers`, and `UnsafeCell` requires that checked access /// take place inside a c...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
fb7dfcf4322b5e60604815aea91266b88f0b7823
github
async-runtime
https://github.com/tokio-rs/tokio/blob/fb7dfcf4322b5e60604815aea91266b88f0b7823/tokio/src/sync/batch_semaphore.rs
81
140
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4
/// Returns the current number of available permits pub(crate) fn available_permits(&self) -> usize { self.permits.load(Acquire) >> Self::PERMIT_SHIFT } /// Adds `n` new permits to the semaphore. pub(crate) fn release(&self, added: usize) { if added == 0 { return; } ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
fb7dfcf4322b5e60604815aea91266b88f0b7823
github
async-runtime
https://github.com/tokio-rs/tokio/blob/fb7dfcf4322b5e60604815aea91266b88f0b7823/tokio/src/sync/batch_semaphore.rs
121
180
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5
let mut curr = self.permits.load(Acquire); let num_permits = (num_permits as usize) << Self::PERMIT_SHIFT; loop { // Has the semaphore closed?git if curr & Self::CLOSED > 0 { return Err(TryAcquireError::Closed); } // Are there enough permi...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
fb7dfcf4322b5e60604815aea91266b88f0b7823
github
async-runtime
https://github.com/tokio-rs/tokio/blob/fb7dfcf4322b5e60604815aea91266b88f0b7823/tokio/src/sync/batch_semaphore.rs
161
220
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6
Some(waiter) => { if !waiter.assign_permits(&mut rem) { break 'inner; } } None => { is_empty = true; // If we assigned permits to all the waiters in the que...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
fb7dfcf4322b5e60604815aea91266b88f0b7823
github
async-runtime
https://github.com/tokio-rs/tokio/blob/fb7dfcf4322b5e60604815aea91266b88f0b7823/tokio/src/sync/batch_semaphore.rs
201
260
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7
assert_eq!(rem, 0); } fn poll_acquire( &self, cx: &mut Context<'_>, num_permits: u16, node: Pin<&mut Waiter>, queued: bool, ) -> Poll<Result<(), AcquireError>> { let mut acquired = 0; let needed = if queued { node.state.load(Acquire) << S...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
fb7dfcf4322b5e60604815aea91266b88f0b7823
github
async-runtime
https://github.com/tokio-rs/tokio/blob/fb7dfcf4322b5e60604815aea91266b88f0b7823/tokio/src/sync/batch_semaphore.rs
241
300
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8
if remaining > 0 && lock.is_none() { // No permits were immediately available, so this permit will // (probably) need to wait. We'll need to acquire a lock on the // wait queue before continuing. We need to do this _before_ the // CAS that sets the new val...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
fb7dfcf4322b5e60604815aea91266b88f0b7823
github
async-runtime
https://github.com/tokio-rs/tokio/blob/fb7dfcf4322b5e60604815aea91266b88f0b7823/tokio/src/sync/batch_semaphore.rs
281
340
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9
node.waker.with_mut(|waker| { // Safety: the wait list is locked, so we may modify the waker. let waker = unsafe { &mut *waker }; // Do we need to register the new waker? if waker .as_ref() .map(|waker| !waker.will_wake(cx.waker())) ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
fb7dfcf4322b5e60604815aea91266b88f0b7823
github
async-runtime
https://github.com/tokio-rs/tokio/blob/fb7dfcf4322b5e60604815aea91266b88f0b7823/tokio/src/sync/batch_semaphore.rs
321
380
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10
pointers: linked_list::Pointers::new(), _p: PhantomPinned, } } /// Assign permits to the waiter. /// /// Returns `true` if the waiter should be removed from the queue fn assign_permits(&self, n: &mut usize) -> bool { let mut curr = self.state.load(Acquire); loop ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
fb7dfcf4322b5e60604815aea91266b88f0b7823
github
async-runtime
https://github.com/tokio-rs/tokio/blob/fb7dfcf4322b5e60604815aea91266b88f0b7823/tokio/src/sync/batch_semaphore.rs
361
420
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11
*queued = false; Ready(Ok(())) } } } } impl<'a> Acquire<'a> { fn new(semaphore: &'a Semaphore, num_permits: u16) -> Self { Self { node: Waiter::new(num_permits), semaphore, num_permits, queued: false, } } ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
fb7dfcf4322b5e60604815aea91266b88f0b7823
github
async-runtime
https://github.com/tokio-rs/tokio/blob/fb7dfcf4322b5e60604815aea91266b88f0b7823/tokio/src/sync/batch_semaphore.rs
401
460
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
// can skip acquiring the lock. if !self.queued { return; } // This is where we ensure safety. The future is being dropped, // which means we must ensure that the waiter entry is no longer stored // in the linked list. let mut waiters = match self.semaphore.w...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
fb7dfcf4322b5e60604815aea91266b88f0b7823
github
async-runtime
https://github.com/tokio-rs/tokio/blob/fb7dfcf4322b5e60604815aea91266b88f0b7823/tokio/src/sync/batch_semaphore.rs
441
500
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
AcquireError(()) } } impl fmt::Display for AcquireError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "semaphore closed") } } impl std::error::Error for AcquireError {} // ===== impl TryAcquireError ===== impl TryAcquireError { /// Returns `true` if the error was...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
fb7dfcf4322b5e60604815aea91266b88f0b7823
github
async-runtime
https://github.com/tokio-rs/tokio/blob/fb7dfcf4322b5e60604815aea91266b88f0b7823/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10
pointers: linked_list::Pointers::new(), _p: PhantomPinned, } } /// Assign permits to the waiter. /// /// Returns `true` if the waiter should be removed from the queue fn assign_permits(&self, n: &mut usize) -> bool { let mut curr = self.state.load(Acquire); loop ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1121a8eb23f6f0edd9f41cdc08331d40e18105ee
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1121a8eb23f6f0edd9f41cdc08331d40e18105ee/tokio/src/sync/batch_semaphore.rs
361
420
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11
} } impl<'a> Acquire<'a> { fn new(semaphore: &'a Semaphore, num_permits: u16) -> Self { Self { node: Waiter::new(num_permits), semaphore, num_permits, queued: false, } } fn project(self: Pin<&mut Self>) -> (Pin<&mut Waiter>, &Semaphore, u16, ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1121a8eb23f6f0edd9f41cdc08331d40e18105ee
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1121a8eb23f6f0edd9f41cdc08331d40e18105ee/tokio/src/sync/batch_semaphore.rs
401
460
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
// This is where we ensure safety. The future is being dropped, // which means we must ensure that the waiter entry is no longer stored // in the linked list. let mut waiters = match self.semaphore.waiters.lock() { Ok(lock) => lock, // Removing the node from the linked li...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1121a8eb23f6f0edd9f41cdc08331d40e18105ee
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1121a8eb23f6f0edd9f41cdc08331d40e18105ee/tokio/src/sync/batch_semaphore.rs
441
500
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
impl fmt::Display for AcquireError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "semaphore closed") } } impl std::error::Error for AcquireError {} // ===== impl TryAcquireError ===== impl TryAcquireError { /// Returns `true` if the error was caused by a closed semaph...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1121a8eb23f6f0edd9f41cdc08331d40e18105ee
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1121a8eb23f6f0edd9f41cdc08331d40e18105ee/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
// This is where we ensure safety. The future is being dropped, // which means we must ensure that the waiter entry is no longer stored // in the linked list. let mut waiters = match self.semaphore.waiters.lock() { Ok(lock) => lock, // Removing the node from the linked li...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
00725f6876821f2ec5246a807563e35c5e53f3e1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/00725f6876821f2ec5246a807563e35c5e53f3e1/tokio/src/sync/batch_semaphore.rs
441
500
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
// ===== impl TryAcquireError ===== impl TryAcquireError { /// Returns `true` if the error was caused by a closed semaphore. #[allow(dead_code)] // may be used later! pub(crate) fn is_closed(&self) -> bool { match self { TryAcquireError::Closed => true, _ => false, }...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
00725f6876821f2ec5246a807563e35c5e53f3e1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/00725f6876821f2ec5246a807563e35c5e53f3e1/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14
// invariant that list entries may not move while in the list. However, we // can't do this currently, as using `Pin<&'a mut Waiter>` as the `Handle` // type would require `Semaphore` to be generic over a lifetime. We can't // use `Pin<*mut Waiter>`, as raw pointers are `Unpin` regardless of whether // ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
00725f6876821f2ec5246a807563e35c5e53f3e1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/00725f6876821f2ec5246a807563e35c5e53f3e1/tokio/src/sync/batch_semaphore.rs
521
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:3
/// TODO: Ideally, we would be able to use loom to enforce that /// this isn't accessed concurrently. However, it is difficult to /// use a `UnsafeCell` here, since the `Link` trait requires _returning_ /// references to `Pointers`, and `UnsafeCell` requires that checked access /// take place inside a c...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/batch_semaphore.rs
81
140
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4
/// Returns the current number of available permits pub(crate) fn available_permits(&self) -> usize { self.permits.load(Acquire) >> Self::PERMIT_SHIFT } /// Adds `n` new permits to the semaphore. pub(crate) fn release(&self, added: usize) { if added == 0 { return; } ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/batch_semaphore.rs
121
180
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5
} pub(crate) fn try_acquire(&self, num_permits: u16) -> Result<(), TryAcquireError> { let mut curr = self.permits.load(Acquire); let num_permits = (num_permits as usize) << Self::PERMIT_SHIFT; loop { // Has the semaphore closed?git if curr & Self::CLOSED > 0 { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/batch_semaphore.rs
161
220
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6
mut rem: usize, mut waiters: MutexGuard<'_, Waitlist>, ) -> LinkedList<Waiter> { // Starting from the back of the wait queue, assign each waiter as many // permits as it needs until we run out of permits to assign. let mut last = None; for waiter in waiters.queue.iter().rev()...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/batch_semaphore.rs
201
260
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7
} else { LinkedList::new() } } fn poll_acquire( &self, cx: &mut Context<'_>, num_permits: u16, node: Pin<&mut Waiter>, queued: bool, ) -> Poll<Result<(), AcquireError>> { let mut acquired = 0; let needed = if queued { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/batch_semaphore.rs
241
300
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8
}; if remaining > 0 && lock.is_none() { // No permits were immediately available, so this permit will // (probably) need to wait. We'll need to acquire a lock on the // wait queue before continuing. We need to do this _before_ the // CAS that ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/batch_semaphore.rs
281
340
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9
// Otherwise, register the waker & enqueue the node. node.waker.with_mut(|waker| { // Safety: the wait list is locked, so we may modify the waker. let waker = unsafe { &mut *waker }; // Do we need to register the new waker? if waker .as_ref() ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/batch_semaphore.rs
321
380
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10
let waker = unsafe { waiter.as_ref().waker.with_mut(|waker| (*waker).take()) }; waker .expect("if a node is in the wait list, it must have a waker") .wake(); } } impl Waiter { fn new(num_permits: u16) -> Self { Waiter { waker: UnsafeCell::new(None), ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/batch_semaphore.rs
361
420
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { let (node, semaphore, needed, queued) = self.project(); match semaphore.poll_acquire(cx, needed, node, *queued) { Pending => { *queued = true; Pending } Ready(r...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/batch_semaphore.rs
401
460
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
&mut this.queued, ) } } } impl Drop for Acquire<'_> { fn drop(&mut self) { // If the future is completed, there is no node in the wait list, so we // can skip acquiring the lock. if !self.queued { return; } // This is where we ensure safe...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
1cb1e291c10adf6b4e530cb1475b95ba10fa615f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/sync/batch_semaphore.rs
441
500
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:1
//! # Implementation Details //! //! The semaphore is implemented using an intrusive linked list of waiters. An //! atomic counter tracks the number of available permits. If the semaphore does //! not contain the required number of permits, the task attempting to acquire //! permits places its waker at the end of a que...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
acf8a7da7a64bf08d578db9a9836a8e061765314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/batch_semaphore.rs
1
60
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:2
/// Error returned by `Semaphore::try_acquire`. #[derive(Debug)] pub(crate) enum TryAcquireError { Closed, NoPermits, } /// Error returned by `Semaphore::acquire`. #[derive(Debug)] pub(crate) struct AcquireError(()); pub(crate) struct Acquire<'a> { node: Waiter, semaphore: &'a Semaphore, num_permit...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
acf8a7da7a64bf08d578db9a9836a8e061765314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/batch_semaphore.rs
41
100
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:3
/// this isn't accessed concurrently. However, it is difficult to /// use a `CausalCell` here, since the `Link` trait requires _returning_ /// references to `Pointers`, and `CausalCell` requires that checked access /// take place inside a closure. We should consider changing `Pointers` to /// use `Causa...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
acf8a7da7a64bf08d578db9a9836a8e061765314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/batch_semaphore.rs
81
140
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4
pub(crate) fn available_permits(&self) -> usize { self.permits.load(Acquire) >> Self::PERMIT_SHIFT } /// Adds `n` new permits to the semaphore. pub(crate) fn release(&self, added: usize) { if added == 0 { return; } // Assign permits to the wait queue, returning ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
acf8a7da7a64bf08d578db9a9836a8e061765314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/batch_semaphore.rs
121
180
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5
pub(crate) fn try_acquire(&self, num_permits: u16) -> Result<(), TryAcquireError> { let mut curr = self.permits.load(Acquire); let num_permits = (num_permits as usize) << Self::PERMIT_SHIFT; loop { // Has the semaphore closed?git if curr & Self::CLOSED > 0 { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
acf8a7da7a64bf08d578db9a9836a8e061765314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/batch_semaphore.rs
161
220
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6
mut waiters: MutexGuard<'_, Waitlist>, ) -> LinkedList<Waiter> { // Starting from the back of the wait queue, assign each waiter as many // permits as it needs until we run out of permits to assign. let mut last = None; for waiter in waiters.queue.iter().rev() { // Was th...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
acf8a7da7a64bf08d578db9a9836a8e061765314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/batch_semaphore.rs
201
260
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7
LinkedList::new() } } fn poll_acquire( &self, cx: &mut Context<'_>, num_permits: u16, node: Pin<&mut Waiter>, queued: bool, ) -> Poll<Result<(), AcquireError>> { let mut acquired = 0; let needed = if queued { node.state.load(Acqui...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
acf8a7da7a64bf08d578db9a9836a8e061765314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/batch_semaphore.rs
241
300
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9
node.waker.with_mut(|waker| { // Safety: the wait list is locked, so we may modify the waker. let waker = unsafe { &mut *waker }; // Do we need to register the new waker? if waker .as_ref() .map(|waker| !waker.will_wake(cx.waker())) ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
acf8a7da7a64bf08d578db9a9836a8e061765314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/batch_semaphore.rs
321
380
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10
waker .expect("if a node is in the wait list, it must have a waker") .wake(); } } impl Waiter { fn new(num_permits: u16) -> Self { Waiter { waker: CausalCell::new(None), state: AtomicUsize::new(num_permits as usize), pointers: linked_list::Poi...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
acf8a7da7a64bf08d578db9a9836a8e061765314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/batch_semaphore.rs
361
420
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11
let (node, semaphore, needed, queued) = self.project(); match semaphore.poll_acquire(cx, needed, node, *queued) { Pending => { *queued = true; Pending } Ready(r) => { r?; *queued = false; Ready(Ok...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
acf8a7da7a64bf08d578db9a9836a8e061765314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/batch_semaphore.rs
401
460
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
) } } } impl Drop for Acquire<'_> { fn drop(&mut self) { // If the future is completed, there is no node in the wait list, so we // can skip acquiring the lock. if !self.queued { return; } // This is where we ensure safety. The future is being droppe...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
acf8a7da7a64bf08d578db9a9836a8e061765314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/batch_semaphore.rs
441
500
tokio-rs/tokio:tokio/src/sync/broadcast.rs:4
use crate::loom::sync::{Arc, Mutex, MutexGuard}; use crate::task::coop::cooperative; use crate::util::linked_list::{self, GuardedLinkedList, LinkedList}; use crate::util::WakeList; use std::fmt; use std::future::Future; use std::marker::PhantomPinned; use std::pin::Pin; use std::ptr::NonNull; use std::sync::atomic::Or...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
121
180
tokio-rs/tokio:tokio/src/sync/broadcast.rs:7
shared: Arc<Shared<T>>, /// Next position to read from next: u64, } pub mod error { //! Broadcast error types use std::fmt; /// Error returned by the [`send`] function on a [`Sender`]. /// /// A **send** operation can only fail if there are no active receivers, /// implying that the ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
241
300
tokio-rs/tokio:tokio/src/sync/broadcast.rs:8
/// The receiver lagged too far behind. 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 RecvError { fn fmt(&self, f: &mut fmt::Formatter<'_...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
281
340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:9
} impl fmt::Display for TryRecvError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { TryRecvError::Empty => write!(f, "channel empty"), TryRecvError::Closed => write!(f, "channel closed"), TryRecvError::Lagged(amt) => wri...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
321
380
tokio-rs/tokio:tokio/src/sync/broadcast.rs:10
/// Next position to write a value. struct Tail { /// Next position to write to. pos: u64, /// Number of active receivers. rx_cnt: usize, /// True if the channel is closed. closed: bool, /// Receivers waiting for a value. waiters: LinkedList<Waiter, <Waiter as linked_list::Link>::Targ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
361
420
tokio-rs/tokio:tokio/src/sync/broadcast.rs:11
/// Task waiting on the broadcast channel. waker: Option<Waker>, /// Intrusive linked-list pointers. pointers: linked_list::Pointers<Waiter>, /// Should not be `Unpin`. _p: PhantomPinned, } impl Waiter { fn new() -> Self { Self { queued: AtomicBool::new(false), ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
401
460
tokio-rs/tokio:tokio/src/sync/broadcast.rs:13
/// # #[tokio::main(flavor = "current_thread")] /// # 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(a...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
481
540
tokio-rs/tokio:tokio/src/sync/broadcast.rs:14
/// See the documentation of [`broadcast::channel`] for more information on this method. /// /// [`broadcast`]: crate::sync::broadcast /// [`broadcast::channel`]: crate::sync::broadcast::channel #[track_caller] pub fn new(capacity: usize) -> Self { // SAFETY: We don't create extra receivers,...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
521
580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
let shared = Arc::new(Shared { buffer: buffer.collect(), mask: capacity - 1, tail: Mutex::new(Tail { pos: 0, rx_cnt: receiver_count, closed: receiver_count == 0, waiters: LinkedList::new(), }), nu...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
/// /// [`Receiver`]: crate::sync::broadcast::Receiver /// [`subscribe`]: crate::sync::broadcast::Sender::subscribe /// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// # #[tokio::main(flavor = "current_thread")] /// # async fn main() { /// let (tx, mut rx1)...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
// Update the tail position tail.pos = tail.pos.wrapping_add(1); // Get the slot let mut slot = self.shared.buffer[idx].lock(); // Track the position slot.pos = pos; // Set remaining receivers slot.rem.with_mut(|v| *v = rem); // Write the value ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
/// use tokio::sync::broadcast; /// /// # #[tokio::main(flavor = "current_thread")] /// # async fn main() { /// let (tx, mut rx1) = broadcast::channel(16); /// let mut rx2 = tx.subscribe(); /// /// tx.send(10).unwrap(); /// tx.send(20).unwrap(); /// tx.send(30).unwrap(); /// ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:22
/// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// # #[tokio::main(flavor = "current_thread")] /// # async fn main() { /// let (tx, _rx) = broadcast::channel::<()>(16); /// let tx2 = tx.clone(); /// /// assert!(tx.same_channel(&tx2)); /// /// let (tx3, _rx...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
841
900
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
/// /// assert_eq!(rx2.recv().await.unwrap(), 10); /// drop(rx2); /// assert!(tx.closed().now_or_never().is_some()); /// # } /// ``` pub async fn closed(&self) { loop { let notified = self.shared.notify_last_rx_drop.notified(); { // Ensure the loc...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
/// Create a new `Receiver` which reads starting from the tail. fn new_receiver<T>(shared: Arc<Shared<T>>) -> Receiver<T> { let mut tail = shared.tail.lock(); assert!(tail.rx_cnt != MAX_RECEIVERS, "max receivers"); if tail.rx_cnt == 0 { // Potentially need to re-open the channel, if a new receiver...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
921
980
tokio-rs/tokio:tokio/src/sync/broadcast.rs:25
impl<'a, T> WaitersList<'a, T> { fn new( unguarded_list: LinkedList<Waiter, <Waiter as linked_list::Link>::Target>, guard: Pin<&'a Waiter>, shared: &'a Shared<T>, ) -> Self { let guard_ptr = NonNull::from(guard.get_ref()); let list = unguarded_list.into_guarded(guard_ptr)...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/broadcast.rs:26
// `NotifyWaitersList` wrapper makes sure we hold the lock to modify it. // * This wrapper will empty the list on drop. It is critical for safety // that we will not leave any list entry with a pointer to the local // guard node after this function returns / panics. let mut list = ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
1,001
1,060
tokio-rs/tokio:tokio/src/sync/broadcast.rs:27
// wake up waiters which will then queue themselves again. wakers.wake_all(); // Acquire the lock again. tail = self.tail.lock(); } // Release the lock before waking. drop(tail); wakers.wake_all(); } } impl<T> Clone for Sender<T> { fn clon...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
1,041
1,100
tokio-rs/tokio:tokio/src/sync/broadcast.rs:28
loop { if tx_count == 0 { // channel is closed so this WeakSender can not be upgraded return None; } match self .shared .num_tx .compare_exchange_weak(tx_count, tx_count + 1, Relaxed, Acquire) ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
1,081
1,140
tokio-rs/tokio:tokio/src/sync/broadcast.rs:31
/// ``` /// use tokio::sync::broadcast; /// /// # #[tokio::main(flavor = "current_thread")] /// # async fn main() { /// let (tx, rx) = broadcast::channel::<()>(16); /// let rx2 = tx.subscribe(); /// /// assert!(rx.same_channel(&rx2)); /// /// let (_tx3, rx3) = broadcast::channel:...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
1,201
1,260
tokio-rs/tokio:tokio/src/sync/broadcast.rs:32
let mut tail = self.shared.tail.lock(); // Acquire slot lock again slot = self.shared.buffer[idx].lock(); // Make sure the position did not change. This could happen in the // unlikely event that the buffer is wrapped between dropping the // read lock and ac...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
1,241
1,300
tokio-rs/tokio:tokio/src/sync/broadcast.rs:33
if !(*ptr).queued.load(Relaxed) { // `Relaxed` order suffices: all the readers will // synchronize with this write through the tail lock. (*ptr).queued.store(true, Relaxed); ta...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
1,281
1,340
tokio-rs/tokio:tokio/src/sync/broadcast.rs:34
} self.next = self.next.wrapping_add(1); Ok(RecvGuard { slot }) } /// Returns the number of [`Sender`] handles. pub fn sender_strong_count(&self) -> usize { self.shared.num_tx.load(Acquire) } /// Returns the number of [`WeakSender`] handles. pub fn sender_weak_count(&...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
1,321
1,380
tokio-rs/tokio:tokio/src/sync/broadcast.rs:39
/// # Examples /// ``` /// # #[cfg(not(target_family = "wasm"))] /// # { /// use std::thread; /// use tokio::sync::broadcast; /// /// #[tokio::main] /// async fn main() { /// let (tx, mut rx) = broadcast::channel(16); /// /// let sync_code = thread::spawn(move || { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
1,521
1,580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:40
while self.next < until { match self.recv_ref(None) { Ok(_) => {} // The channel is closed Err(TryRecvError::Closed) => break, // Ignore lagging, we will catch up Err(TryRecvError::Lagged(..)) => {} // Can't be e...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
1,561
1,620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:41
impl<'a, T> Future for Recv<'a, T> where T: Clone, { type Output = Result<T, RecvError>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> { ready!(crate::trace::trace_leaf()); let (receiver, waiter) = self.project(); let guard = match receiver.recv...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
1,601
1,660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:42
// Safety: tail lock is held. // `Relaxed` order suffices because we hold the tail lock. let queued = self .waiter .0 .with_mut(|ptr| unsafe { (*ptr).queued.load(Relaxed) }); if queued { // Remove the node ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
1,641
1,700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:43
} impl<T> fmt::Debug for Sender<T> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "broadcast::Sender") } } impl<T> fmt::Debug for WeakSender<T> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "broadcast::WeakSender") } } impl<T> f...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
1,681
1,740
tokio-rs/tokio:tokio/src/sync/broadcast.rs:44
#[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_count(), 1); let rx_2...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/broadcast.rs
1,721
1,757
tokio-rs/tokio:tokio/src/sync/broadcast.rs:40
while self.next < until { match self.recv_ref(None) { Ok(_) => {} // The channel is closed Err(TryRecvError::Closed) => break, // Ignore lagging, we will catch up Err(TryRecvError::Lagged(..)) => {} // Can't be e...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
26dee92b535d0a204531b6a04ee761f06c402d7e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/26dee92b535d0a204531b6a04ee761f06c402d7e/tokio/src/sync/broadcast.rs
1,561
1,620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:41
impl<'a, T> Future for Recv<'a, T> where T: Clone, { type Output = Result<T, RecvError>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>> { ready!(crate::trace::trace_leaf(cx)); let (receiver, waiter) = self.project(); let guard = match receiver.re...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
26dee92b535d0a204531b6a04ee761f06c402d7e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/26dee92b535d0a204531b6a04ee761f06c402d7e/tokio/src/sync/broadcast.rs
1,601
1,660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:14
/// See the documentation of [`broadcast::channel`] for more information on this method. /// /// [`broadcast`]: crate::sync::broadcast /// [`broadcast::channel`]: crate::sync::broadcast::channel #[track_caller] pub fn new(capacity: usize) -> Self { // SAFETY: We don't create extra receivers,...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
521
580
tokio-rs/tokio:tokio/src/sync/broadcast.rs:15
} let shared = Arc::new(Shared { buffer: buffer.into_boxed_slice(), mask: capacity - 1, tail: Mutex::new(Tail { pos: 0, rx_cnt: receiver_count, closed: receiver_count == 0, waiters: LinkedList::new(), ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
561
620
tokio-rs/tokio:tokio/src/sync/broadcast.rs:16
/// will fail. New [`Receiver`] handles may be created by calling /// [`subscribe`]. /// /// [`Receiver`]: crate::sync::broadcast::Receiver /// [`subscribe`]: crate::sync::broadcast::Sender::subscribe /// /// # Examples /// /// ``` /// use tokio::sync::broadcast; /// /// # #[...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
601
660
tokio-rs/tokio:tokio/src/sync/broadcast.rs:17
let idx = (pos & self.shared.mask as u64) as usize; // Update the tail position tail.pos = tail.pos.wrapping_add(1); // Get the slot let mut slot = self.shared.buffer[idx].lock(); // Track the position slot.pos = pos; // Set remaining receivers slot.re...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
641
700
tokio-rs/tokio:tokio/src/sync/broadcast.rs:19
/// /// ``` /// use tokio::sync::broadcast; /// /// # #[tokio::main(flavor = "current_thread")] /// # async fn main() { /// let (tx, mut rx1) = broadcast::channel(16); /// let mut rx2 = tx.subscribe(); /// /// tx.send(10).unwrap(); /// tx.send(20).unwrap(); /// tx.send(30).un...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
721
780
tokio-rs/tokio:tokio/src/sync/broadcast.rs:23
/// drop(rx1); /// assert!(tx.closed().now_or_never().is_none()); /// /// assert_eq!(rx2.recv().await.unwrap(), 10); /// drop(rx2); /// assert!(tx.closed().now_or_never().is_some()); /// # } /// ``` pub async fn closed(&self) { loop { let notified = self.shared.notify...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
881
940
tokio-rs/tokio:tokio/src/sync/broadcast.rs:24
} /// Create a new `Receiver` which reads starting from the tail. fn new_receiver<T>(shared: Arc<Shared<T>>) -> Receiver<T> { let mut tail = shared.tail.lock(); assert!(tail.rx_cnt != MAX_RECEIVERS, "max receivers"); if tail.rx_cnt == 0 { // Potentially need to re-open the channel, if a new recei...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/broadcast.rs
MIT
665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/665f08b5ad15485e8dcd6c3ec5ad1bda03a2a68d/tokio/src/sync/broadcast.rs
921
980