about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomás Vallotton <tvallotton@uc.cl>2023-12-06 15:19:24 -0300
committerTomás Vallotton <tvallotton@uc.cl>2024-01-20 10:14:25 -0300
commit2012d4b70370d86c9ed0c60a2ad6bf03d9fc5157 (patch)
tree281ac085759f2522d2cb908fa150f89304d9e465
parent403718b19de6ad0979833fd2cf6074f2a1b50c8c (diff)
downloadrust-2012d4b70370d86c9ed0c60a2ad6bf03d9fc5157.tar.gz
rust-2012d4b70370d86c9ed0c60a2ad6bf03d9fc5157.zip
fix: make LocalWake available in targets that don't support atomics by removing a #[cfg(target_has_atomic = ptr)]
-rw-r--r--library/alloc/src/lib.rs2
-rw-r--r--library/alloc/src/task.rs18
-rw-r--r--library/core/src/task/wake.rs4
3 files changed, 14 insertions, 10 deletions
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index c8b4cebdf89..878aedce3a6 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -254,7 +254,7 @@ pub mod str;
 pub mod string;
 #[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
 pub mod sync;
-#[cfg(all(not(no_global_oom_handling), not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
+#[cfg(all(not(no_global_oom_handling), not(no_rc), not(no_sync)))]
 pub mod task;
 #[cfg(test)]
 mod tests;
diff --git a/library/alloc/src/task.rs b/library/alloc/src/task.rs
index 736a55700f6..9db4c919505 100644
--- a/library/alloc/src/task.rs
+++ b/library/alloc/src/task.rs
@@ -2,15 +2,17 @@
 
 //! Types and Traits for working with asynchronous tasks.
 //!
-//! **Note**: This module is only available on platforms that support atomic
-//! loads and stores of pointers. This may be detected at compile time using
+//! **Note**: Some of the types in this module are only available
+//! on platforms that support atomic loads and stores of pointers. 
+//! This may be detected at compile time using 
 //! `#[cfg(target_has_atomic = "ptr")]`.
 
 use core::mem::ManuallyDrop;
-use core::task::{LocalWaker, RawWaker, RawWakerVTable, Waker};
-
+use core::task::{LocalWaker, RawWaker, RawWakerVTable};
 use crate::rc::Rc;
-use crate::sync::Arc;
+
+#[cfg(target_has_atomic = "ptr")]
+use core::{task::Waker, sync::Arc};
 
 /// The implementation of waking a task on an executor.
 ///
@@ -74,6 +76,7 @@ use crate::sync::Arc;
 ///     println!("Hi from inside a future!");
 /// });
 /// ```
+#[cfg(target_has_atomic = "ptr")]
 #[stable(feature = "wake_trait", since = "1.51.0")]
 pub trait Wake {
     /// Wake this task.
@@ -92,7 +95,7 @@ pub trait Wake {
         self.clone().wake();
     }
 }
-
+#[cfg(target_has_atomic = "ptr")]
 #[stable(feature = "wake_trait", since = "1.51.0")]
 impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {
     /// Use a `Wake`-able type as a `Waker`.
@@ -104,7 +107,7 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {
         unsafe { Waker::from_raw(raw_waker(waker)) }
     }
 }
-
+#[cfg(target_has_atomic = "ptr")]
 #[stable(feature = "wake_trait", since = "1.51.0")]
 impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
     /// Use a `Wake`-able type as a `RawWaker`.
@@ -120,6 +123,7 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
 // the safety of `From<Arc<W>> for Waker` does not depend on the correct
 // trait dispatch - instead both impls call this function directly and
 // explicitly.
+#[cfg(target_has_atomic = "ptr")]
 #[inline(always)]
 fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
     // Increment the reference count of the arc to clone it.
diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs
index fa4590f18ec..5696b63e5fa 100644
--- a/library/core/src/task/wake.rs
+++ b/library/core/src/task/wake.rs
@@ -347,7 +347,7 @@ impl<'a> ContextBuilder<'a> {
 /// use std::task::{Waker, ContextBuilder};
 /// use std::future::{poll_fn, Future};
 /// use std::pin::pin;
-///
+/// 
 /// async fn with_waker<F>(f: F, waker: &Waker) -> F::Output
 /// where
 ///     F: Future
@@ -365,7 +365,7 @@ impl<'a> ContextBuilder<'a> {
 ///         f.as_mut().poll(&mut cx)
 ///     }).await
 /// }
-/// 
+///  
 /// # async fn __() {
 /// with_waker(async { /* ... */ }, &Waker::noop()).await;
 /// # }