Skip to main content

SharedSemaphore

Struct SharedSemaphore 

Source
pub struct SharedSemaphore { /* private fields */ }

Implementations§

Source§

impl SharedSemaphore

Source

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

Create a new semaphore with initial available permits and an upper bound max_permits (release fails if it pushes count above this).

Source

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

Open an existing semaphore. Must pass the same max_permits the creator used; this is enforced only at release time, so open is cheap (no header magic check beyond what the underlying atomic provides).

Source

pub fn try_acquire(&self) -> Result<Permit<'_>, SemaphoreError>

Non-blocking acquire. Returns Err(WouldBlock) immediately when no permits are available.

Source

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

Blocking acquire. Spins on a generation-counter wakeup signal; yields between spins and sleeps briefly after a yield budget.

Source

pub fn acquire_timeout( &self, timeout: Duration, ) -> Result<Permit<'_>, SemaphoreError>

Blocking acquire with deadline. Returns Err(Timeout) when the deadline passes before a permit becomes available.

Source

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

Standalone release (one permit). Use this when a Permit guard has been mem::forgotten to transfer ownership across an API boundary that can’t carry the lifetime. Returns Err(ReleaseOverflow) if releasing pushes the count past max_permits; rolls back the count in that case.

Source

pub fn available(&self) -> u32

Currently available permit count (observational; may race).

Source

pub fn waiters(&self) -> u32

Currently waiting acquirers (observational).

Source

pub fn max_permits(&self) -> u32

Maximum permit cap configured at construction.

Source

pub fn wakeup_generation(&self) -> u64

Current wakeup-generation counter snapshot. Used by the BlockingSemaphore wrapper to compute waker park targets: the wrapper snapshots this BEFORE checking available(), then parks at snapshot + 1. Any subsequent release bumps the generation, which the wake call observes as seq >= target.

Source

pub fn mark_waiter_entered(&self)

Mark the calling thread as entering the waiter set. Callers must pair every mark_waiter_entered with exactly one mark_waiter_left. The existing acquire / acquire_timeout slow paths call these around their sleep loop; the BlockingSemaphore wrapper calls them around its kernel-park slow path.

The internal release path keys its wakeup-bump on waiters > 0, so a parker that does NOT register here will not be woken (the wakeup generation stays unchanged).

Source

pub fn mark_waiter_left(&self)

Counterpart to mark_waiter_entered. Must be called exactly once per entered marker (regardless of whether the parker woke from the release or timed out).

Source

pub fn flush(&self) -> Result<(), SemaphoreError>

Sync all three files to disk.

Source

pub fn flush_async(&self) -> Result<(), SemaphoreError>

Non-blocking flush of all three files. Delegates to each inner SharedAtomic’s flush_async. Note: Windows is only partially async (sync to page cache, not to disk).

Trait Implementations§

Source§

impl AdaptiveInstance for SharedSemaphore

Source§

fn header(&self) -> &HandshakeHeader

Source§

fn ring(&self) -> &ObservationRing

Source§

fn make_policy(&self) -> Box<dyn Policy>

Source§

fn apply_migration(&self, new_tag: u32)

Called by the sidecar when the policy returns a new strategy tag. Default implementation: just set the tag on the header. Primitives that need heavier migration (data-layout swap) override this to perform the swap before (or after) updating the tag.

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.