pub trait SemaphoreMethods: SemaphoreHandle {
    // Provided methods
    fn drain(&self) -> Result<(), DrainSemaphoreError> { ... }
    fn get(&self) -> Result<SemaphoreValue, GetSemaphoreError> { ... }
    fn signal(&self, count: SemaphoreValue) -> Result<(), SignalSemaphoreError> { ... }
    fn signal_one(&self) -> Result<(), SignalSemaphoreError> { ... }
    fn wait_one(&self) -> Result<(), WaitSemaphoreError> { ... }
    fn wait_one_timeout(
        &self,
        timeout: Duration
    ) -> Result<(), WaitSemaphoreTimeoutError> { ... }
    fn poll_one(&self) -> Result<(), PollSemaphoreError> { ... }
}
Expand description

The supported operations on SemaphoreHandle.

Provided Methods§

source

fn drain(&self) -> Result<(), DrainSemaphoreError>

Remove all permits held by the semaphore.

source

fn get(&self) -> Result<SemaphoreValue, GetSemaphoreError>

Get the number of permits currently held by the semaphore.

source

fn signal(&self, count: SemaphoreValue) -> Result<(), SignalSemaphoreError>

Release count permits, returning them to the semaphore.

source

fn signal_one(&self) -> Result<(), SignalSemaphoreError>

Release a permit, returning it to the semaphore.

source

fn wait_one(&self) -> Result<(), WaitSemaphoreError>

Acquire a permit, potentially blocking the calling thread until one is available.

This system service may block. Therefore, calling this method is not allowed in a non-waitable context and will return Err(BadContext).

Rationale: Multi-wait (waiting for more than one permit) is not supported because it introduces additional complexity to the wait queue mechanism by requiring it to reevaluate wait conditions after reordering the queue.

The support for multi-wait is relatively rare among operating systems. It’s not supported by POSIX, RTEMS, TOPPERS, VxWorks, nor Win32. The rare exception is μT-Kernel.

source

fn wait_one_timeout( &self, timeout: Duration ) -> Result<(), WaitSemaphoreTimeoutError>

wait_one with timeout.

source

fn poll_one(&self) -> Result<(), PollSemaphoreError>

Non-blocking version of wait_one. Returns immediately with PollSemaphoreError::Timeout if the unblocking condition is not satisfied.

Implementors§