diff options
| author | Dániel Buga <[email protected]> | 2024-12-09 17:11:47 +0100 |
|---|---|---|
| committer | Dániel Buga <[email protected]> | 2024-12-17 16:47:33 +0100 |
| commit | 7eac184af0b6bf88c43158b9a791d7c169d5bb3c (patch) | |
| tree | f6068a11845b379e9f452bac7dbbf6326eb84988 /embassy-executor/src | |
| parent | c504ae8d3a5eb754e0b0920b346dd1a2dc9e2b48 (diff) | |
Document task states and state transitions
Diffstat (limited to 'embassy-executor/src')
| -rw-r--r-- | embassy-executor/src/raw/mod.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index bdd5ff5ae..0ac569946 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs | |||
| @@ -38,6 +38,44 @@ pub use self::waker::task_from_waker; | |||
| 38 | use super::SpawnToken; | 38 | use super::SpawnToken; |
| 39 | 39 | ||
| 40 | /// Raw task header for use in task pointers. | 40 | /// Raw task header for use in task pointers. |
| 41 | /// | ||
| 42 | /// A task can be in one of the following states: | ||
| 43 | /// | ||
| 44 | /// - Not spawned: the task is ready to spawn. | ||
| 45 | /// - `SPAWNED`: the task is currently spawned and may be running. | ||
| 46 | /// - `RUN_ENQUEUED`: the task is enqueued to be polled. Note that the task may be `!SPAWNED`. | ||
| 47 | /// In this case, the `RUN_ENQUEUED` state will be cleared when the task is next polled, without | ||
| 48 | /// polling the task's future. | ||
| 49 | /// | ||
| 50 | /// A task's complete life cycle is as follows: | ||
| 51 | /// | ||
| 52 | /// ```text | ||
| 53 | /// ┌────────────┐ ┌────────────────────────┐ | ||
| 54 | /// ┌─►│Not spawned │◄─6┤Not spawned|Run enqueued│ | ||
| 55 | /// │ │ │ │ │ | ||
| 56 | /// │ └─────┬──────┘ └──────▲─────────────────┘ | ||
| 57 | /// │ 1 │ | ||
| 58 | /// │ │ ┌────────────┘ | ||
| 59 | /// │ │ 5 | ||
| 60 | /// │ ┌─────▼────┴─────────┐ | ||
| 61 | /// │ │Spawned|Run enqueued│ | ||
| 62 | /// │ │ │ | ||
| 63 | /// │ └─────┬▲─────────────┘ | ||
| 64 | /// │ 2│ | ||
| 65 | /// │ │3 | ||
| 66 | /// │ ┌─────▼┴─────┐ | ||
| 67 | /// └─4┤ Spawned │ | ||
| 68 | /// │ │ | ||
| 69 | /// └────────────┘ | ||
| 70 | /// ``` | ||
| 71 | /// | ||
| 72 | /// Transitions: | ||
| 73 | /// - 1: Task is spawned - `AvailableTask::claim -> Executor::spawn` | ||
| 74 | /// - 2: During poll - `RunQueue::dequeue_all -> State::run_dequeue` | ||
| 75 | /// - 3: Task wakes itself, waker wakes task - `Waker::wake -> wake_task -> State::run_enqueue` | ||
| 76 | /// - 4: Task exits - `TaskStorage::poll -> Poll::Ready` | ||
| 77 | /// - 5: A run-queued task exits - `TaskStorage::poll -> Poll::Ready` | ||
| 78 | /// - 6: Task is dequeued and then ignored via `State::run_dequeue` | ||
| 41 | pub(crate) struct TaskHeader { | 79 | pub(crate) struct TaskHeader { |
| 42 | pub(crate) state: State, | 80 | pub(crate) state: State, |
| 43 | pub(crate) run_queue_item: RunQueueItem, | 81 | pub(crate) run_queue_item: RunQueueItem, |
