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:9
.checked_add(acquired) .expect("number of permits must not overflow"); let (next, acq) = if total >= needed { let next = curr - (needed - acquired); (next, needed >> Self::PERMIT_SHIFT) } else { remaining = (needed - acquired) - cur...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
ce0e9c67cfe61c7a91a284331ecc53fa01c32879
github
async-runtime
https://github.com/tokio-rs/tokio/blob/ce0e9c67cfe61c7a91a284331ecc53fa01c32879/tokio/src/sync/batch_semaphore.rs
321
380
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10
if node.assign_permits(&mut acquired) { self.add_permits_locked(acquired, waiters); return Ready(Ok(())); } assert_eq!(acquired, 0); // Otherwise, register the waker & enqueue the node. node.waker.with_mut(|waker| { // Safety: the wait list is locked...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
ce0e9c67cfe61c7a91a284331ecc53fa01c32879
github
async-runtime
https://github.com/tokio-rs/tokio/blob/ce0e9c67cfe61c7a91a284331ecc53fa01c32879/tokio/src/sync/batch_semaphore.rs
361
420
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11
.finish() } } impl Waiter { fn new(num_permits: u32) -> Self { Waiter { waker: UnsafeCell::new(None), state: AtomicUsize::new(num_permits as usize), pointers: linked_list::Pointers::new(), _p: PhantomPinned, } } /// Assign permits to the ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
ce0e9c67cfe61c7a91a284331ecc53fa01c32879
github
async-runtime
https://github.com/tokio-rs/tokio/blob/ce0e9c67cfe61c7a91a284331ecc53fa01c32879/tokio/src/sync/batch_semaphore.rs
401
460
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
this.num_permits, &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; } ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
ce0e9c67cfe61c7a91a284331ecc53fa01c32879
github
async-runtime
https://github.com/tokio-rs/tokio/blob/ce0e9c67cfe61c7a91a284331ecc53fa01c32879/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14
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
ce0e9c67cfe61c7a91a284331ecc53fa01c32879
github
async-runtime
https://github.com/tokio-rs/tokio/blob/ce0e9c67cfe61c7a91a284331ecc53fa01c32879/tokio/src/sync/batch_semaphore.rs
521
580
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15
impl std::error::Error for TryAcquireError {} /// # Safety /// /// `Waiter` is forced to be !Unpin. unsafe impl linked_list::Link for Waiter { // XXX: ideally, we would be able to use `Pin` here, to enforce the // invariant that list entries may not move while in the list. However, we // can't do this curr...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
ce0e9c67cfe61c7a91a284331ecc53fa01c32879
github
async-runtime
https://github.com/tokio-rs/tokio/blob/ce0e9c67cfe61c7a91a284331ecc53fa01c32879/tokio/src/sync/batch_semaphore.rs
561
588
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:1
#![cfg_attr(not(feature = "sync"), allow(unreachable_pub, dead_code))] //! # 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...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
1
60
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:2
closed: bool, } /// Error returned from the [`Semaphore::try_acquire`] function. /// /// [`Semaphore::try_acquire`]: crate::sync::Semaphore::try_acquire #[derive(Debug, PartialEq)] pub enum TryAcquireError { /// The semaphore has been [closed] and cannot issue new permits. /// /// [closed]: crate::sync::Se...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
41
100
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:3
/// the waiter, or a flag indicating that the waiter is not yet queued. state: AtomicUsize, /// The waker to notify the task awaiting permits. /// /// # Safety /// /// This may only be accessed while the wait queue is locked. waker: UnsafeCell<Option<Waker>>, /// Intrusive linked-list ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
81
140
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4
// PERMIT_SHIFT is used to leave that bit for that purpose. const PERMIT_SHIFT: usize = 1; /// Creates a new semaphore with the initial number of permits /// /// Maximum number of permits on 32-bit platforms is `1<<29`. pub(crate) fn new(permits: usize) -> Self { assert!( permit...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
121
180
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5
} /// 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 p...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
161
220
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6
/// Returns true if the semaphore is closed pub(crate) fn is_closed(&self) -> bool { self.permits.load(Acquire) & Self::CLOSED == Self::CLOSED } pub(crate) fn try_acquire(&self, num_permits: u32) -> Result<(), TryAcquireError> { assert!( num_permits as usize <= Self::MAX_PERMITS...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
201
260
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7
/// If `rem` exceeds the number of permits needed by the wait list, the /// remainder are assigned back to the semaphore. fn add_permits_locked(&self, mut rem: usize, waiters: MutexGuard<'_, Waitlist>) { let mut wakers: [Option<Waker>; 8] = Default::default(); let mut lock = Some(waiters); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
241
300
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8
); rem = 0; } drop(waiters); // release the lock wakers .iter_mut() .filter_map(Option::take) .for_each(Waker::wake); } assert_eq!(rem, 0); } fn poll_acquire( &self, cx: &mut C...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
281
340
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9
let mut remaining = 0; let total = curr .checked_add(acquired) .expect("number of permits must not overflow"); let (next, acq) = if total >= needed { let next = curr - (needed - acquired); (next, needed >> Self::PERMIT_SHIFT) ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
321
380
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10
return Ready(Err(AcquireError::closed())); } if node.assign_permits(&mut acquired) { self.add_permits_locked(acquired, waiters); return Ready(Ok(())); } assert_eq!(acquired, 0); // Otherwise, register the waker & enqueue the node. node.waker.wit...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
361
420
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11
fmt.debug_struct("Semaphore") .field("permits", &self.available_permits()) .finish() } } impl Waiter { fn new(num_permits: u32) -> Self { Waiter { waker: UnsafeCell::new(None), state: AtomicUsize::new(num_permits as usize), pointers: linked_li...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
401
460
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
let coop = ready!(crate::coop::poll_proceed(cx)); let (node, semaphore, needed, queued) = self.project(); match semaphore.poll_acquire(cx, needed, node, *queued) { Pending => { *queued = true; Pending } Ready(r) => { c...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
441
500
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
Pin::new_unchecked(&mut this.node), &this.semaphore, this.num_permits, &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 sk...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14
// ===== impl AcquireError ==== 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 {} // =====...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
521
580
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15
} } impl std::error::Error for TryAcquireError {} /// # Safety /// /// `Waiter` is forced to be !Unpin. unsafe impl linked_list::Link for Waiter { // XXX: ideally, we would be able to use `Pin` here, to enforce the // invariant that list entries may not move while in the list. However, we // can't do this...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
575938d4579e6fe6a89b700aadb0ae2bbab5483b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/sync/batch_semaphore.rs
561
590
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:1
#![cfg_attr(not(feature = "sync"), allow(unreachable_pub, dead_code))] //! # 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...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
1
60
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:2
closed: bool, } /// 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 Semaphor...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/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 in...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
81
140
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4
queue: LinkedList::new(), closed: false, }), } } /// Creates a new semaphore with the initial number of permits /// /// Maximum number of permits on 32-bit platforms is `1<<29`. /// /// If the specified number of permits exceeds the maximum permit amount ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
121
180
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5
// Assign permits to the wait queue self.add_permits_locked(added, self.waiters.lock()); } /// Closes the semaphore. This prevents the semaphore from issuing new /// permits and notifies all pending waiters. // This will be used once the bounded MPSC is updated to use the new // semaphore i...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
161
220
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6
loop { // Has the semaphore closed? if curr & Self::CLOSED == Self::CLOSED { return Err(TryAcquireError::Closed); } // Are there enough permits remaining? if curr < num_permits { return Err(TryAcquireError::NoPermits); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
201
260
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7
break 'inner; } } None => { is_empty = true; // If we assigned permits to all the waiters in the queue, and there are // still permits left over, assign them back to the semaphore. ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
241
300
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8
} fn poll_acquire( &self, cx: &mut Context<'_>, num_permits: u32, node: Pin<&mut Waiter>, queued: bool, ) -> Poll<Result<(), AcquireError>> { let mut acquired = 0; let needed = if queued { node.state.load(Acquire) << Self::PERMIT_SHIFT ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
281
340
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9
// 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 value of the semaphore's `permits` // co...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
321
380
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10
let waker = unsafe { &mut *waker }; // Do we need to register the new waker? if waker .as_ref() .map(|waker| !waker.will_wake(cx.waker())) .unwrap_or(true) { *waker = Some(cx.waker().clone()); } }); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
361
420
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11
} } /// 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 { let assign = cmp::min(curr, *n); let next = curr - as...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
401
460
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
Ready(Ok(())) } } } } impl<'a> Acquire<'a> { fn new(semaphore: &'a Semaphore, num_permits: u32) -> Self { Self { node: Waiter::new(num_permits), semaphore, num_permits, queued: false, } } fn project(self: Pin<&mut Self...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
441
500
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
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 = self.semaphore.waiters.lock(); // remove the entry fr...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14
} impl std::error::Error for AcquireError {} // ===== 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 { matches!(self, TryAcquireError::Closed) ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
521
577
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15
// use `Pin<*mut Waiter>`, as raw pointers are `Unpin` regardless of whether // or not they dereference to an `!Unpin` target. type Handle = NonNull<Waiter>; type Target = Waiter; fn as_raw(handle: &Self::Handle) -> NonNull<Waiter> { *handle } unsafe fn from_raw(ptr: NonNull<Waiter>) -...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
a6051a61ec5c96113f4b543de3ec55431695347a
github
async-runtime
https://github.com/tokio-rs/tokio/blob/a6051a61ec5c96113f4b543de3ec55431695347a/tokio/src/sync/batch_semaphore.rs
561
577
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6
loop { // Has the semaphore closed? if curr & Self::CLOSED == Self::CLOSED { return Err(TryAcquireError::Closed); } // Are there enough permits remaining? if curr < num_permits { return Err(TryAcquireError::NoPermits); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
afe535283c68dec40c5fc7a810445e8c2380880f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/afe535283c68dec40c5fc7a810445e8c2380880f/tokio/src/sync/batch_semaphore.rs
201
260
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7
break 'inner; } } None => { is_empty = true; // If we assigned permits to all the waiters in the queue, and there are // still permits left over, assign them back to the semaphore. ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
afe535283c68dec40c5fc7a810445e8c2380880f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/afe535283c68dec40c5fc7a810445e8c2380880f/tokio/src/sync/batch_semaphore.rs
241
300
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
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/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
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/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
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/tokio/src/sync/batch_semaphore.rs
81
140
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4
closed: false, }), } } /// Creates a new semaphore with the initial number of permits /// /// Maximum number of permits on 32-bit platforms is `1<<29`. /// /// If the specified number of permits exceeds the maximum permit amount /// Then the value will get clamped to the...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/tokio/src/sync/batch_semaphore.rs
121
180
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5
self.add_permits_locked(added, self.waiters.lock()); } /// Closes the semaphore. This prevents the semaphore from issuing new /// permits and notifies all pending waiters. // This will be used once the bounded MPSC is updated to use the new // semaphore implementation. pub(crate) fn close(&self...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/tokio/src/sync/batch_semaphore.rs
161
220
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6
// Has the semaphore closed? if curr & Self::CLOSED == Self::CLOSED { return Err(TryAcquireError::Closed); } // Are there enough permits remaining? if curr < num_permits { return Err(TryAcquireError::NoPermits); } ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/tokio/src/sync/batch_semaphore.rs
201
260
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7
} } None => { is_empty = true; // If we assigned permits to all the waiters in the queue, and there are // still permits left over, assign them back to the semaphore. break 'inner; ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/tokio/src/sync/batch_semaphore.rs
241
300
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8
fn poll_acquire( &self, cx: &mut Context<'_>, num_permits: u32, node: Pin<&mut Waiter>, queued: bool, ) -> Poll<Result<(), AcquireError>> { let mut acquired = 0; let needed = if queued { node.state.load(Acquire) << Self::PERMIT_SHIFT } els...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/tokio/src/sync/batch_semaphore.rs
281
340
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9
// (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 value of the semaphore's `permits` // counter. Otherwise, if we subtract the permits and then // acqui...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/tokio/src/sync/batch_semaphore.rs
321
380
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10
// Do we need to register the new waker? if waker .as_ref() .map(|waker| !waker.will_wake(cx.waker())) .unwrap_or(true) { *waker = Some(cx.waker().clone()); } }); // If the waiter is not already in the w...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/tokio/src/sync/batch_semaphore.rs
361
420
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11
} /// 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 { let assign = cmp::min(curr, *n); let next = curr - assign; ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/tokio/src/sync/batch_semaphore.rs
401
460
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
} } } } impl<'a> Acquire<'a> { fn new(semaphore: &'a Semaphore, num_permits: u32) -> Self { Self { node: Waiter::new(num_permits), semaphore, num_permits, queued: false, } } fn project(self: Pin<&mut Self>) -> (Pin<&mut Waiter>, &...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/tokio/src/sync/batch_semaphore.rs
441
500
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
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 = self.semaphore.waiters.lock(); // remove the entry from the list let node =...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14
impl std::error::Error for AcquireError {} // ===== 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 { matches!(self, TryAcquireError::Closed) } ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/tokio/src/sync/batch_semaphore.rs
521
576
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15
// or not they dereference to an `!Unpin` target. type Handle = NonNull<Waiter>; type Target = Waiter; fn as_raw(handle: &Self::Handle) -> NonNull<Waiter> { *handle } unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> { ptr } unsafe fn pointers(mut target: NonNull...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
b704c53b9cc76eaf8c9c6585f8444c4515d27728
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b704c53b9cc76eaf8c9c6585f8444c4515d27728/tokio/src/sync/batch_semaphore.rs
561
576
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
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 = self.semaphore.waiters.lock(); // remove the entry from the list let node =...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
496e8899172a39eb8b2cff0f2462141ddc6b575d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/496e8899172a39eb8b2cff0f2462141ddc6b575d/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14
impl std::error::Error for AcquireError {} // ===== 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::Close...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
496e8899172a39eb8b2cff0f2462141ddc6b575d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/496e8899172a39eb8b2cff0f2462141ddc6b575d/tokio/src/sync/batch_semaphore.rs
521
580
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15
unsafe impl linked_list::Link for Waiter { // XXX: ideally, we would be able to use `Pin` here, to enforce the // 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 gen...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
496e8899172a39eb8b2cff0f2462141ddc6b575d
github
async-runtime
https://github.com/tokio-rs/tokio/blob/496e8899172a39eb8b2cff0f2462141ddc6b575d/tokio/src/sync/batch_semaphore.rs
561
582
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
444660664b96f758610a0e7201a6a1a31a0f2405
github
async-runtime
https://github.com/tokio-rs/tokio/blob/444660664b96f758610a0e7201a6a1a31a0f2405/tokio/src/sync/batch_semaphore.rs
81
140
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4
closed: false, }), } } /// Creates a new semaphore with the initial number of permits /// /// Maximum number of permits on 32-bit platforms is `1<<29`. /// /// If the specified number of permits exceeds the maximum permit amount /// Then the value will get clamped to the...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
444660664b96f758610a0e7201a6a1a31a0f2405
github
async-runtime
https://github.com/tokio-rs/tokio/blob/444660664b96f758610a0e7201a6a1a31a0f2405/tokio/src/sync/batch_semaphore.rs
121
180
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4
closed: false, }), } } /// Creates a new semaphore with the initial number of permits /// /// Maximum number of permits on 32-bit platforms is `1<<29`. /// /// If the specified number of permits exceeds the maximum permit amount /// Then the value will get clamped to the...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
cf025ba45f68934ae2138bb75ee2a5ee50506d1b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cf025ba45f68934ae2138bb75ee2a5ee50506d1b/tokio/src/sync/batch_semaphore.rs
121
180
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5
self.add_permits_locked(added, self.waiters.lock().unwrap()); } /// Closes the semaphore. This prevents the semaphore from issuing new /// permits and notifies all pending waiters. // This will be used once the bounded MPSC is updated to use the new // semaphore implementation. pub(crate) fn cl...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
cf025ba45f68934ae2138bb75ee2a5ee50506d1b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cf025ba45f68934ae2138bb75ee2a5ee50506d1b/tokio/src/sync/batch_semaphore.rs
161
220
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6
// Has the semaphore closed? if curr & Self::CLOSED == Self::CLOSED { return Err(TryAcquireError::Closed); } // Are there enough permits remaining? if curr < num_permits { return Err(TryAcquireError::NoPermits); } ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
cf025ba45f68934ae2138bb75ee2a5ee50506d1b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cf025ba45f68934ae2138bb75ee2a5ee50506d1b/tokio/src/sync/batch_semaphore.rs
201
260
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8
fn poll_acquire( &self, cx: &mut Context<'_>, num_permits: u32, node: Pin<&mut Waiter>, queued: bool, ) -> Poll<Result<(), AcquireError>> { let mut acquired = 0; let needed = if queued { node.state.load(Acquire) << Self::PERMIT_SHIFT } els...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
cf025ba45f68934ae2138bb75ee2a5ee50506d1b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cf025ba45f68934ae2138bb75ee2a5ee50506d1b/tokio/src/sync/batch_semaphore.rs
281
340
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9
// (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 value of the semaphore's `permits` // counter. Otherwise, if we subtract the permits and then // acqui...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
cf025ba45f68934ae2138bb75ee2a5ee50506d1b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cf025ba45f68934ae2138bb75ee2a5ee50506d1b/tokio/src/sync/batch_semaphore.rs
321
380
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
} } } } impl<'a> Acquire<'a> { fn new(semaphore: &'a Semaphore, num_permits: u32) -> Self { Self { node: Waiter::new(num_permits), semaphore, num_permits, queued: false, } } fn project(self: Pin<&mut Self>) -> (Pin<&mut Waiter>, &...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
cf025ba45f68934ae2138bb75ee2a5ee50506d1b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cf025ba45f68934ae2138bb75ee2a5ee50506d1b/tokio/src/sync/batch_semaphore.rs
441
500
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
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.waiters.lock() { Ok(lock) => lock, // Removing ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
cf025ba45f68934ae2138bb75ee2a5ee50506d1b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cf025ba45f68934ae2138bb75ee2a5ee50506d1b/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14
} 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 sem...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
cf025ba45f68934ae2138bb75ee2a5ee50506d1b
github
async-runtime
https://github.com/tokio-rs/tokio/blob/cf025ba45f68934ae2138bb75ee2a5ee50506d1b/tokio/src/sync/batch_semaphore.rs
521
580
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4
closed: false, }), } } /// Creates a new semaphore with the initial number of permits /// /// Maximum number of permits on 32-bit platforms is `1<<29`. /// /// If the specified number of permits exceeds the maximum permit amount /// Then the value will get clamped to the...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
20ef28655354ae729a4af2098426a413e3f4d769
github
async-runtime
https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/batch_semaphore.rs
121
180
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5
self.add_permits_locked(added, self.waiters.lock().unwrap()); } /// Closes the semaphore. This prevents the semaphore from issuing new /// permits and notifies all pending waiters. // This will be used once the bounded MPSC is updated to use the new // semaphore implementation. #[allow(dead_cod...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
20ef28655354ae729a4af2098426a413e3f4d769
github
async-runtime
https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/batch_semaphore.rs
161
220
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6
// Are there enough permits remaining? if curr < num_permits { return Err(TryAcquireError::NoPermits); } let next = curr - num_permits; match self.permits.compare_exchange(curr, next, AcqRel, Acquire) { Ok(_) => return Ok(()), ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
20ef28655354ae729a4af2098426a413e3f4d769
github
async-runtime
https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/batch_semaphore.rs
201
260
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7
// If we assigned permits to all the waiters in the queue, and there are // still permits left over, assign them back to the semaphore. break 'inner; } }; let mut waiter = waiters.queue.pop_back().unwrap(); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
20ef28655354ae729a4af2098426a413e3f4d769
github
async-runtime
https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/batch_semaphore.rs
241
300
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8
num_permits: u32, node: Pin<&mut Waiter>, queued: bool, ) -> Poll<Result<(), AcquireError>> { let mut acquired = 0; let needed = if queued { node.state.load(Acquire) << Self::PERMIT_SHIFT } else { (num_permits as usize) << Self::PERMIT_SHIFT }...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
20ef28655354ae729a4af2098426a413e3f4d769
github
async-runtime
https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/batch_semaphore.rs
281
340
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9
// acquire the lock, we might miss additional permits being // added while waiting for the lock. lock = Some(self.waiters.lock().unwrap()); } match self.permits.compare_exchange(curr, next, AcqRel, Acquire) { Ok(_) => { acquire...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
20ef28655354ae729a4af2098426a413e3f4d769
github
async-runtime
https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/batch_semaphore.rs
321
380
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:10
.unwrap_or(true) { *waker = Some(cx.waker().clone()); } }); // If the waiter is not already in the wait queue, enqueue it. if !queued { let node = unsafe { let node = Pin::into_inner_unchecked(node) as *mut _; N...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
20ef28655354ae729a4af2098426a413e3f4d769
github
async-runtime
https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/batch_semaphore.rs
361
420
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11
/// 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 { let assign = cmp::min(curr, *n); let next = curr - assign; match self.state.compare_exchange(curr, n...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
20ef28655354ae729a4af2098426a413e3f4d769
github
async-runtime
https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/batch_semaphore.rs
401
460
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
impl<'a> Acquire<'a> { fn new(semaphore: &'a Semaphore, num_permits: u32) -> Self { Self { node: Waiter::new(num_permits), semaphore, num_permits, queued: false, } } fn project(self: Pin<&mut Self>) -> (Pin<&mut Waiter>, &Semaphore, u32, &mut ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
20ef28655354ae729a4af2098426a413e3f4d769
github
async-runtime
https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/batch_semaphore.rs
441
500
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
// 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 list is necessary to ensure // safety. Even if the lock was po...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
20ef28655354ae729a4af2098426a413e3f4d769
github
async-runtime
https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14
write!(fmt, "semaphore closed") } } impl std::error::Error for AcquireError {} // ===== 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 ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
20ef28655354ae729a4af2098426a413e3f4d769
github
async-runtime
https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/batch_semaphore.rs
521
580
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:15
/// # Safety /// /// `Waiter` is forced to be !Unpin. unsafe impl linked_list::Link for Waiter { // XXX: ideally, we would be able to use `Pin` here, to enforce the // 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 `H...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
20ef28655354ae729a4af2098426a413e3f4d769
github
async-runtime
https://github.com/tokio-rs/tokio/blob/20ef28655354ae729a4af2098426a413e3f4d769/tokio/src/sync/batch_semaphore.rs
561
585
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
c9f5bc29158a6f3a786e9d67df8da31524e8a9c3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c9f5bc29158a6f3a786e9d67df8da31524e8a9c3/tokio/src/sync/batch_semaphore.rs
81
140
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:4
closed: false, }), } } /// 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 i...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
c9f5bc29158a6f3a786e9d67df8da31524e8a9c3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c9f5bc29158a6f3a786e9d67df8da31524e8a9c3/tokio/src/sync/batch_semaphore.rs
121
180
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5
if let Some(waker) = waker { waker.wake(); } } } pub(crate) fn try_acquire(&self, num_permits: u32) -> Result<(), TryAcquireError> { assert!( num_permits as usize <= Self::MAX_PERMITS, "a semaphore may not have more than MAX_PERMITS permits ({...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
c9f5bc29158a6f3a786e9d67df8da31524e8a9c3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c9f5bc29158a6f3a786e9d67df8da31524e8a9c3/tokio/src/sync/batch_semaphore.rs
161
220
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6
/// /// If `rem` exceeds the number of permits needed by the wait list, the /// remainder are assigned back to the semaphore. fn add_permits_locked(&self, mut rem: usize, waiters: MutexGuard<'_, Waitlist>) { let mut wakers: [Option<Waker>; 8] = Default::default(); let mut lock = Some(waiters...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
c9f5bc29158a6f3a786e9d67df8da31524e8a9c3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c9f5bc29158a6f3a786e9d67df8da31524e8a9c3/tokio/src/sync/batch_semaphore.rs
201
260
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7
Self::MAX_PERMITS ); rem = 0; } drop(waiters); // release the lock wakers .iter_mut() .filter_map(Option::take) .for_each(Waker::wake); } assert_eq!(rem, 0); } fn poll_acquire(...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
c9f5bc29158a6f3a786e9d67df8da31524e8a9c3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c9f5bc29158a6f3a786e9d67df8da31524e8a9c3/tokio/src/sync/batch_semaphore.rs
241
300
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8
let mut remaining = 0; let total = curr .checked_add(acquired) .expect("number of permits must not overflow"); let (next, acq) = if total >= needed { let next = curr - (needed - acquired); (next, needed >> Self::PERMIT_SHIFT) ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
c9f5bc29158a6f3a786e9d67df8da31524e8a9c3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c9f5bc29158a6f3a786e9d67df8da31524e8a9c3/tokio/src/sync/batch_semaphore.rs
281
340
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:11
// First, ensure the current task has enough budget to proceed. let coop = ready!(crate::coop::poll_proceed(cx)); let (node, semaphore, needed, queued) = self.project(); match semaphore.poll_acquire(cx, needed, node, *queued) { Pending => { *queued = true; ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
c9f5bc29158a6f3a786e9d67df8da31524e8a9c3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c9f5bc29158a6f3a786e9d67df8da31524e8a9c3/tokio/src/sync/batch_semaphore.rs
401
460
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
( Pin::new_unchecked(&mut this.node), &this.semaphore, this.num_permits, &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...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
c9f5bc29158a6f3a786e9d67df8da31524e8a9c3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c9f5bc29158a6f3a786e9d67df8da31524e8a9c3/tokio/src/sync/batch_semaphore.rs
441
500
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:13
} // Safety: the `Acquire` future is not `Sync` automatically because it contains // 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_) ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
c9f5bc29158a6f3a786e9d67df8da31524e8a9c3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c9f5bc29158a6f3a786e9d67df8da31524e8a9c3/tokio/src/sync/batch_semaphore.rs
481
540
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:14
pub(crate) fn is_no_permits(&self) -> bool { match self { TryAcquireError::NoPermits => true, _ => false, } } } impl fmt::Display for TryAcquireError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match self { TryAcquireError::Closed =...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/batch_semaphore.rs
MIT
c9f5bc29158a6f3a786e9d67df8da31524e8a9c3
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c9f5bc29158a6f3a786e9d67df8da31524e8a9c3/tokio/src/sync/batch_semaphore.rs
521
564
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
e9adac288e3c4279d19d80b77ea61aa0677459b5
github
async-runtime
https://github.com/tokio-rs/tokio/blob/e9adac288e3c4279d19d80b77ea61aa0677459b5/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
27bfe52bba06283df3e9481b89a903390ee70369
github
async-runtime
https://github.com/tokio-rs/tokio/blob/27bfe52bba06283df3e9481b89a903390ee70369/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
27bfe52bba06283df3e9481b89a903390ee70369
github
async-runtime
https://github.com/tokio-rs/tokio/blob/27bfe52bba06283df3e9481b89a903390ee70369/tokio/src/sync/batch_semaphore.rs
81
140
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
c344aac9252c34fcce196200a99529734b5cb9e8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c344aac9252c34fcce196200a99529734b5cb9e8/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 p...
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
121
180
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:5
} } pub(crate) fn try_acquire(&self, num_permits: u32) -> Result<(), TryAcquireError> { assert!( num_permits as usize <= Self::MAX_PERMITS, "a semaphore may not have more than MAX_PERMITS permits ({})", Self::MAX_PERMITS ); let num_permits = (num_perm...
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
161
220
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:6
fn add_permits_locked(&self, mut rem: usize, waiters: MutexGuard<'_, Waitlist>) { let mut wakers: [Option<Waker>; 8] = Default::default(); let mut lock = Some(waiters); let mut is_empty = false; while rem > 0 { let mut waiters = lock.take().unwrap_or_else(|| self.waiters.lock...
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
201
260
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:7
} drop(waiters); // release the lock wakers .iter_mut() .filter_map(Option::take) .for_each(Waker::wake); } assert_eq!(rem, 0); } fn poll_acquire( &self, cx: &mut Context<'_>, num_permits: u32, ...
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
241
300
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:8
.checked_add(acquired) .expect("number of permits must not overflow"); let (next, acq) = if total >= needed { let next = curr - (needed - acquired); (next, needed >> Self::PERMIT_SHIFT) } else { remaining = (needed - acquired) - cur...
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
281
340
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:9
if node.assign_permits(&mut acquired) { self.add_permits_locked(acquired, waiters); return Ready(Ok(())); } assert_eq!(acquired, 0); // Otherwise, register the waker & enqueue the node. node.waker.with_mut(|waker| { // Safety: the wait list is locked...
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
321
380
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) => { coop.made_progress(); r?; *q...
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
401
460
tokio-rs/tokio:tokio/src/sync/batch_semaphore.rs:12
this.num_permits, &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; } ...
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
441
500