mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-24 00:00:11 +02:00
Remove dead futures2 code. (#538)
The futures 0.2 crate is not intended for widespread usage. Also, the futures team is exploring the compat shim route. If futures 0.3 support is added to Tokio 0.1, then a different integration route will be explored, making the current code unhelpful.
This commit is contained in:
@@ -10,7 +10,6 @@ use self::state::State;
|
||||
|
||||
use notifier::Notifier;
|
||||
use pool::Pool;
|
||||
use sender::Sender;
|
||||
|
||||
use futures::{self, Future, Async};
|
||||
use futures::executor::{self, Spawn};
|
||||
@@ -21,9 +20,6 @@ use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, AtomicPtr};
|
||||
use std::sync::atomic::Ordering::{AcqRel, Release, Relaxed};
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
use futures2;
|
||||
|
||||
/// Harness around a future.
|
||||
///
|
||||
/// This also behaves as a node in the inbound work queue and the blocking
|
||||
@@ -44,7 +40,7 @@ pub(crate) struct Task {
|
||||
/// Store the future at the head of the struct
|
||||
///
|
||||
/// The future is dropped immediately when it transitions to Complete
|
||||
future: UnsafeCell<Option<TaskFuture>>,
|
||||
future: UnsafeCell<Option<Spawn<BoxFuture>>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -56,27 +52,13 @@ pub(crate) enum Run {
|
||||
|
||||
type BoxFuture = Box<Future<Item = (), Error = ()> + Send + 'static>;
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
type BoxFuture2 = Box<futures2::Future<Item = (), Error = futures2::Never> + Send>;
|
||||
|
||||
enum TaskFuture {
|
||||
Futures1(Spawn<BoxFuture>),
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
Futures2 {
|
||||
tls: futures2::task::LocalMap,
|
||||
waker: futures2::task::Waker,
|
||||
fut: BoxFuture2,
|
||||
}
|
||||
}
|
||||
|
||||
// ===== impl Task =====
|
||||
|
||||
impl Task {
|
||||
/// Create a new `Task` as a harness for `future`.
|
||||
pub fn new(future: BoxFuture) -> Task {
|
||||
// Wrap the future with an execution context.
|
||||
let task_fut = TaskFuture::Futures1(executor::spawn(future));
|
||||
let task_fut = executor::spawn(future);
|
||||
|
||||
Task {
|
||||
state: AtomicUsize::new(State::new().into()),
|
||||
@@ -87,31 +69,11 @@ impl Task {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new `Task` as a harness for a futures 0.2 `future`.
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
pub fn new2<F>(fut: BoxFuture2, make_waker: F) -> Task
|
||||
where F: FnOnce(usize) -> futures2::task::Waker
|
||||
{
|
||||
let mut inner = Box::new(Task {
|
||||
state: AtomicUsize::new(State::new().into()),
|
||||
blocking: AtomicUsize::new(BlockingState::new().into()),
|
||||
next: AtomicPtr::new(ptr::null_mut()),
|
||||
next_blocking: AtomicPtr::new(ptr::null_mut()),
|
||||
future: None,
|
||||
});
|
||||
|
||||
let waker = make_waker((&*inner) as *const _ as usize);
|
||||
let tls = futures2::task::LocalMap::new();
|
||||
inner.future = Some(TaskFuture::Futures2 { waker, tls, fut });
|
||||
|
||||
Task { ptr: Box::into_raw(inner) }
|
||||
}
|
||||
|
||||
/// Create a fake `Task` to be used as part of the intrusive mpsc channel
|
||||
/// algorithm.
|
||||
fn stub() -> Task {
|
||||
let future = Box::new(futures::empty());
|
||||
let task_fut = TaskFuture::Futures1(executor::spawn(future));
|
||||
let future = Box::new(futures::empty()) as BoxFuture;
|
||||
let task_fut = executor::spawn(future);
|
||||
|
||||
Task {
|
||||
state: AtomicUsize::new(State::stub().into()),
|
||||
@@ -124,7 +86,7 @@ impl Task {
|
||||
|
||||
/// Execute the task returning `Run::Schedule` if the task needs to be
|
||||
/// scheduled again.
|
||||
pub fn run(&self, unpark: &Arc<Notifier>, exec: &mut Sender) -> Run {
|
||||
pub fn run(&self, unpark: &Arc<Notifier>) -> Run {
|
||||
use self::State::*;
|
||||
|
||||
// Transition task to running state. At this point, the task must be
|
||||
@@ -149,7 +111,7 @@ impl Task {
|
||||
// `thread::panicking() -> true`. To do this, the future is dropped from
|
||||
// within the catch_unwind block.
|
||||
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
struct Guard<'a>(&'a mut Option<TaskFuture>, bool);
|
||||
struct Guard<'a>(&'a mut Option<Spawn<BoxFuture>>, bool);
|
||||
|
||||
impl<'a> Drop for Guard<'a> {
|
||||
fn drop(&mut self) {
|
||||
@@ -163,8 +125,7 @@ impl Task {
|
||||
let mut g = Guard(fut, true);
|
||||
|
||||
let ret = g.0.as_mut().unwrap()
|
||||
.poll(unpark, self as *const _ as usize, exec);
|
||||
|
||||
.poll_future_notify(unpark, self as *const _ as usize);
|
||||
|
||||
g.1 = false;
|
||||
|
||||
@@ -282,23 +243,3 @@ impl fmt::Debug for Task {
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
// ===== impl TaskFuture =====
|
||||
|
||||
impl TaskFuture {
|
||||
#[allow(unused_variables)]
|
||||
fn poll(&mut self, unpark: &Arc<Notifier>, id: usize, exec: &mut Sender) -> futures::Poll<(), ()> {
|
||||
match *self {
|
||||
TaskFuture::Futures1(ref mut fut) => fut.poll_future_notify(unpark, id),
|
||||
|
||||
#[cfg(feature = "unstable-futures")]
|
||||
TaskFuture::Futures2 { ref mut fut, ref waker, ref mut tls } => {
|
||||
let mut cx = futures2::task::Context::new(tls, waker, exec);
|
||||
match fut.poll(&mut cx).unwrap() {
|
||||
futures2::Async::Pending => Ok(Async::NotReady),
|
||||
futures2::Async::Ready(x) => Ok(Async::Ready(x)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user