zephyr::work

Struct Signal

Source
pub struct Signal { /* private fields */ }
Expand description

A Rust wrapper for k_poll_signal.

A signal in Zephyr is an event mechanism that can be used to trigger actions in event queues to run. The work somewhat like a kind of half boolean semaphore. The signaling is robust in the direction of the event happening, as in a blocked task will definitely wake when the signal happens. However, the clearing of the signal is racy. Generally, there are two ways to do this:

  • A work action can clear the signal as soon as it wakes up, before it starts processing any data the signal was meant to indicate. If the race happens, the processing will handle the extra data.
  • A work action can clear the signal after it does it’s processing. This is useful for things like periodic timers, where if it is still processing when an additional timer tick comes in, that timer tick will be ignored. This is useful for periodic events where it is better to just skip a tick rather than for them to “stack up” and get behind.

Notably, as long as the reset method is only ever called by the worker that is waiting upon it, there shouldn’t ever be a race in the wait_async itself.

Signals can pass a c_int from the signalling task to the task that is waiting for the signal. It is not specified in the Zephyr documentation what value will be passed if raise is called multiple times before a task waits upon a signal. The current implementation will return the most recent raised result value.

For most other use cases, channels or semaphores are likely to be better solutions.

Implementations§

Source§

impl Signal

Source

pub fn new() -> Signal

Create a new Signal.

The Signal will be in the non-signaled state.

Source

pub fn reset(&self)

Reset the Signal

This resets the signal state to unsignaled.

Please see the Signal documentation on how to handle the races that this implies.

Source

pub fn check(&self) -> Option<c_int>

Check the status of a signal.

This reads the status of the signal. If the state is “signalled”, this will return Some(result) where the result is the result value given to raise.

Source

pub fn raise(&self, result: c_int) -> Result<()>

Signal a signal object.

This will signal to any worker that is waiting on this object that the event has happened. The result will be returned from the worker’s wait call.

As per the Zephyr docs, this could return an EAGAIN error if the polling thread is in the process of expiring. The implication is that the signal will not be raised in this case. …

Source

pub fn wait_async<'a>( &'a self, timeout: impl Into<Timeout>, ) -> impl Future<Output = Result<c_int>> + 'a

Asynchronously wait for a signal to be signaled.

If the signal has not been raised, will wait until it has been. If the signal has been raised, the Future will immediately return that value without waiting.

Note: there is no sync wait, as Zephyr does not provide a convenient mechanmism for this. It could be implemented with k_poll if needed.

Trait Implementations§

Source§

impl Default for Signal

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Send for Signal

Source§

impl Sync for Signal

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.