Module drone_cortexm::fib [−][src]
The Fibers module.
NOTE This module documentation should be viewed as a continuation of
the drone_core
documentation.
Stackful Fibers
This module implements stackful fibers that are similar to native threads in
the Rust stdlib. They can run synchronous code inside and yield with a
blocking call. A stackful fiber can be created with
fib::new_proc
,
fib::new_proc_unchecked
,
fib::new_proc_unprivileged
,
fib::new_proc_unprivileged_unchecked
:
use drone_cortexm::{fib, sv}; use drone_cortexm::sv::{SwitchBackService, SwitchContextService}; // Stackful fibers need a supervisor. sv::pool! { pool => SERVICES; supervisor => pub Sv; services => { // These services are required for stackful fibers. SwitchContextService; SwitchBackService; } } // This is `impl Fiber<Input = bool, Yield = i32, Return = usize>` let a = fib::new_proc::<Sv, bool, i32, usize, _>(0x800, |input, yielder| { // do some work and yield yielder.proc_yield(1); // do some work and yield yielder.proc_yield(2); // do some work and return 3 });
A stackful fiber can be attached to a thread with
token.add_proc(...)
,
token.add_proc_unchecked(...)
,
token.add_proc_unprivileged(...)
,
token.add_proc_unprivileged_unchecked(...)
.
Note that fibers that are directly attached to threads can’t have input,
yield and return values other than ()
.
use drone_cortexm::thr::prelude::*; // this is `impl Fiber<Input = (), Yield = (), Return = ()>` thr.sys_tick.add_proc(0x800, |yielder| { // do some work and yield yielder.proc_yield(()); // do some work and yield yielder.proc_yield(()); // do some work and return });
Re-exports
pub use drone_core::fib::*; |
Structs
FiberProc | Stackful fiber for |
Yielder | A zero-sized token that provides |
Traits
ThrFiberProc | Extends |
Functions
new_proc | Creates a stackful fiber from the closure |
new_proc_unchecked⚠ | Creates a stackful fiber from the closure |
new_proc_unprivileged | Creates a stackful fiber from the closure |
new_proc_unprivileged_unchecked⚠ | Creates a stackful fiber from the closure |