pub fn run_tasks(
futures: &mut [Pin<&mut dyn Future<Output = Infallible>>],
initial_mask: usize
) -> !
Expand description
Runs the given futures forever, sleeping when possible. Each future acts as
a task, in the sense of core::task
– that is, it is a top-level entity
that can wake up separately from the other tasks.
Task futures must not ever resolve/complete – they need to be infinite
loops or equivalent. Due to limitations in the language, this requires their
return type to be Infallible
, which is an awkward way of writing !
.
Not all tasks are polled every time through the loop. On the first
iteration, only the tasks with a corresponding bit set in initial_mask
are
polled; on subsequent passes, only tasks awoken by the previous iteration
are called.
Any time polling completes with no tasks awoken, code will never run again
unless an interrupt handler wakes tasks using Notify
. And so, when we
detect this condition, we use the WFI
instruction to idle the processor
until an interrupt arrives. This has the advantages of using less power and
having more predictable response latency than spinning. If you’d like to
override this behavior, see run_tasks_with_idle
.