pub type StartToken = TokenParts<true, true, true>;
Expand description
Data created for each thread that is spawned.
It encodes for permission to do anything that can only be done once per thread.
Aliased Type§
struct StartToken {
pub(super) _not_send: PhantomData<*const ()>,
}
Fields§
§_not_send: PhantomData<*const ()>
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
Implementations
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, 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> 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).
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.