Skip to main content

BlockingSemaphore

Struct BlockingSemaphore 

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

Cross-process semaphore with a kernel-park slow path.

Implementations§

Source§

impl BlockingSemaphore

Source

pub fn create( base_path: impl AsRef<Path>, max_permits: u32, init_permits: u32, ) -> Result<Self, BlockingSemaphoreError>

Create a new blocking semaphore. Lays out the underlying SharedSemaphore files plus a <base>.waker.bin for the waker. Caller picks max_permits (capacity) and init_permits (starting value); see SharedSemaphore::create for semantics.

Source

pub fn open( base_path: impl AsRef<Path>, expected_max_permits: u32, ) -> Result<Self, BlockingSemaphoreError>

Open an existing blocking semaphore.

Source

pub fn try_acquire(&self) -> Result<BlockingPermit<'_>, BlockingSemaphoreError>

Non-blocking acquire. Pure CAS; never sleeps.

Source

pub fn acquire_park(&self) -> Result<BlockingPermit<'_>, BlockingSemaphoreError>

Blocking acquire with kernel-park slow path. Returns when a permit is available. No timeout variant returns Err(Timeout); for a bounded wait use acquire_park_timeout.

Source

pub fn acquire_park_timeout( &self, timeout: Duration, ) -> Result<BlockingPermit<'_>, BlockingSemaphoreError>

Blocking acquire with bounded wait. Err(Timeout) when the timeout elapses before a permit is available.

Source

pub fn release(&self) -> Result<(), BlockingSemaphoreError>

Release one permit. Bumps the inner generation atom and fires wake_up_to(new_gen) on the waker.

Source

pub fn available(&self) -> u32

Available-permits observation (may race).

Source

pub fn max_permits(&self) -> u32

Cap fixed at construction.

Source

pub fn inner(&self) -> &Arc<SharedSemaphore>

Inner primitive (for sidecar / observability hooks).

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.