Skip to content

Commit

Permalink
if critical-section is enabled, always use it regardless of arch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Dec 23, 2022
1 parent 8ee2cfa commit 0077d2e
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions src/imp/interrupt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,9 @@
// CAS together with atomic load/store. The load/store will not be
// called while interrupts are disabled, and since the load/store is
// atomic, it is not affected by interrupts even if interrupts are enabled.
#[cfg(not(target_arch = "avr"))]
#[cfg(not(feature = "critical-section"))]
#[cfg(not(any(target_arch = "avr", feature = "critical-section")))]
use arch::atomic;

#[cfg(not(target_arch = "avr"))]
#[cfg(feature = "critical-section")]
use core::sync::atomic;

#[cfg(not(feature = "critical-section"))]
#[cfg_attr(
all(
Expand All @@ -55,7 +50,7 @@ use core::sync::atomic;
),
path = "armv4t.rs"
)]
#[cfg_attr(target_arch = "avr", path = "avr.rs")]
#[cfg_attr(any(target_arch = "avr", feature = "critical-section"), path = "avr.rs")]
#[cfg_attr(target_arch = "msp430", path = "msp430.rs")]
#[cfg_attr(any(target_arch = "riscv32", target_arch = "riscv64"), path = "riscv.rs")]
mod arch;
Expand Down Expand Up @@ -142,12 +137,12 @@ impl AtomicBool {
crate::utils::assert_load_ordering(order);
#[deny(unreachable_patterns)]
match () {
#[cfg(not(target_arch = "avr"))]
#[cfg(not(any(target_arch = "avr", feature = "critical-section")))]
// SAFETY: any data races are prevented by atomic intrinsics (see
// module-level comments) and the raw pointer is valid because we got it
// from a reference.
() => unsafe { (*(self as *const Self as *const atomic::AtomicBool)).load(order) },
#[cfg(target_arch = "avr")]
#[cfg(any(target_arch = "avr", feature = "critical-section"))]
// SAFETY: any data races are prevented by disabling interrupts (see
// module-level comments) and the raw pointer is valid because we got it
// from a reference.
Expand All @@ -161,14 +156,14 @@ impl AtomicBool {
crate::utils::assert_store_ordering(order);
#[deny(unreachable_patterns)]
match () {
#[cfg(not(target_arch = "avr"))]
#[cfg(not(any(target_arch = "avr", feature = "critical-section")))]
// SAFETY: any data races are prevented by atomic intrinsics (see
// module-level comments) and the raw pointer is valid because we got it
// from a reference.
() => unsafe {
(*(self as *const Self as *const atomic::AtomicBool)).store(val, order);
},
#[cfg(target_arch = "avr")]
#[cfg(any(target_arch = "avr", feature = "critical-section"))]
// SAFETY: any data races are prevented by disabling interrupts (see
// module-level comments) and the raw pointer is valid because we got it
// from a reference.
Expand Down Expand Up @@ -270,9 +265,9 @@ impl AtomicBool {
}
}

#[cfg(not(target_arch = "msp430"))]
#[cfg(not(all(target_arch = "msp430", not(feature = "critical-section"))))]
no_fetch_ops_impl!(AtomicBool, bool);
#[cfg(target_arch = "msp430")]
#[cfg(all(target_arch = "msp430", not(feature = "critical-section")))]
impl AtomicBool {
#[inline]
pub(crate) fn and(&self, val: bool, order: Ordering) {
Expand Down Expand Up @@ -347,12 +342,12 @@ impl<T> AtomicPtr<T> {
crate::utils::assert_load_ordering(order);
#[deny(unreachable_patterns)]
match () {
#[cfg(not(target_arch = "avr"))]
#[cfg(not(any(target_arch = "avr", feature = "critical-section")))]
// SAFETY: any data races are prevented by atomic intrinsics (see
// module-level comments) and the raw pointer is valid because we got it
// from a reference.
() => unsafe { (*(self as *const Self as *const atomic::AtomicPtr<T>)).load(order) },
#[cfg(target_arch = "avr")]
#[cfg(any(target_arch = "avr", feature = "critical-section"))]
// SAFETY: any data races are prevented by disabling interrupts (see
// module-level comments) and the raw pointer is valid because we got it
// from a reference.
Expand All @@ -366,14 +361,14 @@ impl<T> AtomicPtr<T> {
crate::utils::assert_store_ordering(order);
#[deny(unreachable_patterns)]
match () {
#[cfg(not(target_arch = "avr"))]
#[cfg(not(any(target_arch = "avr", feature = "critical-section")))]
// SAFETY: any data races are prevented by atomic intrinsics (see
// module-level comments) and the raw pointer is valid because we got it
// from a reference.
() => unsafe {
(*(self as *const Self as *const atomic::AtomicPtr<T>)).store(ptr, order);
},
#[cfg(target_arch = "avr")]
#[cfg(any(target_arch = "avr", feature = "critical-section"))]
// SAFETY: any data races are prevented by disabling interrupts (see
// module-level comments) and the raw pointer is valid because we got it
// from a reference.
Expand Down Expand Up @@ -477,14 +472,14 @@ macro_rules! atomic_int {
crate::utils::assert_load_ordering(order);
#[deny(unreachable_patterns)]
match () {
#[cfg(not(target_arch = "avr"))]
#[cfg(not(any(target_arch = "avr", feature = "critical-section")))]
// SAFETY: any data races are prevented by atomic intrinsics (see
// module-level comments) and the raw pointer is valid because we got it
// from a reference.
() => unsafe {
(*(self as *const Self as *const atomic::$atomic_type)).load(order)
},
#[cfg(target_arch = "avr")]
#[cfg(any(target_arch = "avr", feature = "critical-section"))]
// SAFETY: any data races are prevented by disabling interrupts (see
// module-level comments) and the raw pointer is valid because we got it
// from a reference.
Expand All @@ -498,14 +493,14 @@ macro_rules! atomic_int {
crate::utils::assert_store_ordering(order);
#[deny(unreachable_patterns)]
match () {
#[cfg(not(target_arch = "avr"))]
#[cfg(not(any(target_arch = "avr", feature = "critical-section")))]
// SAFETY: any data races are prevented by atomic intrinsics (see
// module-level comments) and the raw pointer is valid because we got it
// from a reference.
() => unsafe {
(*(self as *const Self as *const atomic::$atomic_type)).store(val, order);
},
#[cfg(target_arch = "avr")]
#[cfg(any(target_arch = "avr", feature = "critical-section"))]
// SAFETY: any data races are prevented by disabling interrupts (see
// module-level comments) and the raw pointer is valid because we got it
// from a reference.
Expand All @@ -514,16 +509,16 @@ macro_rules! atomic_int {
}
}

#[cfg(not(target_arch = "msp430"))]
#[cfg(not(all(target_arch = "msp430", not(feature = "critical-section"))))]
no_fetch_ops_impl!($atomic_type, $int_type);
#[cfg(not(target_arch = "msp430"))]
#[cfg(not(all(target_arch = "msp430", not(feature = "critical-section"))))]
impl $atomic_type {
#[inline]
pub(crate) fn not(&self, order: Ordering) {
self.fetch_not(order);
}
}
#[cfg(target_arch = "msp430")]
#[cfg(all(target_arch = "msp430", not(feature = "critical-section")))]
impl $atomic_type {
#[inline]
pub(crate) fn add(&self, val: $int_type, order: Ordering) {
Expand Down

0 comments on commit 0077d2e

Please sign in to comment.