about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorMatthias Einwag <matthias.einwag@live.com>2019-01-29 19:02:42 -0800
committerMatthias Einwag <matthias.einwag@live.com>2019-02-03 13:46:53 -0800
commitd9a4b22d3291913a8f2158a1b7c195bc30c9286e (patch)
treecfa2cc014dc500634727555d9fc16b818e2c10f0 /src/libstd
parent4f4f4a40b6c7bcb6fa07ee6575e8a9759ba08922 (diff)
downloadrust-d9a4b22d3291913a8f2158a1b7c195bc30c9286e.tar.gz
rust-d9a4b22d3291913a8f2158a1b7c195bc30c9286e.zip
Update the future/task API
This change updates the future and task API as discussed in the stabilization RFC at https://github.com/rust-lang/rfcs/pull/2592.

Changes:
- Replacing UnsafeWake with RawWaker and RawWakerVtable
- Removal of LocalWaker
- Removal of Arc-based Wake trait
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/future.rs20
-rw-r--r--src/libstd/lib.rs2
-rw-r--r--src/libstd/panic.rs6
3 files changed, 13 insertions, 15 deletions
diff --git a/src/libstd/future.rs b/src/libstd/future.rs
index d1203be3cf0..aa784746122 100644
--- a/src/libstd/future.rs
+++ b/src/libstd/future.rs
@@ -5,7 +5,7 @@ use core::marker::Unpin;
 use core::pin::Pin;
 use core::option::Option;
 use core::ptr::NonNull;
-use core::task::{LocalWaker, Poll};
+use core::task::{Waker, Poll};
 use core::ops::{Drop, Generator, GeneratorState};
 
 #[doc(inline)]
@@ -32,10 +32,10 @@ impl<T: Generator<Yield = ()>> !Unpin for GenFuture<T> {}
 #[unstable(feature = "gen_future", issue = "50547")]
 impl<T: Generator<Yield = ()>> Future for GenFuture<T> {
     type Output = T::Return;
-    fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<Self::Output> {
+    fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> {
         // Safe because we're !Unpin + !Drop mapping to a ?Unpin value
         let gen = unsafe { Pin::map_unchecked_mut(self, |s| &mut s.0) };
-        set_task_waker(lw, || match gen.resume() {
+        set_task_waker(waker, || match gen.resume() {
             GeneratorState::Yielded(()) => Poll::Pending,
             GeneratorState::Complete(x) => Poll::Ready(x),
         })
@@ -43,10 +43,10 @@ impl<T: Generator<Yield = ()>> Future for GenFuture<T> {
 }
 
 thread_local! {
-    static TLS_WAKER: Cell<Option<NonNull<LocalWaker>>> = Cell::new(None);
+    static TLS_WAKER: Cell<Option<NonNull<Waker>>> = Cell::new(None);
 }
 
-struct SetOnDrop(Option<NonNull<LocalWaker>>);
+struct SetOnDrop(Option<NonNull<Waker>>);
 
 impl Drop for SetOnDrop {
     fn drop(&mut self) {
@@ -58,12 +58,12 @@ impl Drop for SetOnDrop {
 
 #[unstable(feature = "gen_future", issue = "50547")]
 /// Sets the thread-local task context used by async/await futures.
-pub fn set_task_waker<F, R>(lw: &LocalWaker, f: F) -> R
+pub fn set_task_waker<F, R>(waker: &Waker, f: F) -> R
 where
     F: FnOnce() -> R
 {
     let old_waker = TLS_WAKER.with(|tls_waker| {
-        tls_waker.replace(Some(NonNull::from(lw)))
+        tls_waker.replace(Some(NonNull::from(waker)))
     });
     let _reset_waker = SetOnDrop(old_waker);
     f()
@@ -78,7 +78,7 @@ where
 /// retrieved by a surrounding call to get_task_waker.
 pub fn get_task_waker<F, R>(f: F) -> R
 where
-    F: FnOnce(&LocalWaker) -> R
+    F: FnOnce(&Waker) -> R
 {
     let waker_ptr = TLS_WAKER.with(|tls_waker| {
         // Clear the entry so that nested `get_task_waker` calls
@@ -88,7 +88,7 @@ where
     let _reset_waker = SetOnDrop(waker_ptr);
 
     let waker_ptr = waker_ptr.expect(
-        "TLS LocalWaker not set. This is a rustc bug. \
+        "TLS Waker not set. This is a rustc bug. \
         Please file an issue on https://github.com/rust-lang/rust.");
     unsafe { f(waker_ptr.as_ref()) }
 }
@@ -99,5 +99,5 @@ pub fn poll_with_tls_waker<F>(f: Pin<&mut F>) -> Poll<F::Output>
 where
     F: Future
 {
-    get_task_waker(|lw| F::poll(f, lw))
+    get_task_waker(|waker| F::poll(f, waker))
 }
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs
index 244caf28ec7..207ba9ae02f 100644
--- a/src/libstd/lib.rs
+++ b/src/libstd/lib.rs
@@ -468,8 +468,6 @@ pub mod task {
     //! Types and Traits for working with asynchronous tasks.
     #[doc(inline)]
     pub use core::task::*;
-    #[doc(inline)]
-    pub use alloc_crate::task::*;
 }
 
 #[unstable(feature = "futures_api",
diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs
index d27f6ca88c2..862fdf051cc 100644
--- a/src/libstd/panic.rs
+++ b/src/libstd/panic.rs
@@ -12,7 +12,7 @@ use panicking;
 use ptr::{Unique, NonNull};
 use rc::Rc;
 use sync::{Arc, Mutex, RwLock, atomic};
-use task::{LocalWaker, Poll};
+use task::{Waker, Poll};
 use thread::Result;
 
 #[stable(feature = "panic_hooks", since = "1.10.0")]
@@ -323,9 +323,9 @@ impl<T: fmt::Debug> fmt::Debug for AssertUnwindSafe<T> {
 impl<'a, F: Future> Future for AssertUnwindSafe<F> {
     type Output = F::Output;
 
-    fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<Self::Output> {
+    fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> {
         let pinned_field = unsafe { Pin::map_unchecked_mut(self, |x| &mut x.0) };
-        F::poll(pinned_field, lw)
+        F::poll(pinned_field, waker)
     }
 }