Skip to content

Commit

Permalink
os: switch from "secret features" to non-feature cfgs
Browse files Browse the repository at this point in the history
This moves basepri and native atomics detection to cfgs (namespaced by
lilos_) instead of fake features. This seems less confusing, since
normally if you see cfg(feature = "foo") in the source, you can expect
to also find a definition of that feature in Cargo.toml... which was not
the case here.
  • Loading branch information
cbiffle committed May 5, 2024
1 parent 3b31f5c commit 09c8ba6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
8 changes: 5 additions & 3 deletions os/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

fn main() {
println!(r#"cargo:rustc-check-cfg=cfg(feature, values("has-basepri", "has-native-rmw"))"#);
println!(r#"cargo:rustc-check-cfg=cfg(lilos-has-basepri)"#);
println!(r#"cargo:rustc-check-cfg=cfg(lilos-has-native-rmw)"#);

match std::env::var("TARGET").unwrap().as_str() {
"thumbv7m-none-eabi" | "thumbv7em-none-eabi" | "thumbv7em-none-eabihf" => {
// Turn on BASEPRI support for interrupt priority filtering.
println!("cargo:rustc-cfg=feature=\"has-basepri\"");
println!("cargo:rustc-cfg=lilos_has_basepri");
// Use native atomic RMW operations
println!("cargo:rustc-cfg=feature=\"has-native-rmw\"");
println!("cargo:rustc-cfg=lilos_has_native_rmw");
}
"thumbv6m-none-eabi" => {
// Don't turn anything on.
Expand Down
10 changes: 5 additions & 5 deletions os/src/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ macro_rules! impl_atomic_polyfills {
impl<$($param)?> private::Sealed for $t {}

// Native version
#[cfg(feature = "has-native-rmw")]
#[cfg(lilos_has_native_rmw)]
impl<$($param)?> AtomicExt for $t {
type Value = $v;

Expand Down Expand Up @@ -113,7 +113,7 @@ macro_rules! impl_atomic_polyfills {
}

// Non-native version
#[cfg(not(feature = "has-native-rmw"))]
#[cfg(not(lilos_has_native_rmw))]
impl<$($param)?> AtomicExt for $t {
type Value = $v;

Expand Down Expand Up @@ -186,7 +186,7 @@ impl_atomic_polyfills!(AtomicPtr<T>, *mut T, T);
macro_rules! impl_atomic_arith_polyfills {
($t:ty $(, $param:ident)?) => {
// Native version
#[cfg(feature = "has-native-rmw")]
#[cfg(lilos_has_native_rmw)]
impl<$($param)?> AtomicArithExt for $t {
fn fetch_add_polyfill(
&self,
Expand Down Expand Up @@ -214,7 +214,7 @@ macro_rules! impl_atomic_arith_polyfills {
}

// Non-native version
#[cfg(not(feature = "has-native-rmw"))]
#[cfg(not(lilos_has_native_rmw))]
impl<$($param)?> AtomicArithExt for $t {
fn fetch_add_polyfill(
&self,
Expand Down Expand Up @@ -262,7 +262,7 @@ impl_atomic_arith_polyfills!(core::sync::atomic::AtomicIsize);
impl_atomic_arith_polyfills!(AtomicUsize);
impl_atomic_arith_polyfills!(AtomicU32);

#[cfg(not(feature = "has-native-rmw"))]
#[cfg(not(lilos_has_native_rmw))]
#[inline(always)]
fn rmw_ordering(o: Ordering) -> (Ordering, Ordering) {
match o {
Expand Down
4 changes: 2 additions & 2 deletions os/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ pub enum Interrupts {
/// adjust this priority in the NVIC.)
///
/// This is not available on ARMv6-M, which lacks the `BASEPRI` feature.
#[cfg(feature = "has-basepri")]
#[cfg(lilos_has_basepri)]
Filtered(u8),
}

Expand All @@ -332,7 +332,7 @@ impl Interrupts {

r
}
#[cfg(feature = "has-basepri")]
#[cfg(lilos_has_basepri)]
Interrupts::Filtered(priority) => {
let prev = cortex_m::register::basepri::read();
cortex_m::register::basepri_max::write(priority);
Expand Down

0 comments on commit 09c8ba6

Please sign in to comment.