diff --git a/futures-core/Cargo.toml b/futures-core/Cargo.toml index ca05a6b306..6ad2258cd6 100644 --- a/futures-core/Cargo.toml +++ b/futures-core/Cargo.toml @@ -16,6 +16,7 @@ std = ["alloc"] alloc = [] [dependencies] +portable-atomic = { version = "0.3.15", default-features = false, optional = true } [dev-dependencies] futures = { path = "../futures" } diff --git a/futures-core/src/task/__internal/atomic_waker.rs b/futures-core/src/task/__internal/atomic_waker.rs index d49d043619..0677e83b09 100644 --- a/futures-core/src/task/__internal/atomic_waker.rs +++ b/futures-core/src/task/__internal/atomic_waker.rs @@ -1,9 +1,16 @@ use core::cell::UnsafeCell; use core::fmt; -use core::sync::atomic::AtomicUsize; -use core::sync::atomic::Ordering::{AcqRel, Acquire, Release}; use core::task::Waker; +use atomic::AtomicUsize; +use atomic::Ordering::{AcqRel, Acquire, Release}; + +#[cfg(feature = "portable-atomic")] +use portable_atomic as atomic; + +#[cfg(not(feature = "portable-atomic"))] +use core::sync::atomic; + /// A synchronization primitive for task wakeup. /// /// Sometimes the task interested in a given event will change over time. diff --git a/futures-util/Cargo.toml b/futures-util/Cargo.toml index b8db23243d..1858bf62a8 100644 --- a/futures-util/Cargo.toml +++ b/futures-util/Cargo.toml @@ -21,6 +21,7 @@ io-compat = ["io", "compat", "tokio-io"] sink = ["futures-sink"] io = ["std", "futures-io", "memchr"] channel = ["std", "futures-channel"] +portable-atomic = ["futures-core/portable-atomic"] # Unstable features # These features are outside of the normal semver guarantees and require the