diff options
author | 2022-01-16 11:51:23 -0800 | |
---|---|---|
committer | 2022-01-17 11:32:13 -0800 | |
commit | bc9e208089a415f0400f88ba4a8bfd20d955e317 (patch) | |
tree | 115527275db30a7f385347b933bb2b1eeef22b78 | |
parent | a68ce63fbed4e3f2da76687a8ed0b064167448b9 (diff) | |
download | heapless-bc9e208089a415f0400f88ba4a8bfd20d955e317.tar.gz heapless-bc9e208089a415f0400f88ba4a8bfd20d955e317.tar.zst heapless-bc9e208089a415f0400f88ba4a8bfd20d955e317.zip |
differentiate full vs CAS polyfill
Diffstat (limited to '')
-rw-r--r-- | build.rs | 12 | ||||
-rw-r--r-- | src/mpmc.rs | 12 | ||||
-rw-r--r-- | src/pool/llsc.rs | 4 | ||||
-rw-r--r-- | src/pool/singleton/arc.rs | 4 | ||||
-rw-r--r-- | src/spsc.rs | 17 |
5 files changed, 27 insertions, 22 deletions
@@ -52,10 +52,16 @@ fn main() -> Result<(), Box<dyn Error>> { } }; - // Let the code know if it should use atomic-polyfill or not + // Let the code know if it should use atomic-polyfill or not, and what aspects + // of polyfill it requires match &target[..] { - "thumbv6m-none-eabi" | "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => { - println!("cargo:rustc-cfg=use_atomic_polyfill"); + "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => { + println!("cargo:rustc-cfg=full_atomic_polyfill"); + println!("cargo:rustc-cfg=cas_atomic_polyfill"); + } + + "thumbv6m-none-eabi" => { + println!("cargo:rustc-cfg=cas_atomic_polyfill"); } _ => {} } diff --git a/src/mpmc.rs b/src/mpmc.rs index a5c327f5..91b33311 100644 --- a/src/mpmc.rs +++ b/src/mpmc.rs @@ -87,18 +87,18 @@ use core::{cell::UnsafeCell, mem::MaybeUninit}; -#[cfg(all(feature = "mpmc_large", not(use_atomic_polyfill)))] +#[cfg(all(feature = "mpmc_large", not(cas_atomic_polyfill)))] type AtomicTargetSize = core::sync::atomic::AtomicUsize; -#[cfg(all(feature = "mpmc_large", use_atomic_polyfill))] +#[cfg(all(feature = "mpmc_large", cas_atomic_polyfill))] type AtomicTargetSize = atomic_polyfill::AtomicUsize; -#[cfg(all(not(feature = "mpmc_large"), not(use_atomic_polyfill)))] +#[cfg(all(not(feature = "mpmc_large"), not(cas_atomic_polyfill)))] type AtomicTargetSize = core::sync::atomic::AtomicU8; -#[cfg(all(not(feature = "mpmc_large"), use_atomic_polyfill))] +#[cfg(all(not(feature = "mpmc_large"), cas_atomic_polyfill))] type AtomicTargetSize = atomic_polyfill::AtomicU8; -#[cfg(not(use_atomic_polyfill))] +#[cfg(not(cas_atomic_polyfill))] type Ordering = core::sync::atomic::Ordering; -#[cfg(use_atomic_polyfill)] +#[cfg(cas_atomic_polyfill)] type Ordering = atomic_polyfill::Ordering; #[cfg(feature = "mpmc_large")] diff --git a/src/pool/llsc.rs b/src/pool/llsc.rs index 823a8a7c..33f65557 100644 --- a/src/pool/llsc.rs +++ b/src/pool/llsc.rs @@ -3,10 +3,10 @@ pub use core::ptr::NonNull as Ptr; use core::{cell::UnsafeCell, ptr}; -#[cfg(use_atomic_polyfill)] +#[cfg(cas_atomic_polyfill)] use atomic_polyfill::{AtomicPtr, Ordering}; -#[cfg(not(use_atomic_polyfill))] +#[cfg(not(cas_atomic_polyfill))] use core::sync::atomic::{AtomicPtr, Ordering}; /// Unfortunate implementation detail required to use the diff --git a/src/pool/singleton/arc.rs b/src/pool/singleton/arc.rs index b64b0f7b..a83519d8 100644 --- a/src/pool/singleton/arc.rs +++ b/src/pool/singleton/arc.rs @@ -81,10 +81,10 @@ use core::{ sync::atomic, }; -#[cfg(use_atomic_polyfill)] +#[cfg(cas_atomic_polyfill)] use atomic_polyfill::{AtomicUsize, Ordering}; -#[cfg(not(use_atomic_polyfill))] +#[cfg(not(cas_atomic_polyfill))] use core::sync::atomic::{AtomicUsize, Ordering}; use crate::pool::{self, stack::Ptr, Node}; diff --git a/src/spsc.rs b/src/spsc.rs index 2c0a6b44..38990d56 100644 --- a/src/spsc.rs +++ b/src/spsc.rs @@ -2,8 +2,8 @@ //! //! Implementation based on <https://www.codeproject.com/Articles/43510/Lock-Free-Single-Producer-Single-Consumer-Circular> //! -//! NOTE: This module is not available on targets that do *not* support atomic loads, e.g. RISC-V -//! cores w/o the A (Atomic) extension +//! NOTE: This module is not available on targets that do *not* support atomic loads and are not +//! supported by [`atomic_polyfill`]. (e.g., MSP430). //! //! # Examples //! @@ -84,13 +84,12 @@ //! - The numbers reported correspond to the successful path (i.e. `Some` is returned by `dequeue` //! and `Ok` is returned by `enqueue`). -use core::{ - cell::UnsafeCell, - fmt, hash, - mem::MaybeUninit, - ptr, - sync::atomic::{AtomicUsize, Ordering}, -}; +use core::{cell::UnsafeCell, fmt, hash, mem::MaybeUninit, ptr}; + +#[cfg(full_atomic_polyfill)] +use atomic_polyfill::{AtomicUsize, Ordering}; +#[cfg(not(full_atomic_polyfill))] +use core::sync::atomic::{AtomicUsize, Ordering}; /// A statically allocated single producer single consumer queue with a capacity of `N - 1` elements /// |