pub struct Semaphore { /* private fields */ }Expand description
A counting or binary semaphore
Implementations§
Source§impl Semaphore
impl Semaphore
Sourcepub fn new_binary() -> Result<Semaphore, FreeRtosError>
pub fn new_binary() -> Result<Semaphore, FreeRtosError>
Create a new binary semaphore
Sourcepub fn new_counting(max: u32, initial: u32) -> Result<Semaphore, FreeRtosError>
pub fn new_counting(max: u32, initial: u32) -> Result<Semaphore, FreeRtosError>
Create a new counting semaphore
Sourcepub unsafe fn from_raw_handle(handle: FreeRtosSemaphoreHandle) -> Self
pub unsafe fn from_raw_handle(handle: FreeRtosSemaphoreHandle) -> Self
§Safety
handle must be a valid FreeRTOS semaphore handle.
Only binary or counting semaphore is expected here.
To create mutex from raw handle use crate::mutex::MutexInnerImpl::from_raw_handle.
pub fn raw_handle(&self) -> FreeRtosSemaphoreHandle
Sourcepub fn lock<D: DurationTicks>(
&self,
max_wait: D,
) -> Result<SemaphoreGuard<'_>, FreeRtosError>
pub fn lock<D: DurationTicks>( &self, max_wait: D, ) -> Result<SemaphoreGuard<'_>, FreeRtosError>
Lock this semaphore in a RAII fashion
Sourcepub fn give(&self) -> bool
pub fn give(&self) -> bool
Returns true on success, false when semaphore count already reached its limit
pub fn take<D: DurationTicks>(&self, max_wait: D) -> Result<(), FreeRtosError>
Sourcepub fn give_from_isr(&self, context: &mut InterruptContext) -> bool
pub fn give_from_isr(&self, context: &mut InterruptContext) -> bool
Returns true on success, false when semaphore count already reached its limit
Sourcepub fn take_from_isr(&self, context: &mut InterruptContext) -> bool
pub fn take_from_isr(&self, context: &mut InterruptContext) -> bool
Returns true on success, false if the semaphore was not successfully taken because it was not available