pub struct Semaphore { /* private fields */ }Expand description
Semaphore and mutex primitives.
Implementations§
Source§impl Semaphore
impl Semaphore
Sourcepub const fn new_counting(initial: u32, max: u32) -> Self
pub const fn new_counting(initial: u32, max: u32) -> Self
Create a new counting semaphore.
Sourcepub const fn new_mutex(recursive: bool) -> Self
pub const fn new_mutex(recursive: bool) -> Self
Create a new mutex.
If recursive is true, the mutex can be locked multiple times by the same task.
Sourcepub fn try_take(&self) -> bool
pub fn try_take(&self) -> bool
Try to take the semaphore.
This is a non-blocking operation. The return value indicates whether the semaphore was successfully taken.
Sourcepub fn try_take_from_isr(&self) -> bool
pub fn try_take_from_isr(&self) -> bool
Try to take the semaphore from an ISR.
This is a non-blocking operation. The return value indicates whether the semaphore was successfully taken.
Sourcepub fn take(&self, timeout_us: Option<u32>) -> bool
pub fn take(&self, timeout_us: Option<u32>) -> bool
Take the semaphore.
This is a blocking operation.
If the semaphore is already taken, the task will be blocked until the semaphore is released. Recursive mutexes can be locked multiple times by the mutex owner task.
Sourcepub fn current_count(&self) -> u32
pub fn current_count(&self) -> u32
Return the current count of the semaphore.
Sourcepub fn try_give_from_isr(&self) -> bool
pub fn try_give_from_isr(&self) -> bool
Try to unlock the semaphore from an ISR.
The return value indicates whether the semaphore was successfully unlocked.