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
impl Mutex
sourcepub fn new() -> Result<Mutex>
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.