riot_wrappers::thread

Struct TokenParts

Source
pub struct TokenParts<const MSG_SEMANTICS: bool, const MSG_QUEUE: bool, const FLAG_SEMANTICS: bool> {
    pub(super) _not_send: PhantomData<*const ()>,
}
Expand description

A StartToken that has possibly already lost some of its properties.

Note that while this item shows up in the documentation, the type is actually hidden and only named as StartToken. This ensures that more properties can be added compatibly (because no user ever names the type and would thus run into conflicts when the list of generics grows). This has the downside that TokenParts can not easily be passed to downstream functions, and all splitting has to happen at the top level; this should not be a problem in practice.

The individual parameters are:

  • MSG_SEMANTICS: If this is true, the thread has not assigned semantics to messages it would receive yet.
  • MSG_QUEUE: If this is true, the thread has not yet set up a message queue.
  • FLAG_SEMANTICS: If this is true, the thread has not assigned semantics to flags yet.

(FLAG_SEMANTICS are not used yet, but are already prepared for a wrapper similar to msg::v2).

Fields§

§_not_send: PhantomData<*const ()>

Implementations§

Source§

impl TokenParts<true, true, true>

Source

pub unsafe fn new() -> Self

Claim that the current thread has not done anything yet that is covered by this type

Do not call yourself; this needs to be public because riot_main! is a macro and thus technically called from the main crate.

Source§

impl<const MS: bool, const MQ: bool, const FS: bool> TokenParts<MS, MQ, FS>

Source

pub fn in_thread(&self) -> InThread

Extract a token that states that code that has access to it is running in a thread (and not in an interrupt).

Source§

impl<const MQ: bool, const FS: bool> TokenParts<true, MQ, FS>

Source

pub fn take_msg_semantics( self, ) -> (TokenParts<false, MQ, FS>, NoConfiguredMessages)

Available on crate feature with_msg_v2 only.

Extract the claim that the thread was not previously configured with any messages that would be sent to it.

§Example
fn thread(tok: StartToken) -> EndToken {
    let (tok, semantics) = tok.take_msg_semantics();
    // keep working with semantics and start receiving messages
    //
    // receive messages
    //
    // recover semantics when everyone has returned the license to send messages
    let tok = tok.return_msg_semantics(semantics);
    tok.can_end()
}
Source§

impl<const MQ: bool, const FS: bool> TokenParts<false, MQ, FS>

Source

pub fn return_msg_semantics( self, semantics: NoConfiguredMessages, ) -> TokenParts<true, MQ, FS>

Available on crate feature with_msg_v2 only.

Inverse of TokenParts::take_msg_semantics, indicating that the thread may be terminated again as far as message semantics are concerned.

Source§

impl<const MS: bool, const FS: bool> TokenParts<MS, true, FS>

Source

pub fn with_message_queue<const N: usize, F: FnOnce(TokenParts<MS, false, FS>) -> !>( self, f: F, ) -> !

Set up a message queue of given size N, and run the function f after that has been set up. f gets passed all the remaining thread invariants.

As this doesn’t deal with the message semantics, it can’t be sure whether at function return time all other system components have stopped sending messages; the easy way out is to require the function to diverge.

§Example
fn thread(tok: StartToken) -> EndToken {
    tok.with_message_queue::<4, _>(|tok| {
        loop {
            // ...
        }
    })
}
Source§

impl<const MQ: bool> TokenParts<true, MQ, true>

Source

pub fn can_end(self) -> EndToken

Certify that nothing has been done in this thread that precludes the termination of the thread

MessageSemantics need to have been returned (or never taken) for the next thread on this PID would get weird messages.

The MessageQueue is not checked for – as all MessageSemantics have been returned (and thus nothing can safely send messages any more), even if there is a queue somewhere on the stack, it wouldn’t be touched by others any more. (Of course, that’s moot with the current mechanism of TokenParts::with_message_queue() as that diverges anyway).

Auto Trait Implementations§

§

impl<const MSG_SEMANTICS: bool, const MSG_QUEUE: bool, const FLAG_SEMANTICS: bool> Freeze for TokenParts<MSG_SEMANTICS, MSG_QUEUE, FLAG_SEMANTICS>

§

impl<const MSG_SEMANTICS: bool, const MSG_QUEUE: bool, const FLAG_SEMANTICS: bool> RefUnwindSafe for TokenParts<MSG_SEMANTICS, MSG_QUEUE, FLAG_SEMANTICS>

§

impl<const MSG_SEMANTICS: bool, const MSG_QUEUE: bool, const FLAG_SEMANTICS: bool> !Send for TokenParts<MSG_SEMANTICS, MSG_QUEUE, FLAG_SEMANTICS>

§

impl<const MSG_SEMANTICS: bool, const MSG_QUEUE: bool, const FLAG_SEMANTICS: bool> !Sync for TokenParts<MSG_SEMANTICS, MSG_QUEUE, FLAG_SEMANTICS>

§

impl<const MSG_SEMANTICS: bool, const MSG_QUEUE: bool, const FLAG_SEMANTICS: bool> Unpin for TokenParts<MSG_SEMANTICS, MSG_QUEUE, FLAG_SEMANTICS>

§

impl<const MSG_SEMANTICS: bool, const MSG_QUEUE: bool, const FLAG_SEMANTICS: bool> UnwindSafe for TokenParts<MSG_SEMANTICS, MSG_QUEUE, FLAG_SEMANTICS>

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> IntoSwitch for T

Source§

fn into_switch<ActiveLevel>(self) -> Switch<T, ActiveLevel>

Consumes the IoPin returning a Switch of the appropriate ActiveLevel. Read more
Source§

fn into_active_low_switch(self) -> Switch<Self, ActiveLow>
where Self: Sized,

Consumes the IoPin returning a Switch<IoPin, ActiveLow>. Read more
Source§

fn into_active_high_switch(self) -> Switch<Self, ActiveHigh>
where Self: Sized,

Consumes the IoPin returning a Switch<IoPin, ActiveHigh>. Read more
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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 0 bytes