Skip to content

Commit

Permalink
Change has_atomic_cas to no_atomic_cas to implement a workaround for …
Browse files Browse the repository at this point in the history
…the first problem
  • Loading branch information
taiki-e committed Jan 1, 2021
1 parent d7ad23a commit 2c2dde2
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 25 deletions.
8 changes: 6 additions & 2 deletions futures-channel/build.rs
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
// treating `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
Expand Up @@ -21,7 +21,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
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
// treating `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
@@ -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
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
// treating `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
Expand Up @@ -13,7 +13,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
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
// treating `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
Expand Up @@ -54,7 +54,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
Expand Up @@ -36,11 +36,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 @@ -58,7 +58,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
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
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
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
// treating `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");
}

0 comments on commit 2c2dde2

Please sign in to comment.