Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2012d4b

Browse files
committed
fix: make LocalWake available in targets that don't support atomics by removing a #[cfg(target_has_atomic = ptr)]
1 parent 403718b commit 2012d4b

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

library/alloc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub mod str;
254254
pub mod string;
255255
#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
256256
pub mod sync;
257-
#[cfg(all(not(no_global_oom_handling), not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
257+
#[cfg(all(not(no_global_oom_handling), not(no_rc), not(no_sync)))]
258258
pub mod task;
259259
#[cfg(test)]
260260
mod tests;

library/alloc/src/task.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
//! Types and Traits for working with asynchronous tasks.
44
//!
5-
//! **Note**: This module is only available on platforms that support atomic
6-
//! loads and stores of pointers. This may be detected at compile time using
5+
//! **Note**: Some of the types in this module are only available
6+
//! on platforms that support atomic loads and stores of pointers.
7+
//! This may be detected at compile time using
78
//! `#[cfg(target_has_atomic = "ptr")]`.
89
910
use core::mem::ManuallyDrop;
10-
use core::task::{LocalWaker, RawWaker, RawWakerVTable, Waker};
11-
11+
use core::task::{LocalWaker, RawWaker, RawWakerVTable};
1212
use crate::rc::Rc;
13-
use crate::sync::Arc;
13+
14+
#[cfg(target_has_atomic = "ptr")]
15+
use core::{task::Waker, sync::Arc};
1416

1517
/// The implementation of waking a task on an executor.
1618
///
@@ -74,6 +76,7 @@ use crate::sync::Arc;
7476
/// println!("Hi from inside a future!");
7577
/// });
7678
/// ```
79+
#[cfg(target_has_atomic = "ptr")]
7780
#[stable(feature = "wake_trait", since = "1.51.0")]
7881
pub trait Wake {
7982
/// Wake this task.
@@ -92,7 +95,7 @@ pub trait Wake {
9295
self.clone().wake();
9396
}
9497
}
95-
98+
#[cfg(target_has_atomic = "ptr")]
9699
#[stable(feature = "wake_trait", since = "1.51.0")]
97100
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {
98101
/// Use a `Wake`-able type as a `Waker`.
@@ -104,7 +107,7 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {
104107
unsafe { Waker::from_raw(raw_waker(waker)) }
105108
}
106109
}
107-
110+
#[cfg(target_has_atomic = "ptr")]
108111
#[stable(feature = "wake_trait", since = "1.51.0")]
109112
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
110113
/// Use a `Wake`-able type as a `RawWaker`.
@@ -120,6 +123,7 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
120123
// the safety of `From<Arc<W>> for Waker` does not depend on the correct
121124
// trait dispatch - instead both impls call this function directly and
122125
// explicitly.
126+
#[cfg(target_has_atomic = "ptr")]
123127
#[inline(always)]
124128
fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
125129
// Increment the reference count of the arc to clone it.

library/core/src/task/wake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'a> ContextBuilder<'a> {
347347
/// use std::task::{Waker, ContextBuilder};
348348
/// use std::future::{poll_fn, Future};
349349
/// use std::pin::pin;
350-
///
350+
///
351351
/// async fn with_waker<F>(f: F, waker: &Waker) -> F::Output
352352
/// where
353353
/// F: Future
@@ -365,7 +365,7 @@ impl<'a> ContextBuilder<'a> {
365365
/// f.as_mut().poll(&mut cx)
366366
/// }).await
367367
/// }
368-
///
368+
///
369369
/// # async fn __() {
370370
/// with_waker(async { /* ... */ }, &Waker::noop()).await;
371371
/// # }

0 commit comments

Comments
 (0)