pub struct Semaphore { /* private fields */ }
Expand description
An unsynchronized (!Sync
), simple semaphore for asynchronous permit
acquisition.
Implementations§
Source§impl Semaphore
impl Semaphore
Sourcepub const fn new(permits: usize) -> Self
pub const fn new(permits: usize) -> Self
Creates a new semaphore with the initial number of permits.
Sourcepub fn close(&self) -> usize
pub fn close(&self) -> usize
Closes the semaphore and returns the number of notified pending waiters.
This prevents the semaphore from issuing new permits and notifies all pending waiters.
Sourcepub fn available_permits(&self) -> usize
pub fn available_permits(&self) -> usize
Returns the current number of available permits.
Sourcepub fn add_permits(&self, n: usize)
pub fn add_permits(&self, n: usize)
Adds n
new permits to the semaphore.
Sourcepub fn remove_permits(&self, n: usize)
pub fn remove_permits(&self, n: usize)
Permanently reduces the number of available permits by n
.
Sourcepub fn try_acquire(&self) -> Result<Permit<'_>, TryAcquireError>
pub fn try_acquire(&self) -> Result<Permit<'_>, TryAcquireError>
Sourcepub fn try_acquire_many(&self, n: usize) -> Result<Permit<'_>, TryAcquireError>
pub fn try_acquire_many(&self, n: usize) -> Result<Permit<'_>, TryAcquireError>
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Semaphore
impl !RefUnwindSafe for Semaphore
impl !Send for Semaphore
impl !Sync for Semaphore
impl Unpin for Semaphore
impl !UnwindSafe for Semaphore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more