|
| 1 | +//! Higher level synchronization primitives. |
| 2 | +//! |
| 3 | +//! These are modeled after the synchronization primitives in |
| 4 | +//! [`std::sync`](https://doc.rust-lang.org/stable/std/sync/index.html) and those from |
| 5 | +//! [`crossbeam-channel`](https://docs.rs/crossbeam-channel/latest/crossbeam_channel/), in as much |
| 6 | +//! as it makes sense. |
| 7 | +
|
| 8 | +pub mod atomic { |
| 9 | + //! Re-export portable atomic. |
| 10 | + //! |
| 11 | + //! Although `core` contains a |
| 12 | + //! [`sync::atomic`](https://doc.rust-lang.org/stable/core/sync/atomic/index.html) module, |
| 13 | + //! these are dependent on the target having atomic instructions, and the types are missing |
| 14 | + //! when the platform cannot support them. Zephyr, however, does provide atomics on platforms |
| 15 | + //! that don't support atomic instructions, using spinlocks. In the Rust-embedded world, this |
| 16 | + //! is done through the [`portable-atomic`](https://crates.io/crates/portable-atomic) crate, |
| 17 | + //! which will either just re-export the types from core, or provide an implementation using |
| 18 | + //! spinlocks when those aren't available. |
| 19 | +
|
| 20 | + pub use portable_atomic::*; |
| 21 | +} |
| 22 | + |
| 23 | +/// Re-export Arc from the portable-atomic library. |
| 24 | +/// |
| 25 | +/// Note that the `Arc` from portable-atomic is missing a few features from the one from `alloc`, |
| 26 | +/// notably the ability to upcast Arcs. This can be worked around by putting the object in a |
| 27 | +/// `Box`, with the downcasting, and then using `Arc::from` to move the object from the box into |
| 28 | +/// the Arc. |
| 29 | +#[cfg(CONFIG_RUST_ALLOC)] |
| 30 | +pub use portable_atomic_util::Arc; |
0 commit comments