From d9fa6378433cb8444ca1095c93b3897fb8b7245b Mon Sep 17 00:00:00 2001 From: erhannis Date: Thu, 24 Oct 2024 21:29:40 -0400 Subject: [PATCH 1/2] Miraculously this seems to work. However, we probably don't want this for all cases. --- Cargo.toml | 1 + src/loom.rs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 426f967..645e480 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ static = [] [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"] } [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..8e15b76 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")] 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 } } From 6c067c7036010bb1f5894430288f823e7bc0137b Mon Sep 17 00:00:00 2001 From: Evans Jahja Date: Fri, 2 May 2025 20:53:27 +0900 Subject: [PATCH 2/2] portable atomic util --- Cargo.toml | 2 ++ src/loom.rs | 2 +- src/mpsc/async_impl.rs | 9 ++++++++- src/recycling.rs | 8 +++++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 645e480..a1d9c92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,11 +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 8e15b76..c1aff4d 100644 --- a/src/loom.rs +++ b/src/loom.rs @@ -207,7 +207,7 @@ mod inner { #[allow(unused_imports)] pub use portable_atomic as atomic; - #[cfg(feature = "alloc")] + #[cfg(all(feature = "alloc", not(feature = "portable_atomic")))] pub use alloc::sync::*; } 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,