pub struct SemaphoreHandle(/* private fields */);Expand description
Semaphore handle.
This handle is used to interact with semaphores created by the driver implementation.
Implementations§
Source§impl SemaphoreHandle
impl SemaphoreHandle
Sourcepub fn new(kind: SemaphoreKind) -> Self
pub fn new(kind: SemaphoreKind) -> Self
Creates a new semaphore instance.
kind specifies the type of semaphore to create.
- Use
SemaphoreKind::Countingto create counting semaphores and non-recursive mutexes. - Use
SemaphoreKind::RecursiveMutexto create recursive mutexes.
Sourcepub fn leak(self) -> SemaphorePtr
pub fn leak(self) -> SemaphorePtr
Converts this object into a pointer without dropping it.
Sourcepub unsafe fn from_ptr(ptr: SemaphorePtr) -> Self
pub unsafe fn from_ptr(ptr: SemaphorePtr) -> Self
Recovers the object from a leaked pointer.
§Safety
- The caller must only use pointers created using
Self::leak. - The caller must ensure the pointer is not shared.
Sourcepub unsafe fn ref_from_ptr(ptr: &SemaphorePtr) -> &Self
pub unsafe fn ref_from_ptr(ptr: &SemaphorePtr) -> &Self
Creates a reference to this object from a leaked pointer.
This function is used in the esp-radio code to interact with the semaphore.
§Safety
- The caller must only use pointers created using
Self::leak.
Sourcepub fn take(&self, timeout_us: Option<u32>) -> bool
pub fn take(&self, timeout_us: Option<u32>) -> bool
Increments the semaphore’s counter.
If a timeout is given, this function blocks until either a semaphore could be taken, or the timeout has been reached. If no timeout is given, this function blocks until the operation succeeds.
This function returns true if the semaphore was taken, false if the timeout was reached.
Sourcepub fn give(&self) -> bool
pub fn give(&self) -> bool
Increments the semaphore’s counter.
This function returns true if the semaphore was given, false if the counter is at its
maximum.
Sourcepub fn try_give_from_isr(
&self,
higher_prio_task_waken: Option<&mut bool>,
) -> bool
pub fn try_give_from_isr( &self, higher_prio_task_waken: Option<&mut bool>, ) -> bool
Attempts to increment the semaphore’s counter from an ISR.
If the counter is at its maximum, this function returns false.
If the flag is Some, the implementation may set it to true to request a context switch.
Sourcepub fn current_count(&self) -> u32
pub fn current_count(&self) -> u32
Returns the current counter value.
Sourcepub fn try_take(&self) -> bool
pub fn try_take(&self) -> bool
Attempts to decrement the semaphore’s counter.
If the counter is zero, this function returns false.
Sourcepub fn try_take_from_isr(
&self,
higher_prio_task_waken: Option<&mut bool>,
) -> bool
pub fn try_take_from_isr( &self, higher_prio_task_waken: Option<&mut bool>, ) -> bool
Attempts to decrement the semaphore’s counter from an ISR.
If the counter is zero, this function returns false.
If a higher priority task is woken up by this operation, the higher_prio_task_waken flag
is set to true.