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>
impl TokenParts<true, true, true>
Sourcepub unsafe fn new() -> Self
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 MQ: bool, const FS: bool> TokenParts<true, MQ, FS>
impl<const MQ: bool, const FS: bool> TokenParts<true, MQ, FS>
Sourcepub fn take_msg_semantics(
self,
) -> (TokenParts<false, MQ, FS>, NoConfiguredMessages)
Available on crate feature with_msg_v2
only.
pub fn take_msg_semantics( self, ) -> (TokenParts<false, MQ, FS>, NoConfiguredMessages)
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>
impl<const MQ: bool, const FS: bool> TokenParts<false, MQ, FS>
Sourcepub fn return_msg_semantics(
self,
semantics: NoConfiguredMessages,
) -> TokenParts<true, MQ, FS>
Available on crate feature with_msg_v2
only.
pub fn return_msg_semantics( self, semantics: NoConfiguredMessages, ) -> TokenParts<true, MQ, FS>
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>
impl<const MS: bool, const FS: bool> TokenParts<MS, true, FS>
Sourcepub fn with_message_queue<const N: usize, F: FnOnce(TokenParts<MS, false, FS>) -> !>(
self,
f: F,
) -> !
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>
impl<const MQ: bool> TokenParts<true, MQ, true>
Sourcepub fn can_end(self) -> EndToken
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoSwitch for T
impl<T> IntoSwitch for T
Source§fn into_switch<ActiveLevel>(self) -> Switch<T, ActiveLevel>
fn into_switch<ActiveLevel>(self) -> Switch<T, ActiveLevel>
Source§fn into_active_high_switch(self) -> Switch<Self, ActiveHigh>where
Self: Sized,
fn into_active_high_switch(self) -> Switch<Self, ActiveHigh>where
Self: Sized,
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