pub struct RankedSemaphore { /* private fields */ }Expand description
High-performance priority semaphore
Implementations§
Source§impl RankedSemaphore
impl RankedSemaphore
Sourcepub const MAX_PERMITS: usize = 2_305_843_009_213_693_951usize
pub const MAX_PERMITS: usize = 2_305_843_009_213_693_951usize
Maximum permits (reserve 3 bits for flags, same as tokio)
Sourcepub fn new(permits: usize, default_strategy: QueueStrategy) -> Self
pub fn new(permits: usize, default_strategy: QueueStrategy) -> Self
Create semaphore with specified strategy
Sourcepub fn new_with_config(permits: usize, config: PriorityConfig) -> Self
pub fn new_with_config(permits: usize, config: PriorityConfig) -> Self
Create semaphore with custom configuration
Sourcepub fn available_permits(&self) -> usize
pub fn available_permits(&self) -> usize
Get current available permits
Sourcepub fn add_permits(&self, added: usize)
pub fn add_permits(&self, added: usize)
Add permits and notify waiters if any.
Sourcepub fn acquire_with_priority(&self, priority: isize) -> Acquire<'_> ⓘ
pub fn acquire_with_priority(&self, priority: isize) -> Acquire<'_> ⓘ
Acquire with specified priority
Sourcepub fn acquire_many(&self, n: u32) -> Acquire<'_> ⓘ
pub fn acquire_many(&self, n: u32) -> Acquire<'_> ⓘ
Acquire many permits (default priority)
Sourcepub fn acquire_many_with_priority(&self, priority: isize, n: u32) -> Acquire<'_> ⓘ
pub fn acquire_many_with_priority(&self, priority: isize, n: u32) -> Acquire<'_> ⓘ
Acquire many permits with priority
Sourcepub fn try_acquire(&self) -> Result<RankedSemaphorePermit<'_>, TryAcquireError>
pub fn try_acquire(&self) -> Result<RankedSemaphorePermit<'_>, TryAcquireError>
Try acquire single permit (non-blocking)
Sourcepub fn try_acquire_many(
&self,
n: u32,
) -> Result<RankedSemaphorePermit<'_>, TryAcquireError>
pub fn try_acquire_many( &self, n: u32, ) -> Result<RankedSemaphorePermit<'_>, TryAcquireError>
Try acquire many permits (non-blocking)
Sourcepub fn forget_permits(&self, n: usize) -> usize
pub fn forget_permits(&self, n: usize) -> usize
Forget (remove) permits from the semaphore
Returns the number of permits that were actually removed. If there are insufficient permits, removes as many as possible.
Sourcepub fn acquire_owned(self: Arc<Self>) -> AcquireOwned ⓘ
pub fn acquire_owned(self: Arc<Self>) -> AcquireOwned ⓘ
Acquire owned permit (default priority)
Sourcepub fn acquire_owned_with_priority(
self: Arc<Self>,
priority: isize,
) -> AcquireOwned ⓘ
pub fn acquire_owned_with_priority( self: Arc<Self>, priority: isize, ) -> AcquireOwned ⓘ
Acquire owned permit with priority
Sourcepub fn acquire_many_owned(self: Arc<Self>, n: u32) -> AcquireOwned ⓘ
pub fn acquire_many_owned(self: Arc<Self>, n: u32) -> AcquireOwned ⓘ
Acquire many owned permits (default priority)
Sourcepub fn acquire_many_owned_with_priority(
self: Arc<Self>,
priority: isize,
n: u32,
) -> AcquireOwned ⓘ
pub fn acquire_many_owned_with_priority( self: Arc<Self>, priority: isize, n: u32, ) -> AcquireOwned ⓘ
Acquire many owned permits with priority
Sourcepub fn try_acquire_owned(
self: Arc<Self>,
) -> Result<OwnedRankedSemaphorePermit, TryAcquireError>
pub fn try_acquire_owned( self: Arc<Self>, ) -> Result<OwnedRankedSemaphorePermit, TryAcquireError>
Attempts to acquire a single permit, returning an owned permit if successful.
The semaphore must be wrapped in an Arc to call this method. If the semaphore has been closed, this returns a TryAcquireError::Closed and a TryAcquireError::NoPermits if there are no permits left. Otherwise, this returns an OwnedRankedSemaphorePermit representing the acquired permit.
Sourcepub fn try_acquire_many_owned(
self: Arc<Self>,
n: u32,
) -> Result<OwnedRankedSemaphorePermit, TryAcquireError>
pub fn try_acquire_many_owned( self: Arc<Self>, n: u32, ) -> Result<OwnedRankedSemaphorePermit, TryAcquireError>
Attempts to acquire n permits, returning an owned permit if successful.
The semaphore must be wrapped in an Arc to call this method. If the semaphore has been closed, this returns a TryAcquireError::Closed and a TryAcquireError::NoPermits if there are not enough permits left. Otherwise, this returns an OwnedRankedSemaphorePermit representing the acquired permit.