mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-09-26 20:10:24 +00:00
differentiate full vs CAS polyfill
This commit is contained in:
parent
a68ce63fbe
commit
bc9e208089
12
build.rs
12
build.rs
@ -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");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
12
src/mpmc.rs
12
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")]
|
||||
|
@ -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
|
||||
|
@ -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};
|
||||
|
17
src/spsc.rs
17
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
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user