zephyr::sync

Struct Condvar

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

Inspired by std::sync::Condvar, implemented directly using z_condvar in Zephyr.

Condition variables represent the ability to block a thread such that it consumes no CPU time while waiting for an even to occur. Condition variables are typically associated with a boolean predicate (a condition) and a mutex. The predicate is always verified inside of the mutex before determining that a thread must block.

Functions in this module will block the current thread of execution. Note that any attempt to use multiple mutexces on the same condition variable may result in a runtime panic.

Implementations§

source§

impl Condvar

source

pub const fn new_from(raw_condvar: Condvar) -> Condvar

Construct a new wrapped Condvar, using the given underlying k_condvar.

This is different from std::sync::Condvar in that in Zephyr, objects are frequently allocated statically, and the sys Condvar will be taken by this structure.

source

pub fn new() -> Condvar

Construct a new Condvar, dynamically allocating the underlying Zephyr k_condvar.

source

pub fn wait<'a, T>( &self, guard: MutexGuard<'a, T>, ) -> LockResult<MutexGuard<'a, T>>

Blocks the current thread until this conditional variable receives a notification.

This function will automatically unlock the mutex specified (represented by guard) and block the current thread. This means that any calls to notify_one or notify_all which happen logically after the mutex is unlocked are candidates to wake this thread up. When this function call returns, the lock specified will have been re-equired.

Note that this function is susceptable to spurious wakeups. Condition variables normally have a boolean predicate associated with them, and the predicate must always be checked each time this function returns to protect against spurious wakeups.

source

pub fn notify_one(&self)

Wakes up one blocked thread on this condvar.

If there is a blocked thread on this condition variable, then it will be woken up from its call to wait or wait_timeout. Calls to notify_one are not buffered in any way.

To wakeup all threads, see notify_all.

source

pub fn notify_all(&self)

Wakes up all blocked threads on this condvar.

This methods will ensure that any current waiters on the condition variable are awoken. Calls to notify_all() are not buffered in any way.

To wake up only one thread, see notify_one.

Trait Implementations§

source§

impl Debug for Condvar

source§

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

Formats the value using the given formatter. Read more

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.