zephyr::sys::sync::mutex

Struct Mutex

source
pub struct Mutex { /* private fields */ }
Expand description

A Zephyr k_mutux usable from safe Rust code.

This merely wraps a pointer to the kernel object. It implements clone, send and sync as it is safe to have multiple instances of these, as well as use them across multiple threads.

Note that these are Safe in the sense that memory safety is guaranteed. Attempts to recursively lock, or incorrect nesting can easily result in deadlock.

Safety: Typically, the Mutex type in Rust does not implement Clone, and must be shared between threads using Arc. However, these sys Mutexes are wrappers around static kernel objects, and Drop doesn’t make sense for them. In addition, Arc requires alloc, and one possible place to make use of the sys Mutex is to be able to do so in an environment without alloc.

This mutex type of only of limited use to application programs. It can be used as a simple binary semaphore, although it has strict semantics, requiring the release to be called by the same thread that called lock. It can be used to protect data that Rust itself is either not managing, or is managing in an unsafe way.

For a Mutex type that is useful in a Rust type of manner, please see the regular sync::Mutex type.

Implementations§

source§

impl Mutex

source

pub fn new() -> Result<Mutex>

Create a new Mutex in an unlocked state.

Create a new dynamically allocated Mutex. The Mutex can only be used from system threads.

source

pub fn lock<T>(&self, timeout: T) -> Result<()>
where T: Into<Timeout>,

Lock a Zephyr Mutex.

Will wait for the lock, returning status, with Ok(()) indicating the lock has been acquired, and an error indicating a timeout (Zephyr returns different errors depending on the reason).

source

pub fn unlock(&self) -> Result<()>

Unlock a Zephyr Mutex.

The mutex must already be locked by the calling thread. Mutexes may not be unlocked in ISRs.

Trait Implementations§

source§

impl Debug for Mutex

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Send for Mutex

source§

impl Sync for Mutex

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

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

source§

type Error = Infallible

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

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

Performs the conversion.
source§

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

source§

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

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

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

Performs the conversion.