Update Tokio to use std::future. (#1120)

A first pass at updating Tokio to use `std::future`.

Implementations of `Future` from the futures crate are updated to implement
`Future` from std. Implementations of `Stream` are moved to a feature flag.

This commits disables a number of crates that have not yet been updated.
This commit is contained in:
Carl Lerche
2019-06-24 12:34:30 -07:00
committed by GitHub
parent aa99950b9c
commit 06c473e628
150 changed files with 2694 additions and 9825 deletions
+17 -18
View File
@@ -2,15 +2,15 @@ use crate::atomic::AtomicU64;
use crate::timer::{HandlePriv, Inner};
use crate::Error;
use crossbeam_utils::CachePadded;
use futures::task::AtomicTask;
use futures::Poll;
use std::cell::UnsafeCell;
use std::ptr;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::{Relaxed, SeqCst};
use std::sync::{Arc, Weak};
use std::task::{self, Poll};
use std::time::{Duration, Instant};
use std::u64;
use tokio_sync::task::AtomicWaker;
/// Internal state shared between a `Delay` instance and the timer.
///
@@ -46,7 +46,7 @@ pub(crate) struct Entry {
state: AtomicU64,
/// Task to notify once the deadline is reached.
task: AtomicTask,
waker: AtomicWaker,
/// True when the entry is queued in the "process" stack. This value
/// is set before pushing the value and unset after popping the value.
@@ -109,7 +109,7 @@ impl Entry {
Entry {
time: CachePadded::new(UnsafeCell::new(Time { deadline, duration })),
inner: None,
task: AtomicTask::new(),
waker: AtomicWaker::new(),
state: AtomicU64::new(0),
queued: AtomicBool::new(false),
next_atomic: UnsafeCell::new(ptr::null_mut()),
@@ -246,7 +246,7 @@ impl Entry {
curr = actual;
}
self.task.notify();
self.waker.wake();
}
pub fn error(&self) {
@@ -269,7 +269,7 @@ impl Entry {
curr = actual;
}
self.task.notify();
self.waker.wake();
}
pub fn cancel(entry: &Arc<Entry>) {
@@ -289,32 +289,31 @@ impl Entry {
let _ = inner.queue(entry);
}
pub fn poll_elapsed(&self) -> Poll<(), Error> {
use futures::Async::NotReady;
pub fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll<Result<(), Error>> {
let mut curr = self.state.load(SeqCst);
if is_elapsed(curr) {
if curr == ERROR {
return Err(Error::shutdown());
return Poll::Ready(if curr == ERROR {
Err(Error::shutdown())
} else {
return Ok(().into());
}
Ok(())
});
}
self.task.register();
self.waker.register_by_ref(cx.waker());
curr = self.state.load(SeqCst).into();
if is_elapsed(curr) {
if curr == ERROR {
return Err(Error::shutdown());
return Poll::Ready(if curr == ERROR {
Err(Error::shutdown())
} else {
return Ok(().into());
}
Ok(())
});
}
Ok(NotReady)
Poll::Pending
}
/// Only called by `Registration`
+4 -8
View File
@@ -1,9 +1,9 @@
use crate::timer::Inner;
use crate::{Deadline, Delay, Error, Interval, Timeout};
use crate::{Delay, Error, /*Interval,*/ Timeout};
use std::cell::RefCell;
use std::fmt;
use std::sync::{Arc, Weak};
use std::time::{Duration, Instant};
use std::time::{/*Duration,*/ Instant};
use tokio_executor::Enter;
/// Handle to timer instance.
@@ -137,22 +137,18 @@ impl Handle {
}
}
#[doc(hidden)]
#[deprecated(since = "0.2.11", note = "use timeout instead")]
pub fn deadline<T>(&self, future: T, deadline: Instant) -> Deadline<T> {
Deadline::new_with_delay(future, self.delay(deadline))
}
/// Create a `Timeout` driven by this handle's associated `Timer`.
pub fn timeout<T>(&self, value: T, deadline: Instant) -> Timeout<T> {
Timeout::new_with_delay(value, self.delay(deadline))
}
/*
/// Create a new `Interval` that starts at `at` and yields every `duration`
/// interval after that.
pub fn interval(&self, at: Instant, duration: Duration) -> Interval {
Interval::new_with_delay(self.delay(at), duration)
}
*/
fn as_priv(&self) -> Option<&HandlePriv> {
self.inner.as_ref()
+6 -5
View File
@@ -1,8 +1,7 @@
use crate::clock::now;
use crate::timer::{Entry, HandlePriv};
use crate::Error;
use futures::Poll;
use std::sync::Arc;
use std::task::{self, Poll};
use std::time::{Duration, Instant};
/// Registration with a timer.
@@ -43,8 +42,10 @@ impl Registration {
Entry::reset(&mut self.entry);
}
// Used by `Timeout<Stream>`
#[cfg(feature = "timeout-stream")]
pub fn reset_timeout(&mut self) {
let deadline = now() + self.entry.time_ref().duration;
let deadline = crate::clock::now() + self.entry.time_ref().duration;
self.entry.time_mut().deadline = deadline;
Entry::reset(&mut self.entry);
}
@@ -53,8 +54,8 @@ impl Registration {
self.entry.is_elapsed()
}
pub fn poll_elapsed(&self) -> Poll<(), Error> {
self.entry.poll_elapsed()
pub fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll<Result<(), Error>> {
self.entry.poll_elapsed(cx)
}
}