diff --git a/Cargo.toml b/Cargo.toml index 426f967..a1d9c92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,10 +25,13 @@ std = ["alloc", "parking_lot"] alloc = [] default = ["std"] static = [] +portable_atomic = [] [dependencies] pin-project = "1" parking_lot = { version = "0.12", optional = true, default-features = false } +portable-atomic = { version = "1.9.0", default-features = false, features = ["require-cas", "critical-section"] } +portable-atomic-util = { version = "0.2.4", default-features = false, features = ["alloc"] } [dev-dependencies] tokio = { version = "1.14.0", features = ["rt", "rt-multi-thread", "macros", "sync"] } diff --git a/src/loom.rs b/src/loom.rs index 4c0d147..c1aff4d 100644 --- a/src/loom.rs +++ b/src/loom.rs @@ -205,13 +205,13 @@ mod inner { #![allow(dead_code)] pub(crate) mod sync { #[allow(unused_imports)] - pub use core::sync::*; + pub use portable_atomic as atomic; - #[cfg(feature = "alloc")] + #[cfg(all(feature = "alloc", not(feature = "portable_atomic")))] pub use alloc::sync::*; } - pub(crate) use core::sync::atomic; + pub(crate) use portable_atomic as atomic; #[cfg(feature = "std")] pub use std::thread; @@ -221,7 +221,7 @@ mod inner { pub(crate) fn spin_loop() { // MSRV: std::hint::spin_loop() stabilized in 1.49.0 #[allow(deprecated)] - super::atomic::spin_loop_hint() + core::sync::atomic::spin_loop_hint(); // Apparently portable_atomic doesn't have spin_loop_hint } } diff --git a/src/mpsc/async_impl.rs b/src/mpsc/async_impl.rs index 9f410d2..6747d78 100644 --- a/src/mpsc/async_impl.rs +++ b/src/mpsc/async_impl.rs @@ -14,7 +14,14 @@ use errors::*; feature! { #![feature = "alloc"] - use crate::{MAX_CAPACITY, loom::sync::Arc}; + use crate::{MAX_CAPACITY}; + + #[cfg(not(feature = "portable_atomic"))] + use crate::loom::sync::Arc; + + #[cfg(feature = "portable_atomic")] + use portable_atomic_util::Arc; + use alloc::boxed::Box; /// Returns a new asynchronous multi-producer, single consumer (MPSC) diff --git a/src/recycling.rs b/src/recycling.rs index d118ab0..fd01b53 100644 --- a/src/recycling.rs +++ b/src/recycling.rs @@ -390,10 +390,16 @@ feature! { use alloc::{ collections::{VecDeque, BinaryHeap}, string::String, - sync::Arc, vec::Vec, }; + #[cfg(all(feature = "alloc", not(feature = "portable_atomic")))] + use alloc::sync::Arc; + + #[cfg(all(feature = "alloc", feature = "portable_atomic"))] + use portable_atomic_util::Arc; + + impl Recycle for Arc where R: Recycle,