-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zephyr: Make symbols from portable-atomic available
Provide the atomic types from portable-atomic in `zephyr::sync::atomic`, and, if allocation is enabled, provide `zephyr::sync::Arc`. The `alloc::arc` will only be available on Zephyr targets that have atomic intrinsics, and the portable one can be supported on any Zephyr target. There are some limitations described in the documentation. Signed-off-by: David Brown <[email protected]>
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,7 @@ | |
#![no_std] | ||
#![allow(unexpected_cfgs)] | ||
|
||
pub mod sync; | ||
pub mod sys; | ||
pub mod time; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//! Higher level synchronization primitives. | ||
//! | ||
//! These are modeled after the synchronization primitives in | ||
//! [`std::sync`](https://doc.rust-lang.org/stable/std/sync/index.html) and those from | ||
//! [`crossbeam-channel`](https://docs.rs/crossbeam-channel/latest/crossbeam_channel/), in as much | ||
//! as it makes sense. | ||
pub mod atomic { | ||
//! Re-export portable atomic. | ||
//! | ||
//! Although `core` contains a | ||
//! [`sync::atomic`](https://doc.rust-lang.org/stable/core/sync/atomic/index.html) module, | ||
//! these are dependent on the target having atomic instructions, and the types are missing | ||
//! when the platform cannot support them. Zephyr, however, does provide atomics on platforms | ||
//! that don't support atomic instructions, using spinlocks. In the Rust-embedded world, this | ||
//! is done through the [`portable-atomic`](https://crates.io/crates/portable-atomic) crate, | ||
//! which will either just re-export the types from core, or provide an implementation using | ||
//! spinlocks when those aren't available. | ||
pub use portable_atomic::*; | ||
} | ||
|
||
/// Re-export Arc from the portable-atomic library. | ||
/// | ||
/// Note that the `Arc` from portable-atomic is missing a few features from the one from `alloc`, | ||
/// notably the ability to upcast Arcs. This can be worked around by putting the object in a | ||
/// `Box`, with the downcasting, and then using `Arc::from` to move the object from the box into | ||
/// the Arc. | ||
#[cfg(CONFIG_RUST_ALLOC)] | ||
pub use portable_atomic_util::Arc; |