Skip to content

Commit

Permalink
Change has_atomic_cas to no_atomic_cas to implement the first workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Dec 31, 2020
1 parent 665c32e commit 621ca85
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 32 deletions.
8 changes: 6 additions & 2 deletions futures-channel/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ fn main() {
}
};

if cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=has_atomic_cas");
// Note that this is `no_atomic_cas`, not `has_atomic_cas`. This allows to
// treat `cfg(target_has_atomic = "ptr")` as true when the build script
// doesn't run. This is needed for compatibility with non-cargo build
// systems that don't run build scripts.
if !cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=no_atomic_cas");
}
println!("cargo:rerun-if-changed=build.rs");
}
2 changes: 1 addition & 1 deletion futures-channel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

macro_rules! cfg_target_has_atomic {
($($item:item)*) => {$(
#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
$item
)*};
}
Expand Down
8 changes: 6 additions & 2 deletions futures-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ fn main() {
}
};

if cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=has_atomic_cas");
// Note that this is `no_atomic_cas`, not `has_atomic_cas`. This allows to
// treat `cfg(target_has_atomic = "ptr")` as true when the build script
// doesn't run. This is needed for compatibility with non-cargo build
// systems that don't run build scripts.
if !cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=no_atomic_cas");
}
println!("cargo:rerun-if-changed=build.rs");
}
4 changes: 2 additions & 2 deletions futures-core/src/task/__internal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
mod atomic_waker;
#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
pub use self::atomic_waker::AtomicWaker;
8 changes: 6 additions & 2 deletions futures-task/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ fn main() {
}
};

if cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=has_atomic_cas");
// Note that this is `no_atomic_cas`, not `has_atomic_cas`. This allows to
// treat `cfg(target_has_atomic = "ptr")` as true when the build script
// doesn't run. This is needed for compatibility with non-cargo build
// systems that don't run build scripts.
if !cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=no_atomic_cas");
}
println!("cargo:rerun-if-changed=build.rs");
}
2 changes: 1 addition & 1 deletion futures-task/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern crate alloc;

macro_rules! cfg_target_has_atomic {
($($item:item)*) => {$(
#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
$item
)*};
}
Expand Down
8 changes: 6 additions & 2 deletions futures-util/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ fn main() {
}
};

if cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=has_atomic_cas");
// Note that this is `no_atomic_cas`, not `has_atomic_cas`. This allows to
// treat `cfg(target_has_atomic = "ptr")` as true when the build script
// doesn't run. This is needed for compatibility with non-cargo build
// systems that don't run build scripts.
if !cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=no_atomic_cas");
}
println!("cargo:rerun-if-changed=build.rs");
}
2 changes: 1 addition & 1 deletion futures-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub mod __private {

macro_rules! cfg_target_has_atomic {
($($item:item)*) => {$(
#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
$item
)*};
}
Expand Down
6 changes: 3 additions & 3 deletions futures-util/src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ pub use self::stream::ReadyChunks;
#[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
pub use self::stream::Forward;

#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use self::stream::{BufferUnordered, Buffered, ForEachConcurrent};

#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "sink")]
#[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
#[cfg(feature = "alloc")]
Expand All @@ -53,7 +53,7 @@ pub use self::try_stream::{
#[cfg(feature = "std")]
pub use self::try_stream::IntoAsyncRead;

#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use self::try_stream::{TryBufferUnordered, TryBuffered, TryForEachConcurrent};

Expand Down
8 changes: 4 additions & 4 deletions futures-util/src/stream/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ pub trait StreamExt: Stream {
/// fut.await;
/// # })
/// ```
#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
fn for_each_concurrent<Fut, F>(
self,
Expand Down Expand Up @@ -1140,7 +1140,7 @@ pub trait StreamExt: Stream {
///
/// This method is only available when the `std` or `alloc` feature of this
/// library is activated, and it is activated by default.
#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
fn buffered(self, n: usize) -> Buffered<Self>
where
Expand Down Expand Up @@ -1185,7 +1185,7 @@ pub trait StreamExt: Stream {
/// assert_eq!(buffered.next().await, None);
/// # Ok::<(), i32>(()) }).unwrap();
/// ```
#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
where
Expand Down Expand Up @@ -1349,7 +1349,7 @@ pub trait StreamExt: Stream {
/// library is activated, and it is activated by default.
#[cfg(feature = "sink")]
#[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
fn split<Item>(self) -> (SplitSink<Self, Item>, SplitStream<Self>)
where
Expand Down
6 changes: 3 additions & 3 deletions futures-util/src/stream/try_stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ pub trait TryStreamExt: TryStream {
/// assert_eq!(Err(oneshot::Canceled), fut.await);
/// # })
/// ```
#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
fn try_for_each_concurrent<Fut, F>(
self,
Expand Down Expand Up @@ -836,7 +836,7 @@ pub trait TryStreamExt: TryStream {
/// assert_eq!(buffered.next().await, Some(Err("error in the stream")));
/// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
/// ```
#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
fn try_buffer_unordered(self, n: usize) -> TryBufferUnordered<Self>
where
Expand Down Expand Up @@ -912,7 +912,7 @@ pub trait TryStreamExt: TryStream {
/// assert_eq!(buffered.next().await, Some(Err("error in the stream")));
/// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
/// ```
#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
fn try_buffered(self, n: usize) -> TryBuffered<Self>
where
Expand Down
8 changes: 6 additions & 2 deletions futures/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ fn main() {
}
};

if cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=has_atomic_cas");
// Note that this is `no_atomic_cas`, not `has_atomic_cas`. This allows to
// treat `cfg(target_has_atomic = "ptr")` as true when the build script
// doesn't run. This is needed for compatibility with non-cargo build
// systems that don't run build scripts.
if !cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=no_atomic_cas");
}
println!("cargo:rerun-if-changed=build.rs");
}
14 changes: 7 additions & 7 deletions futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub use futures_util::{pending, poll, join, try_join, select_biased}; // Async-a
#[cfg(feature = "async-await")]
pub use futures_util::select;

#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
pub mod channel {
//! Cross-task communication.
Expand Down Expand Up @@ -286,7 +286,7 @@ pub mod future {
select_ok, SelectOk,
};

#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use futures_util::future::{
abortable, Abortable, AbortHandle, AbortRegistration, Aborted,
Expand Down Expand Up @@ -347,7 +347,7 @@ pub mod io {
pub use futures_util::io::WriteAllVectored;
}

#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
pub mod lock {
//! Futures-powered synchronization primitives.
Expand Down Expand Up @@ -473,7 +473,7 @@ pub mod stream {
Chunks, ReadyChunks,
};

#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use futures_util::stream::{
FuturesOrdered,
Expand All @@ -492,7 +492,7 @@ pub mod stream {
CatchUnwind,
};

#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use futures_util::stream::{
// For TryStreamExt:
Expand Down Expand Up @@ -531,11 +531,11 @@ pub mod task {
#[cfg(feature = "alloc")]
pub use futures_util::task::{SpawnExt, LocalSpawnExt};

#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use futures_util::task::{waker, waker_ref, WakerRef, ArcWake};

#[cfg(has_atomic_cas)]
#[cfg(not(no_atomic_cas))]
pub use futures_util::task::AtomicWaker;
}

Expand Down

0 comments on commit 621ca85

Please sign in to comment.