Trait r3_core::kernel::semaphore::SemaphoreMethods
source · 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§
sourcefn drain(&self) -> Result<(), DrainSemaphoreError>
fn drain(&self) -> Result<(), DrainSemaphoreError>
Remove all permits held by the semaphore.
sourcefn get(&self) -> Result<SemaphoreValue, GetSemaphoreError>
fn get(&self) -> Result<SemaphoreValue, GetSemaphoreError>
Get the number of permits currently held by the semaphore.
sourcefn signal(&self, count: SemaphoreValue) -> Result<(), SignalSemaphoreError>
fn signal(&self, count: SemaphoreValue) -> Result<(), SignalSemaphoreError>
Release count
permits, returning them to the semaphore.
sourcefn signal_one(&self) -> Result<(), SignalSemaphoreError>
fn signal_one(&self) -> Result<(), SignalSemaphoreError>
Release a permit, returning it to the semaphore.
sourcefn wait_one(&self) -> Result<(), WaitSemaphoreError>
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.
sourcefn wait_one_timeout(
&self,
timeout: Duration
) -> Result<(), WaitSemaphoreTimeoutError>
fn wait_one_timeout( &self, timeout: Duration ) -> Result<(), WaitSemaphoreTimeoutError>
wait_one
with timeout.
sourcefn poll_one(&self) -> Result<(), PollSemaphoreError>
fn poll_one(&self) -> Result<(), PollSemaphoreError>
Non-blocking version of wait_one
. Returns
immediately with PollSemaphoreError::Timeout
if the unblocking
condition is not satisfied.