mirror of https://github.com/rust-lang/rust.git
fix: make LocalWake available in targets that don't support atomics by removing a #[cfg(target_has_atomic = ptr)]
This commit is contained in:
parent
403718b19d
commit
2012d4b703
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
/// # }
|
||||
|
|
Loading…
Reference in New Issue