Skip to content

Commit 15ceea0

Browse files
committed
doc(task): add a task state diagram
1 parent 1af34cd commit 15ceea0

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/constance/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ num-integer = "0.1.42"
1313
num-traits = "0.2.11"
1414
bitflags = "1.2.1"
1515
parse-generics-shim = { version = "0.1.1" }
16+
svgbobdoc = "0.2.2"
1617

1718
[dev-dependencies]
1819
quickcheck = "0.9.2"

src/constance/src/kernel/task.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::utils::{
1212
Init, PrioBitmap,
1313
};
1414

15+
#[cfg_attr(doc, svgbobdoc::transform)]
1516
/// Represents a single task in a system.
1617
///
1718
/// This type is ABI-compatible with [`Id`].
@@ -25,15 +26,43 @@ use crate::utils::{
2526
///
2627
/// A task may be in one of the following states:
2728
///
28-
/// - **Dormant**
29-
/// - **Ready**
30-
/// - **Running**
31-
/// - **Waiting**
29+
/// - **Dormant** — The task is not executing, doesn't have an associated
30+
/// execution [thread], and can be [activated].
3231
///
33-
#[doc(include = "../common.md")]
32+
/// - **Ready** — The task has an associated execution thread, which is ready to
33+
/// be scheduled to the CPU
34+
///
35+
/// - **Running** — The task has an associated execution thread, which is
36+
/// currently scheduled to the CPU
37+
///
38+
/// - **Waiting** — The task has an associated execution thread, which is
39+
/// currently blocked by a blocking operation
40+
///
41+
/// ```svgbob
42+
/// ,-------,
43+
/// ,--------------->| Ready |<--------------,
44+
/// | '-------' |
45+
/// | dispatch | ^ |
46+
/// | | | |
47+
/// | release | | | activate
48+
/// ,---------, | | ,---------,
49+
/// | Waiting | | | | Dormant |
50+
/// '---------' | | '---------'
51+
/// ^ | | ^
52+
/// | | | |
53+
/// | v | preempt |
54+
/// | wait ,---------, |
55+
/// '---------------| Running |--------------'
56+
/// '---------' exit
57+
/// ```
58+
///
59+
/// [thread]: crate#threads
60+
/// [activated]: Task::activate
3461
#[repr(transparent)]
3562
pub struct Task<System>(Id, PhantomData<System>);
3663

64+
// FIXME: `svgbobdoc` doesn't like `#[doc(include = ...)]`
65+
#[doc(include = "../common.md")]
3766
impl<System> Clone for Task<System> {
3867
fn clone(&self) -> Self {
3968
Self(self.0, self.1)

0 commit comments

Comments
 (0)