Commit 8209f16
authored
Support CPU-local variables with user-defined types (#1024)
* The `cpu_local` macro now generates four functions for user-defined types:
```rust
pub fn replace(&self, value: #ty) -> #ty;
pub fn replace_guarded<G>(&self, mut value: #ty, guard: &G) -> #ty
where
G: CpuAtomicGuard
pub fn set(&self, value: #ty);
pub fn set_guarded<G>(&self, mut value: #ty, guard: &G)
where
G: CpuAtomicGuard
```
* The new `CpuAtomicGuard` trait is sealed, but implemented for
`preemption::PreemptionGuard` and `irq_safety::HeldInterrupts`.
Passing a reference to one of those guard types into either `set_guarded()`
or `replace_guarded()` can efficiently ensure that either preemption or
interrupts are disabled, meaning that the CPU-local variable can be
safely accessed in an atomic manner across multiple assembly instructions.
* However, this doesn't cover all use cases, so we also add two optional
arguments to the `cpu_local` macro:
1. `cls_dep`: a boolean that defaults to true, but can be set to false to
prevent the macro from generating functions that depend on `cls`.
This is only used by the `preemption` crate to avoid a circular dependency.
2. `stores_guard`: accepts a type denoting that the CLS variable stores an
`Option<impl cls::CpuAtomicGuard>`, such as the task switch preemption
guard. This argument modifies the signatures of `replace` and `set` to accept
the guard type by value, because the guard type obviates the need to pass in
a reference to another redundant guard (normally used to ensure atomicity).
Signed-off-by: Klimenty Tsoutsman <[email protected]>1 parent 8a1e561 commit 8209f16
File tree
12 files changed
+391
-207
lines changed- kernel
- cls
- cls_macros/src
- src
- cpu_local/src
- per_cpu
- src
- preemption
- src
- task
- src
12 files changed
+391
-207
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
0 commit comments