From bf092b3d9e1765d9bb31225d33d51451711afa7c Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Sat, 10 Nov 2018 01:20:03 +0000 Subject: [PATCH] Move AtomicWaker to futures-core ... so `AtomicWaker` could be used inside `futures-channel`. `AtomicWaker` is still accessible to users only from `futures-util`. --- futures-core/Cargo.toml | 6 ++++++ futures-core/src/lib.rs | 1 + .../src/task/__internal}/atomic_waker.rs | 7 ++++--- futures-core/src/task/__internal/mod.rs | 10 ++++++++++ futures-core/src/task/mod.rs | 2 ++ futures-util/src/task/mod.rs | 7 +------ futures/Cargo.toml | 2 +- 7 files changed, 25 insertions(+), 10 deletions(-) rename {futures-util/src/task => futures-core/src/task/__internal}/atomic_waker.rs (98%) create mode 100644 futures-core/src/task/__internal/mod.rs diff --git a/futures-core/Cargo.toml b/futures-core/Cargo.toml index 8269780657..e14e0aa8b7 100644 --- a/futures-core/Cargo.toml +++ b/futures-core/Cargo.toml @@ -1,3 +1,5 @@ +cargo-features = ["rename-dependency"] + [package] name = "futures-core-preview" edition = "2018" @@ -17,6 +19,10 @@ name = "futures_core" [features] default = ["std"] std = ["either/use_std"] +nightly = [] [dependencies] either = { version = "1.4", default-features = false, optional = true } + +[dev-dependencies] +futures-preview = { path = "../futures", version = "0.3.0-alpha.9" } diff --git a/futures-core/src/lib.rs b/futures-core/src/lib.rs index 48813e8cb0..9b54d2aa54 100644 --- a/futures-core/src/lib.rs +++ b/futures-core/src/lib.rs @@ -1,6 +1,7 @@ //! Core traits and types for asynchronous operations in Rust. #![feature(pin, arbitrary_self_types, futures_api)] +#![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))] #![cfg_attr(not(feature = "std"), no_std)] diff --git a/futures-util/src/task/atomic_waker.rs b/futures-core/src/task/__internal/atomic_waker.rs similarity index 98% rename from futures-util/src/task/atomic_waker.rs rename to futures-core/src/task/__internal/atomic_waker.rs index 45d8695e60..df718c6a6f 100644 --- a/futures-util/src/task/atomic_waker.rs +++ b/futures-core/src/task/__internal/atomic_waker.rs @@ -2,7 +2,7 @@ use core::fmt; use core::cell::UnsafeCell; use core::sync::atomic::AtomicUsize; use core::sync::atomic::Ordering::{Acquire, Release, AcqRel}; -use futures_core::task::{LocalWaker, Waker}; +use crate::task::{LocalWaker, Waker}; /// A synchronization primitive for task wakeup. /// @@ -170,8 +170,9 @@ impl AtomicWaker { /// /// ``` /// #![feature(pin, arbitrary_self_types, futures_api)] - /// use futures::future::Future; - /// use futures::task::{LocalWaker, Poll, AtomicWaker}; + /// use futures_core::future::Future; + /// use futures_core::task::__internal::AtomicWaker; + /// use futures_core::task::{LocalWaker, Poll}; /// use std::sync::atomic::AtomicBool; /// use std::sync::atomic::Ordering::SeqCst; /// use std::pin::Pin; diff --git a/futures-core/src/task/__internal/mod.rs b/futures-core/src/task/__internal/mod.rs new file mode 100644 index 0000000000..822ff8fa68 --- /dev/null +++ b/futures-core/src/task/__internal/mod.rs @@ -0,0 +1,10 @@ +#[cfg_attr( + feature = "nightly", + cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) +)] +mod atomic_waker; +#[cfg_attr( + feature = "nightly", + cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) +)] +pub use self::atomic_waker::AtomicWaker; diff --git a/futures-core/src/task/mod.rs b/futures-core/src/task/mod.rs index be168862ba..95dc3cb57f 100644 --- a/futures-core/src/task/mod.rs +++ b/futures-core/src/task/mod.rs @@ -1,6 +1,8 @@ //! Task notification. mod spawn; +#[doc(hidden)] +pub mod __internal; pub use self::spawn::{Spawn, LocalSpawn, SpawnError}; pub use core::task::{Poll, Waker, LocalWaker, UnsafeWake}; diff --git a/futures-util/src/task/mod.rs b/futures-util/src/task/mod.rs index d3d4ac29c5..93266e6f16 100644 --- a/futures-util/src/task/mod.rs +++ b/futures-util/src/task/mod.rs @@ -15,9 +15,4 @@ pub use self::local_waker_ref::{local_waker_ref, local_waker_ref_from_nonlocal, feature = "nightly", cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) )] -mod atomic_waker; -#[cfg_attr( - feature = "nightly", - cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) -)] -pub use self::atomic_waker::AtomicWaker; +pub use futures_core::task::__internal::AtomicWaker; diff --git a/futures/Cargo.toml b/futures/Cargo.toml index 14cfcbe6f3..bb6e7a830b 100644 --- a/futures/Cargo.toml +++ b/futures/Cargo.toml @@ -36,7 +36,7 @@ futures-test-preview = { path = "../futures-test", version = "0.3.0-alpha.9", de tokio = "0.1.11" [features] -nightly = ["futures-util-preview/nightly"] +nightly = ["futures-util-preview/nightly", "futures-core-preview/nightly"] std = ["futures-core-preview/std", "futures-executor-preview/std", "futures-io-preview/std", "futures-sink-preview/std", "futures-util-preview/std"] default = ["std"] compat = ["std", "futures-util-preview/compat"]