Upgrade rust/crates/futures-executor to 0.3.12 Test: make Change-Id: I12d01f1fee572bd237ca5f26f369e7ae2e65ddc6
diff --git a/src/lib.rs b/src/lib.rs index a8ba5c8..b679649 100644 --- a/src/lib.rs +++ b/src/lib.rs
@@ -1,7 +1,40 @@ //! Built-in executors and related tools. //! -//! All items of this library are only available when the `std` feature of this +//! All asynchronous computation occurs within an executor, which is +//! capable of spawning futures as tasks. This module provides several +//! built-in executors, as well as tools for building your own. +//! +//! All items are only available when the `std` feature of this //! library is activated, and it is activated by default. +//! +//! # Using a thread pool (M:N task scheduling) +//! +//! Most of the time tasks should be executed on a [thread pool](ThreadPool). +//! A small set of worker threads can handle a very large set of spawned tasks +//! (which are much lighter weight than threads). Tasks spawned onto the pool +//! with the [`spawn_ok`](ThreadPool::spawn_ok) function will run ambiently on +//! the created threads. +//! +//! # Spawning additional tasks +//! +//! Tasks can be spawned onto a spawner by calling its [`spawn_obj`] method +//! directly. In the case of `!Send` futures, [`spawn_local_obj`] can be used +//! instead. +//! +//! # Single-threaded execution +//! +//! In addition to thread pools, it's possible to run a task (and the tasks +//! it spawns) entirely within a single thread via the [`LocalPool`] executor. +//! Aside from cutting down on synchronization costs, this executor also makes +//! it possible to spawn non-`Send` tasks, via [`spawn_local_obj`]. The +//! [`LocalPool`] is best suited for running I/O-bound tasks that do relatively +//! little work between I/O operations. +//! +//! There is also a convenience function [`block_on`] for simply running a +//! future to completion on the current thread. +//! +//! [`spawn_obj`]: https://docs.rs/futures/0.3/futures/task/trait.Spawn.html#tymethod.spawn_obj +//! [`spawn_local_obj`]: https://docs.rs/futures/0.3/futures/task/trait.LocalSpawn.html#tymethod.spawn_local_obj #![cfg_attr(not(feature = "std"), no_std)] @@ -9,16 +42,8 @@ // It cannot be included in the published code because this lints have false positives in the minimum required version. #![cfg_attr(test, warn(single_use_lifetimes))] #![warn(clippy::all)] - -// mem::take requires Rust 1.40, matches! requires Rust 1.42 -// Can be removed if the minimum supported version increased or if https://github.com/rust-lang/rust-clippy/issues/3941 -// get's implemented. -#![allow(clippy::mem_replace_with_default, clippy::match_like_matches_macro)] - #![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))] -#![doc(html_root_url = "https://docs.rs/futures-executor/0.3.7")] - #![cfg_attr(docsrs, feature(doc_cfg))] #[cfg(feature = "std")]
diff --git a/src/local_pool.rs b/src/local_pool.rs index b089a80..156d5cc 100644 --- a/src/local_pool.rs +++ b/src/local_pool.rs
@@ -118,8 +118,8 @@ impl LocalPool { /// Create a new, empty pool of tasks. - pub fn new() -> LocalPool { - LocalPool { + pub fn new() -> Self { + Self { pool: FuturesUnordered::new(), incoming: Default::default(), }
diff --git a/src/thread_pool.rs b/src/thread_pool.rs index 3247aa3..741e6d9 100644 --- a/src/thread_pool.rs +++ b/src/thread_pool.rs
@@ -80,7 +80,7 @@ /// See documentation for the methods in /// [`ThreadPoolBuilder`](ThreadPoolBuilder) for details on the default /// configuration. - pub fn new() -> Result<ThreadPool, io::Error> { + pub fn new() -> Result<Self, io::Error> { ThreadPoolBuilder::new().create() } @@ -168,9 +168,9 @@ } impl Clone for ThreadPool { - fn clone(&self) -> ThreadPool { + fn clone(&self) -> Self { self.state.cnt.fetch_add(1, Ordering::Relaxed); - ThreadPool { state: self.state.clone() } + Self { state: self.state.clone() } } } @@ -313,7 +313,7 @@ /// Actually run the task (invoking `poll` on the future) on the current /// thread. fn run(self) { - let Task { mut future, wake_handle, mut exec } = self; + let Self { mut future, wake_handle, mut exec } = self; let waker = waker_ref(&wake_handle); let mut cx = Context::from_waker(&waker); @@ -328,7 +328,7 @@ Poll::Pending => {} Poll::Ready(()) => return wake_handle.mutex.complete(), } - let task = Task { + let task = Self { future, wake_handle: wake_handle.clone(), exec,
diff --git a/src/unpark_mutex.rs b/src/unpark_mutex.rs index 1f69aed..c49c64c 100644 --- a/src/unpark_mutex.rs +++ b/src/unpark_mutex.rs
@@ -43,8 +43,8 @@ const COMPLETE: usize = 3; // No transitions out impl<D> UnparkMutex<D> { - pub(crate) fn new() -> UnparkMutex<D> { - UnparkMutex { + pub(crate) fn new() -> Self { + Self { status: AtomicUsize::new(WAITING), inner: UnsafeCell::new(None), }