Skip to content

Commit

Permalink
Use AtomicBool from core if not using portable-atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
9names committed Jul 28, 2024
1 parent cc868a3 commit b556544
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions embedded-hal-bus/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
#[allow(unused_imports)]
use core::cell::UnsafeCell;

#[cfg(feature = "portable-atomic")]
use portable_atomic::AtomicBool;
#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic::AtomicBool;

#[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))]
/// Cell type used by [`spi::AtomicDevice`](crate::spi::AtomicDevice) and [`i2c::AtomicDevice`](crate::i2c::AtomicDevice).
///
/// To use `AtomicDevice`, you must wrap the bus with this struct, and then
/// construct multiple `AtomicDevice` instances with references to it.
pub struct AtomicCell<BUS> {
pub(crate) bus: UnsafeCell<BUS>,
pub(crate) busy: portable_atomic::AtomicBool,
pub(crate) busy: AtomicBool,
}
#[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))]
unsafe impl<BUS: Send> Send for AtomicCell<BUS> {}
Expand All @@ -23,7 +28,7 @@ impl<BUS> AtomicCell<BUS> {
pub fn new(bus: BUS) -> Self {
Self {
bus: UnsafeCell::new(bus),
busy: portable_atomic::AtomicBool::from(false),
busy: AtomicBool::from(false),
}
}
}

0 comments on commit b556544

Please sign in to comment.