std :: sync::task
Struct std::TaskScheduler
Fields
number of registered tasks
index of currently running task
Methods
An empty scheduler (no tasks).
Spawn a task running func(arg, resume_point):
- func returns >0 to yield, with that value as the next resume_point
- func returns 0 when done
Returns the task index, or -1 if the scheduler is full. static int blink(?&Led led, int step) { ...; return step < 3 ? step + 1 : 0; } sched.spawn(blink, (?&Led)&led);
Run one scheduling round: every non-blocked, non-done task gets one turn (blocked tasks are skipped without being invoked — see await_fd). Returns the count of still-active (blocked or ready, i.e. not yet TASK_DONE) tasks.
Run all tasks in round-robin until all are TASK_DONE. Note: a task that calls await_fd() and is never unblocked (no reactor driving this scheduler) will spin run_all() forever — use std::reactor_run() instead whenever any task may block on I/O.
Return number of active (non-DONE) tasks.
Marks the currently running task (self.current) as blocked until 'fd' becomes ready for 'filter'. Must be called from within a task function's own body during its turn (i.e. before that turn's 'return'), not from outside the scheduler.
Unblocks every task waiting on the given (fd, filter) pair. Returns how many tasks were unblocked. Called by std::Reactor::poll when the OS reports readiness — not normally called directly.
True if at least one non-done task is currently blocked.
True if at least one non-done task is immediately runnable (not blocked). Together with has_blocked(), this is what reactor_run() uses to decide whether to poll with a zero or infinite timeout.