SemaphoreHandle

Struct SemaphoreHandle 

Source
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

Source

pub fn new(kind: SemaphoreKind) -> Self

Creates a new semaphore instance.

kind specifies the type of semaphore to create.

  • Use SemaphoreKind::Counting to create counting semaphores and non-recursive mutexes.
  • Use SemaphoreKind::RecursiveMutex to create recursive mutexes.
Source

pub fn leak(self) -> SemaphorePtr

Converts this object into a pointer without dropping it.

Source

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.
Source

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.
Source

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.

Source

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.

Source

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.

Source

pub fn current_count(&self) -> u32

Returns the current counter value.

Source

pub fn try_take(&self) -> bool

Attempts to decrement the semaphore’s counter.

If the counter is zero, this function returns false.

Source

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.

Trait Implementations§

Source§

impl Drop for SemaphoreHandle

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for SemaphoreHandle

§

impl RefUnwindSafe for SemaphoreHandle

§

impl !Send for SemaphoreHandle

§

impl !Sync for SemaphoreHandle

§

impl Unpin for SemaphoreHandle

§

impl UnwindSafe for SemaphoreHandle

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.