pub struct Semaphore { /* private fields */ }Expand description
A counting semaphore without priority inheritance or task ownership.
up and try_down are IRQ-safe. Blocking acquisition is task-only and
grants queued waiters in FIFO order without allowing a new caller to steal
a published grant.
Implementations§
Source§impl Semaphore
impl Semaphore
Sourcepub const fn new(permits: usize) -> Semaphore
pub const fn new(permits: usize) -> Semaphore
Creates a semaphore with permits initially available grants.
Sourcepub fn try_down(&self) -> bool
pub fn try_down(&self) -> bool
Consumes one available permit without blocking, including in IRQ context.
Sourcepub fn up(&self) -> Result<(), SemaphoreError>
pub fn up(&self) -> Result<(), SemaphoreError>
Releases a permit or directly grants the oldest queued waiter.
Sourcepub fn down(&self) -> Result<(), SemaphoreError>
pub fn down(&self) -> Result<(), SemaphoreError>
Waits without interruption until one permit is granted.
Sourcepub fn down_interruptible(
&self,
interrupted: impl FnMut() -> bool,
) -> Result<(), SemaphoreError>
pub fn down_interruptible( &self, interrupted: impl FnMut() -> bool, ) -> Result<(), SemaphoreError>
Waits until a permit is granted or an ordinary wake observes interruption. The interruption publisher must also wake this task.
Sourcepub fn down_until(
&self,
deadline: MonotonicDeadline,
) -> Result<(), SemaphoreError>
pub fn down_until( &self, deadline: MonotonicDeadline, ) -> Result<(), SemaphoreError>
Waits for a permit until an absolute monotonic deadline.
Auto Trait Implementations§
impl !Freeze for Semaphore
impl !RefUnwindSafe for Semaphore
impl !UnwindSafe for Semaphore
impl Send for Semaphore
impl Sync for Semaphore
impl Unpin for Semaphore
impl UnsafeUnpin for Semaphore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more