pub struct SharedSemaphore { /* private fields */ }Implementations§
Sourcepub fn create(
base_path: impl AsRef<Path>,
initial: u32,
max_permits: u32,
) -> Result<Self, SemaphoreError>
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).
Sourcepub fn open(
base_path: impl AsRef<Path>,
max_permits: u32,
) -> Result<Self, SemaphoreError>
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).
Sourcepub fn try_acquire(&self) -> Result<Permit<'_>, SemaphoreError>
pub fn try_acquire(&self) -> Result<Permit<'_>, SemaphoreError>
Non-blocking acquire. Returns Err(WouldBlock) immediately
when no permits are available.
Sourcepub fn acquire(&self) -> Permit<'_>
pub fn acquire(&self) -> Permit<'_>
Blocking acquire. Spins on a generation-counter wakeup signal; yields between spins and sleeps briefly after a yield budget.
Sourcepub fn acquire_timeout(
&self,
timeout: Duration,
) -> Result<Permit<'_>, SemaphoreError>
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.
Sourcepub fn release(&self) -> Result<(), SemaphoreError>
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.
Sourcepub fn max_permits(&self) -> u32
pub fn max_permits(&self) -> u32
Maximum permit cap configured at construction.
Sourcepub fn wakeup_generation(&self) -> u64
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.
Sourcepub fn mark_waiter_entered(&self)
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).
Sourcepub fn mark_waiter_left(&self)
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).
Sourcepub fn flush(&self) -> Result<(), SemaphoreError>
pub fn flush(&self) -> Result<(), SemaphoreError>
Sync all three files to disk.
Sourcepub fn flush_async(&self) -> Result<(), SemaphoreError>
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).