Struct RankedSemaphore

Source
pub struct RankedSemaphore { /* private fields */ }
Expand description

High-performance priority semaphore

Implementations§

Source§

impl RankedSemaphore

Source

pub const MAX_PERMITS: usize = 536_870_911usize

Maximum permits (reserve 3 bits for flags, same as tokio)

Source

pub fn new_fifo(permits: usize) -> Self

Create FIFO semaphore

Source

pub fn new_lifo(permits: usize) -> Self

Create LIFO semaphore

Source

pub fn new(permits: usize, default_strategy: QueueStrategy) -> Self

Create semaphore with specified strategy

Source

pub fn new_with_config(permits: usize, config: PriorityConfig) -> Self

Create semaphore with custom configuration

Source

pub fn available_permits(&self) -> usize

Get current available permits

Source

pub fn is_closed(&self) -> bool

Check if semaphore is closed

Source

pub fn add_permits(&self, added: usize)

Add permits and notify waiters if any.

Source

pub fn close(&self)

Close semaphore and cancel all pending waiters.

Source

pub fn acquire(&self) -> Acquire<'_>

Acquire with default priority

Source

pub fn acquire_with_priority(&self, priority: isize) -> Acquire<'_>

Acquire with specified priority

Source

pub fn acquire_many(&self, n: u32) -> Acquire<'_>

Acquire many permits (default priority)

Source

pub fn acquire_many_with_priority(&self, priority: isize, n: u32) -> Acquire<'_>

Acquire many permits with priority

Source

pub fn try_acquire(&self) -> Result<RankedSemaphorePermit<'_>, TryAcquireError>

Try acquire single permit (non-blocking)

Source

pub fn try_acquire_many( &self, n: u32, ) -> Result<RankedSemaphorePermit<'_>, TryAcquireError>

Try acquire many permits (non-blocking)

Source

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.

Source

pub fn acquire_owned(self: Arc<Self>) -> AcquireOwned

Acquire owned permit (default priority)

Source

pub fn acquire_owned_with_priority( self: Arc<Self>, priority: isize, ) -> AcquireOwned

Acquire owned permit with priority

Source

pub fn acquire_many_owned(self: Arc<Self>, n: u32) -> AcquireOwned

Acquire many owned permits (default priority)

Source

pub fn acquire_many_owned_with_priority( self: Arc<Self>, priority: isize, n: u32, ) -> AcquireOwned

Acquire many owned permits with priority

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for RankedSemaphore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.