Commit f11909f
committed
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]> 8209f161 parent 50bfe6b commit f11909f
File tree
63 files changed
+684
-366
lines changed- doc
- app_io
- cls_macros
- cls
- cpu_local
- implementors
- cls
- core2/io/traits
- core
- clone
- cmp
- default
- fmt
- hash
- marker
- ops
- deref
- drop
- panic/unwind_safe
- cpu_local
- fs_node
- io
- per_cpu
- src
- cls_macros
- cls
- cpu_local
- per_cpu
- preemption
- task
- task
- cpu_local_task_switch
- tty
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
63 files changed
+684
-366
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
0 commit comments