differentiate full vs CAS polyfill

This commit is contained in:
Tyler Holmes 2022-01-16 11:51:23 -08:00
parent a68ce63fbe
commit bc9e208089
5 changed files with 27 additions and 22 deletions

View File

@ -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[..] { match &target[..] {
"thumbv6m-none-eabi" | "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => { "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {
println!("cargo:rustc-cfg=use_atomic_polyfill"); println!("cargo:rustc-cfg=full_atomic_polyfill");
println!("cargo:rustc-cfg=cas_atomic_polyfill");
}
"thumbv6m-none-eabi" => {
println!("cargo:rustc-cfg=cas_atomic_polyfill");
} }
_ => {} _ => {}
} }

View File

@ -87,18 +87,18 @@
use core::{cell::UnsafeCell, mem::MaybeUninit}; 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; 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; 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; 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; type AtomicTargetSize = atomic_polyfill::AtomicU8;
#[cfg(not(use_atomic_polyfill))] #[cfg(not(cas_atomic_polyfill))]
type Ordering = core::sync::atomic::Ordering; type Ordering = core::sync::atomic::Ordering;
#[cfg(use_atomic_polyfill)] #[cfg(cas_atomic_polyfill)]
type Ordering = atomic_polyfill::Ordering; type Ordering = atomic_polyfill::Ordering;
#[cfg(feature = "mpmc_large")] #[cfg(feature = "mpmc_large")]

View File

@ -3,10 +3,10 @@
pub use core::ptr::NonNull as Ptr; pub use core::ptr::NonNull as Ptr;
use core::{cell::UnsafeCell, ptr}; use core::{cell::UnsafeCell, ptr};
#[cfg(use_atomic_polyfill)] #[cfg(cas_atomic_polyfill)]
use atomic_polyfill::{AtomicPtr, Ordering}; use atomic_polyfill::{AtomicPtr, Ordering};
#[cfg(not(use_atomic_polyfill))] #[cfg(not(cas_atomic_polyfill))]
use core::sync::atomic::{AtomicPtr, Ordering}; use core::sync::atomic::{AtomicPtr, Ordering};
/// Unfortunate implementation detail required to use the /// Unfortunate implementation detail required to use the

View File

@ -81,10 +81,10 @@ use core::{
sync::atomic, sync::atomic,
}; };
#[cfg(use_atomic_polyfill)] #[cfg(cas_atomic_polyfill)]
use atomic_polyfill::{AtomicUsize, Ordering}; use atomic_polyfill::{AtomicUsize, Ordering};
#[cfg(not(use_atomic_polyfill))] #[cfg(not(cas_atomic_polyfill))]
use core::sync::atomic::{AtomicUsize, Ordering}; use core::sync::atomic::{AtomicUsize, Ordering};
use crate::pool::{self, stack::Ptr, Node}; use crate::pool::{self, stack::Ptr, Node};

View File

@ -2,8 +2,8 @@
//! //!
//! Implementation based on <https://www.codeproject.com/Articles/43510/Lock-Free-Single-Producer-Single-Consumer-Circular> //! 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 //! NOTE: This module is not available on targets that do *not* support atomic loads and are not
//! cores w/o the A (Atomic) extension //! supported by [`atomic_polyfill`]. (e.g., MSP430).
//! //!
//! # Examples //! # Examples
//! //!
@ -84,13 +84,12 @@
//! - The numbers reported correspond to the successful path (i.e. `Some` is returned by `dequeue` //! - The numbers reported correspond to the successful path (i.e. `Some` is returned by `dequeue`
//! and `Ok` is returned by `enqueue`). //! and `Ok` is returned by `enqueue`).
use core::{ use core::{cell::UnsafeCell, fmt, hash, mem::MaybeUninit, ptr};
cell::UnsafeCell,
fmt, hash, #[cfg(full_atomic_polyfill)]
mem::MaybeUninit, use atomic_polyfill::{AtomicUsize, Ordering};
ptr, #[cfg(not(full_atomic_polyfill))]
sync::atomic::{AtomicUsize, Ordering}, use core::sync::atomic::{AtomicUsize, Ordering};
};
/// A statically allocated single producer single consumer queue with a capacity of `N - 1` elements /// A statically allocated single producer single consumer queue with a capacity of `N - 1` elements
/// ///