Struct futures_intrusive::sync::GenericSharedSemaphore
source · pub struct GenericSharedSemaphore<MutexType: RawMutex> { /* private fields */ }
Expand description
A futures-aware shared semaphore.
Implementations
sourcepub fn new(is_fair: bool, permits: usize) -> GenericSharedSemaphore<MutexType>
pub fn new(is_fair: bool, permits: usize) -> GenericSharedSemaphore<MutexType>
Creates a new futures-aware shared semaphore.
See GenericSharedSemaphore
for more information.
sourcepub fn acquire(
&self,
nr_permits: usize
) -> GenericSharedSemaphoreAcquireFuture<MutexType>ⓘNotable traits for GenericSharedSemaphoreAcquireFuture<MutexType>impl<MutexType: RawMutex> Future for GenericSharedSemaphoreAcquireFuture<MutexType> type Output = GenericSharedSemaphoreReleaser<MutexType>;
pub fn acquire(
&self,
nr_permits: usize
) -> GenericSharedSemaphoreAcquireFuture<MutexType>ⓘNotable traits for GenericSharedSemaphoreAcquireFuture<MutexType>impl<MutexType: RawMutex> Future for GenericSharedSemaphoreAcquireFuture<MutexType> type Output = GenericSharedSemaphoreReleaser<MutexType>;
Acquire a certain amount of permits on a semaphore asynchronously.
This method returns a future that will resolve once the given amount of
permits have been acquired.
The Future will resolve to a GenericSharedSemaphoreReleaser
, which will
release all acquired permits automatically when dropped.
sourcepub fn try_acquire(
&self,
nr_permits: usize
) -> Option<GenericSharedSemaphoreReleaser<MutexType>>
pub fn try_acquire(
&self,
nr_permits: usize
) -> Option<GenericSharedSemaphoreReleaser<MutexType>>
Tries to acquire a certain amount of permits on a semaphore.
If acquiring the permits is successful, a GenericSharedSemaphoreReleaser
will be returned, which will release all acquired permits automatically
when dropped.
Otherwise None
will be returned.
sourcepub fn release(&self, nr_permits: usize)
pub fn release(&self, nr_permits: usize)
Releases the given amount of permits back to the semaphore.
This method should in most cases not be used, since the
GenericSharedSemaphoreReleaser
which is obtained when acquiring a Semaphore
will automatically release the obtained permits again.
Therefore this method should only be used if the automatic release was
disabled by calling GenericSharedSemaphoreReleaser::disarm
,
or when the amount of permits in the Semaphore
should increase from the initial amount.