aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
authorDániel Buga <[email protected]>2023-08-12 22:20:11 +0200
committerDániel Buga <[email protected]>2023-08-12 22:20:11 +0200
commitd5e66f6f87222de65ac575c4b923b2fee5487388 (patch)
treeea80dc599969eab5d6038e09c0c479269a1e0eb2 /embassy-executor/src
parentbce250bbdc18f025547f59c30a7bec24826b3aea (diff)
Lift thread-context feature restrictions
Diffstat (limited to 'embassy-executor/src')
-rw-r--r--embassy-executor/src/arch/riscv32.rs10
-rw-r--r--embassy-executor/src/arch/xtensa.rs19
2 files changed, 17 insertions, 12 deletions
diff --git a/embassy-executor/src/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs
index becc0245a..c4e772e34 100644
--- a/embassy-executor/src/arch/riscv32.rs
+++ b/embassy-executor/src/arch/riscv32.rs
@@ -1,9 +1,6 @@
1#[cfg(feature = "executor-interrupt")] 1#[cfg(feature = "executor-interrupt")]
2compile_error!("`executor-interrupt` is not supported with `arch-riscv32`."); 2compile_error!("`executor-interrupt` is not supported with `arch-riscv32`.");
3 3
4#[cfg(feature = "thread-context")]
5compile_error!("`thread-context` is not supported with `arch-riscv32`.");
6
7#[cfg(feature = "executor-thread")] 4#[cfg(feature = "executor-thread")]
8pub use thread::*; 5pub use thread::*;
9#[cfg(feature = "executor-thread")] 6#[cfg(feature = "executor-thread")]
@@ -30,6 +27,13 @@ mod thread {
30 pub struct RiscVThreadContext; 27 pub struct RiscVThreadContext;
31 28
32 impl ThreadContext for RiscVThreadContext { 29 impl ThreadContext for RiscVThreadContext {
30 #[cfg(feature = "thread-context")]
31 fn context(&self) -> OpaqueThreadContext {
32 // Enabling thread-context is not incorrect, just wasteful.
33 OpaqueThreadContext(0)
34 }
35
36 #[cfg(not(feature = "thread-context"))]
33 fn context(&self) -> OpaqueThreadContext { 37 fn context(&self) -> OpaqueThreadContext {
34 OpaqueThreadContext(()) 38 OpaqueThreadContext(())
35 } 39 }
diff --git a/embassy-executor/src/arch/xtensa.rs b/embassy-executor/src/arch/xtensa.rs
index 6357bfef2..1097bff83 100644
--- a/embassy-executor/src/arch/xtensa.rs
+++ b/embassy-executor/src/arch/xtensa.rs
@@ -1,12 +1,6 @@
1#[cfg(feature = "executor-interrupt")] 1#[cfg(feature = "executor-interrupt")]
2compile_error!("`executor-interrupt` is not supported with `arch-xtensa`."); 2compile_error!("`executor-interrupt` is not supported with `arch-xtensa`.");
3 3
4#[cfg(feature = "thread-context")]
5compile_error!(
6 "`thread-context` is not supported with `arch-xtensa`.\
7 Use a multicore-safe executor from esp-hal instead." // obviously, this is too specific to ESP32
8);
9
10#[cfg(feature = "executor-thread")] 4#[cfg(feature = "executor-thread")]
11pub use thread::*; 5pub use thread::*;
12#[cfg(feature = "executor-thread")] 6#[cfg(feature = "executor-thread")]
@@ -17,7 +11,7 @@ mod thread {
17 use crate::raw::OpaqueThreadContext; 11 use crate::raw::OpaqueThreadContext;
18 use crate::thread::ThreadContext; 12 use crate::thread::ThreadContext;
19 13
20 /// global atomic used to keep track of whether there is work to do since sev() is not available on RISCV 14 /// global atomic used to keep track of whether there is work to do since sev() is not available on Xtensa
21 static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false); 15 static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false);
22 16
23 #[export_name = "__thread_mode_pender"] 17 #[export_name = "__thread_mode_pender"]
@@ -31,6 +25,13 @@ mod thread {
31 pub struct XtensaThreadContext; 25 pub struct XtensaThreadContext;
32 26
33 impl ThreadContext for XtensaThreadContext { 27 impl ThreadContext for XtensaThreadContext {
28 #[cfg(feature = "thread-context")]
29 fn context(&self) -> OpaqueThreadContext {
30 // Enabling thread-context is not incorrect, just wasteful.
31 OpaqueThreadContext(0)
32 }
33
34 #[cfg(not(feature = "thread-context"))]
34 fn context(&self) -> OpaqueThreadContext { 35 fn context(&self) -> OpaqueThreadContext {
35 OpaqueThreadContext(()) 36 OpaqueThreadContext(())
36 } 37 }
@@ -43,8 +44,8 @@ mod thread {
43 let token: critical_section::RawRestoreState; 44 let token: critical_section::RawRestoreState;
44 core::arch::asm!("rsil {0}, 5", out(reg) token); 45 core::arch::asm!("rsil {0}, 5", out(reg) token);
45 46
46 // we do not care about race conditions between the load and store operations, interrupts 47 // we do not care about race conditions between the load and store operations,
47 // will only set this value to true. 48 // interrupts will only set this value to true.
48 // if there is work to do, loop back to polling 49 // if there is work to do, loop back to polling
49 if SIGNAL_WORK_THREAD_MODE.load(Ordering::SeqCst) { 50 if SIGNAL_WORK_THREAD_MODE.load(Ordering::SeqCst) {
50 SIGNAL_WORK_THREAD_MODE.store(false, Ordering::SeqCst); 51 SIGNAL_WORK_THREAD_MODE.store(false, Ordering::SeqCst);