mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
Update Tokio to Rust 2018 (#1082)
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
use worker::Worker;
|
||||
|
||||
use futures::Poll;
|
||||
|
||||
use crate::worker::Worker;
|
||||
use futures::{try_ready, Poll};
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
|
||||
@@ -80,9 +78,6 @@ pub struct BlockingError {
|
||||
/// that needs to be performed.
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate futures;
|
||||
/// # extern crate tokio_threadpool;
|
||||
///
|
||||
/// use tokio_threadpool::{ThreadPool, blocking};
|
||||
///
|
||||
/// use futures::Future;
|
||||
@@ -157,13 +152,13 @@ where
|
||||
}
|
||||
|
||||
impl fmt::Display for BlockingError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(fmt, "{}", self.description())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for BlockingError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("BlockingError")
|
||||
.field("reason", &self.description())
|
||||
.finish()
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
use callback::Callback;
|
||||
use config::{Config, MAX_WORKERS};
|
||||
use park::{BoxPark, BoxedPark, DefaultPark};
|
||||
use pool::{Pool, MAX_BACKUP};
|
||||
use shutdown::ShutdownTrigger;
|
||||
use thread_pool::ThreadPool;
|
||||
use worker::{self, Worker, WorkerId};
|
||||
|
||||
use crate::callback::Callback;
|
||||
use crate::config::{Config, MAX_WORKERS};
|
||||
use crate::park::{BoxPark, BoxedPark, DefaultPark};
|
||||
use crate::pool::{Pool, MAX_BACKUP};
|
||||
use crate::shutdown::ShutdownTrigger;
|
||||
use crate::thread_pool::ThreadPool;
|
||||
use crate::worker::{self, Worker, WorkerId};
|
||||
use crossbeam_deque::Injector;
|
||||
use log::trace;
|
||||
use num_cpus;
|
||||
use std::any::Any;
|
||||
use std::cmp::max;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use crossbeam_deque::Injector;
|
||||
use num_cpus;
|
||||
use tokio_executor::park::Park;
|
||||
use tokio_executor::Enter;
|
||||
|
||||
@@ -34,13 +33,10 @@ use tokio_executor::Enter;
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::Builder;
|
||||
/// use tokio_threadpool::Builder;
|
||||
/// use futures::future::{Future, lazy};
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .pool_size(4)
|
||||
/// .keep_alive(Some(Duration::from_secs(30)))
|
||||
@@ -53,7 +49,6 @@ use tokio_executor::Enter;
|
||||
///
|
||||
/// // Gracefully shutdown the threadpool
|
||||
/// thread_pool.shutdown().wait().unwrap();
|
||||
/// # }
|
||||
/// ```
|
||||
pub struct Builder {
|
||||
/// Thread pool specific configuration values
|
||||
@@ -67,7 +62,7 @@ pub struct Builder {
|
||||
max_blocking: usize,
|
||||
|
||||
/// Generates the `Park` instances
|
||||
new_park: Box<Fn(&WorkerId) -> BoxPark>,
|
||||
new_park: Box<dyn Fn(&WorkerId) -> BoxPark>,
|
||||
}
|
||||
|
||||
impl Builder {
|
||||
@@ -79,17 +74,13 @@ impl Builder {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::Builder;
|
||||
/// use tokio_threadpool::Builder;
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .pool_size(4)
|
||||
/// .keep_alive(Some(Duration::from_secs(30)))
|
||||
/// .build();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn new() -> Builder {
|
||||
let num_cpus = max(1, num_cpus::get());
|
||||
@@ -123,15 +114,11 @@ impl Builder {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::Builder;
|
||||
/// use tokio_threadpool::Builder;
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .pool_size(4)
|
||||
/// .build();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn pool_size(&mut self, val: usize) -> &mut Self {
|
||||
assert!(val >= 1, "at least one thread required");
|
||||
@@ -155,15 +142,11 @@ impl Builder {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::Builder;
|
||||
/// use tokio_threadpool::Builder;
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .max_blocking(200)
|
||||
/// .build();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn max_blocking(&mut self, val: usize) -> &mut Self {
|
||||
assert!(val <= MAX_BACKUP, "max value is {}", MAX_BACKUP);
|
||||
@@ -185,16 +168,12 @@ impl Builder {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::Builder;
|
||||
/// use tokio_threadpool::Builder;
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .keep_alive(Some(Duration::from_secs(30)))
|
||||
/// .build();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn keep_alive(&mut self, val: Option<Duration>) -> &mut Self {
|
||||
self.config.keep_alive = val;
|
||||
@@ -211,19 +190,15 @@ impl Builder {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::Builder;
|
||||
/// use tokio_threadpool::Builder;
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .panic_handler(|err| std::panic::resume_unwind(err))
|
||||
/// .build();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn panic_handler<F>(&mut self, f: F) -> &mut Self
|
||||
where
|
||||
F: Fn(Box<Any + Send>) + Send + Sync + 'static,
|
||||
F: Fn(Box<dyn Any + Send>) + Send + Sync + 'static,
|
||||
{
|
||||
self.config.panic_handler = Some(Arc::new(f));
|
||||
self
|
||||
@@ -241,15 +216,11 @@ impl Builder {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::Builder;
|
||||
/// use tokio_threadpool::Builder;
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .name_prefix("my-pool-")
|
||||
/// .build();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn name_prefix<S: Into<String>>(&mut self, val: S) -> &mut Self {
|
||||
self.config.name_prefix = Some(val.into());
|
||||
@@ -267,15 +238,11 @@ impl Builder {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::Builder;
|
||||
/// use tokio_threadpool::Builder;
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .stack_size(32 * 1024)
|
||||
/// .build();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn stack_size(&mut self, val: usize) -> &mut Self {
|
||||
self.config.stack_size = Some(val);
|
||||
@@ -291,11 +258,8 @@ impl Builder {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::Builder;
|
||||
/// use tokio_threadpool::Builder;
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .around_worker(|worker, _| {
|
||||
/// println!("worker is starting up");
|
||||
@@ -303,7 +267,6 @@ impl Builder {
|
||||
/// println!("worker is shutting down");
|
||||
/// })
|
||||
/// .build();
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// [`Worker::run`]: struct.Worker.html#method.run
|
||||
@@ -323,17 +286,13 @@ impl Builder {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::Builder;
|
||||
/// use tokio_threadpool::Builder;
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .after_start(|| {
|
||||
/// println!("thread started");
|
||||
/// })
|
||||
/// .build();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn after_start<F>(&mut self, f: F) -> &mut Self
|
||||
where
|
||||
@@ -350,17 +309,13 @@ impl Builder {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::Builder;
|
||||
/// use tokio_threadpool::Builder;
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .before_stop(|| {
|
||||
/// println!("thread stopping");
|
||||
/// })
|
||||
/// .build();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn before_stop<F>(&mut self, f: F) -> &mut Self
|
||||
where
|
||||
@@ -378,12 +333,9 @@ impl Builder {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::Builder;
|
||||
/// use tokio_threadpool::Builder;
|
||||
/// # fn decorate<F>(f: F) -> F { f }
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .custom_park(|_| {
|
||||
/// use tokio_threadpool::park::DefaultPark;
|
||||
@@ -397,7 +349,6 @@ impl Builder {
|
||||
/// decorate(park)
|
||||
/// })
|
||||
/// .build();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn custom_park<F, P>(&mut self, f: F) -> &mut Self
|
||||
where
|
||||
@@ -417,14 +368,10 @@ impl Builder {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::Builder;
|
||||
/// use tokio_threadpool::Builder;
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// let thread_pool = Builder::new()
|
||||
/// .build();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn build(&self) -> ThreadPool {
|
||||
trace!("build; num-workers={}", self.pool_size);
|
||||
@@ -466,7 +413,7 @@ impl Builder {
|
||||
}
|
||||
|
||||
impl fmt::Debug for Builder {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt.debug_struct("Builder")
|
||||
.field("config", &self.config)
|
||||
.field("pool_size", &self.pool_size)
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
use worker::Worker;
|
||||
|
||||
use crate::worker::Worker;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
|
||||
use tokio_executor::Enter;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct Callback {
|
||||
f: Arc<Fn(&Worker, &mut Enter) + Send + Sync>,
|
||||
f: Arc<dyn Fn(&Worker, &mut Enter) + Send + Sync>,
|
||||
}
|
||||
|
||||
impl Callback {
|
||||
@@ -24,7 +22,7 @@ impl Callback {
|
||||
}
|
||||
|
||||
impl fmt::Debug for Callback {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(fmt, "Fn")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use callback::Callback;
|
||||
|
||||
use crate::callback::Callback;
|
||||
use std::any::Any;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
@@ -13,9 +12,9 @@ pub(crate) struct Config {
|
||||
pub name_prefix: Option<String>,
|
||||
pub stack_size: Option<usize>,
|
||||
pub around_worker: Option<Callback>,
|
||||
pub after_start: Option<Arc<Fn() + Send + Sync>>,
|
||||
pub before_stop: Option<Arc<Fn() + Send + Sync>>,
|
||||
pub panic_handler: Option<Arc<Fn(Box<Any + Send>) + Send + Sync>>,
|
||||
pub after_start: Option<Arc<dyn Fn() + Send + Sync>>,
|
||||
pub before_stop: Option<Arc<dyn Fn() + Send + Sync>>,
|
||||
pub panic_handler: Option<Arc<dyn Fn(Box<dyn Any + Send>) + Send + Sync>>,
|
||||
}
|
||||
|
||||
/// Max number of workers that can be part of a pool. This is the most that can
|
||||
@@ -24,7 +23,7 @@ pub(crate) struct Config {
|
||||
pub(crate) const MAX_WORKERS: usize = 1 << 15;
|
||||
|
||||
impl fmt::Debug for Config {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt.debug_struct("Config")
|
||||
.field("keep_alive", &self.keep_alive)
|
||||
.field("name_prefix", &self.name_prefix)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-threadpool/0.1.14")]
|
||||
#![deny(warnings, missing_docs, missing_debug_implementations)]
|
||||
#![deny(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
#![cfg_attr(test, deny(warnings))]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
|
||||
//! A work-stealing based thread pool for executing futures.
|
||||
//!
|
||||
@@ -77,20 +79,6 @@
|
||||
//! [`blocking`]: fn.blocking.html
|
||||
//! [`runtime`]: https://docs.rs/tokio/0.1/tokio/runtime/
|
||||
|
||||
extern crate tokio_executor;
|
||||
|
||||
extern crate crossbeam_deque;
|
||||
extern crate crossbeam_queue;
|
||||
extern crate crossbeam_utils;
|
||||
#[macro_use]
|
||||
extern crate futures;
|
||||
extern crate num_cpus;
|
||||
extern crate rand;
|
||||
extern crate slab;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
// ## Crate layout
|
||||
//
|
||||
// The primary type, `Pool`, holds the majority of a thread pool's state,
|
||||
@@ -155,9 +143,9 @@ mod task;
|
||||
mod thread_pool;
|
||||
mod worker;
|
||||
|
||||
pub use blocking::{blocking, BlockingError};
|
||||
pub use builder::Builder;
|
||||
pub use sender::Sender;
|
||||
pub use shutdown::Shutdown;
|
||||
pub use thread_pool::{SpawnHandle, ThreadPool};
|
||||
pub use worker::{Worker, WorkerId};
|
||||
pub use crate::blocking::{blocking, BlockingError};
|
||||
pub use crate::builder::Builder;
|
||||
pub use crate::sender::Sender;
|
||||
pub use crate::shutdown::Shutdown;
|
||||
pub use crate::thread_pool::{SpawnHandle, ThreadPool};
|
||||
pub use crate::worker::{Worker, WorkerId};
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
use pool::Pool;
|
||||
use task::Task;
|
||||
|
||||
use crate::pool::Pool;
|
||||
use crate::task::Task;
|
||||
use futures::executor::Notify;
|
||||
use log::trace;
|
||||
use std::mem;
|
||||
use std::ops;
|
||||
use std::sync::Arc;
|
||||
|
||||
use futures::executor::Notify;
|
||||
|
||||
/// Implements the future `Notify` API.
|
||||
///
|
||||
/// This is how external events are able to signal the task, informing it to try
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use tokio_executor::park::{Park, Unpark};
|
||||
|
||||
use log::warn;
|
||||
use std::error::Error;
|
||||
use std::time::Duration;
|
||||
use tokio_executor::park::{Park, Unpark};
|
||||
|
||||
pub(crate) type BoxPark = Box<Park<Unpark = BoxUnpark, Error = ()> + Send>;
|
||||
pub(crate) type BoxUnpark = Box<Unpark>;
|
||||
pub(crate) type BoxPark = Box<dyn Park<Unpark = BoxUnpark, Error = ()> + Send>;
|
||||
pub(crate) type BoxUnpark = Box<dyn Unpark>;
|
||||
|
||||
pub(crate) struct BoxedPark<T>(T);
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
use tokio_executor::park::{Park, Unpark};
|
||||
|
||||
use crossbeam_utils::sync::{Parker, Unparker};
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::time::Duration;
|
||||
|
||||
use crossbeam_utils::sync::{Parker, Unparker};
|
||||
use tokio_executor::park::{Park, Unpark};
|
||||
|
||||
/// Parks the thread.
|
||||
#[derive(Debug)]
|
||||
@@ -85,7 +83,7 @@ impl Unpark for DefaultUnpark {
|
||||
// ===== impl ParkError =====
|
||||
|
||||
impl fmt::Display for ParkError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.description().fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use park::DefaultPark;
|
||||
use worker::WorkerId;
|
||||
use crate::park::DefaultPark;
|
||||
use crate::worker::WorkerId;
|
||||
|
||||
use std::cell::UnsafeCell;
|
||||
use std::fmt;
|
||||
@@ -298,7 +298,7 @@ impl From<State> for usize {
|
||||
}
|
||||
|
||||
impl fmt::Debug for State {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt.debug_struct("backup::State")
|
||||
.field("is_pushed", &self.is_pushed())
|
||||
.field("is_running", &self.is_running())
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use pool::{Backup, BackupId};
|
||||
use crate::pool::{Backup, BackupId};
|
||||
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering::{AcqRel, Acquire};
|
||||
|
||||
@@ -9,13 +9,15 @@ pub(crate) use self::state::{Lifecycle, State, MAX_FUTURES};
|
||||
use self::backup::Handoff;
|
||||
use self::backup_stack::BackupStack;
|
||||
|
||||
use config::Config;
|
||||
use shutdown::ShutdownTrigger;
|
||||
use task::{Blocking, Task};
|
||||
use worker::{self, Worker, WorkerId};
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::shutdown::ShutdownTrigger;
|
||||
use crate::task::{Blocking, Task};
|
||||
use crate::worker::{self, Worker, WorkerId};
|
||||
use crossbeam_deque::Injector;
|
||||
use crossbeam_utils::CachePadded;
|
||||
use futures::Poll;
|
||||
|
||||
use log::{debug, error, trace};
|
||||
use rand;
|
||||
use std::cell::Cell;
|
||||
use std::num::Wrapping;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
@@ -23,10 +25,6 @@ use std::sync::atomic::Ordering::{AcqRel, Acquire};
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::thread;
|
||||
|
||||
use crossbeam_deque::Injector;
|
||||
use crossbeam_utils::CachePadded;
|
||||
use rand;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Pool {
|
||||
// Tracks the state of the thread pool (running, shutting down, ...).
|
||||
@@ -202,7 +200,7 @@ impl Pool {
|
||||
}
|
||||
|
||||
pub fn terminate_sleeping_workers(&self) {
|
||||
use worker::Lifecycle::Signaled;
|
||||
use crate::worker::Lifecycle::Signaled;
|
||||
|
||||
trace!(" -> shutting down workers");
|
||||
// Wakeup all sleeping workers. They will wake up, see the state
|
||||
@@ -221,7 +219,7 @@ impl Pool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn poll_blocking_capacity(&self, task: &Arc<Task>) -> Poll<(), ::BlockingError> {
|
||||
pub fn poll_blocking_capacity(&self, task: &Arc<Task>) -> Poll<(), crate::BlockingError> {
|
||||
self.blocking.poll_blocking_capacity(task)
|
||||
}
|
||||
|
||||
@@ -395,7 +393,7 @@ impl Pool {
|
||||
pub fn signal_work(&self, pool: &Arc<Pool>) {
|
||||
debug_assert_eq!(*self, **pool);
|
||||
|
||||
use worker::Lifecycle::Signaled;
|
||||
use crate::worker::Lifecycle::Signaled;
|
||||
|
||||
if let Some((idx, worker_state)) = self.sleep_stack.pop(&self.workers, Signaled, false) {
|
||||
let entry = &self.workers[idx];
|
||||
|
||||
@@ -99,7 +99,7 @@ impl From<State> for usize {
|
||||
}
|
||||
|
||||
impl fmt::Debug for State {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt.debug_struct("pool::State")
|
||||
.field("lifecycle", &self.lifecycle())
|
||||
.field("num_futures", &self.num_futures())
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use pool::{self, Lifecycle, Pool, MAX_FUTURES};
|
||||
use task::Task;
|
||||
|
||||
use crate::pool::{self, Lifecycle, Pool, MAX_FUTURES};
|
||||
use crate::task::Task;
|
||||
use futures::{future, Future};
|
||||
use log::trace;
|
||||
use std::sync::atomic::Ordering::{AcqRel, Acquire};
|
||||
use std::sync::Arc;
|
||||
|
||||
use futures::{future, Future};
|
||||
use tokio_executor::{self, SpawnError};
|
||||
|
||||
/// Submit futures to the associated thread pool for execution.
|
||||
@@ -58,8 +57,6 @@ impl Sender {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::ThreadPool;
|
||||
/// use futures::future::{Future, lazy};
|
||||
///
|
||||
@@ -131,7 +128,7 @@ impl tokio_executor::Executor for Sender {
|
||||
|
||||
fn spawn(
|
||||
&mut self,
|
||||
future: Box<Future<Item = (), Error = ()> + Send>,
|
||||
future: Box<dyn Future<Item = (), Error = ()> + Send>,
|
||||
) -> Result<(), SpawnError> {
|
||||
let mut s = &*self;
|
||||
tokio_executor::Executor::spawn(&mut s, future)
|
||||
@@ -157,7 +154,7 @@ impl<'a> tokio_executor::Executor for &'a Sender {
|
||||
|
||||
fn spawn(
|
||||
&mut self,
|
||||
future: Box<Future<Item = (), Error = ()> + Send>,
|
||||
future: Box<dyn Future<Item = (), Error = ()> + Send>,
|
||||
) -> Result<(), SpawnError> {
|
||||
self.prepare_for_spawn()?;
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
use task::Task;
|
||||
use worker;
|
||||
|
||||
use crate::task::Task;
|
||||
use crate::worker;
|
||||
use crossbeam_deque::Injector;
|
||||
use futures::task::AtomicTask;
|
||||
use futures::{Async, Future, Poll};
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
/// Future that resolves when the thread pool is shutdown.
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use pool::Pool;
|
||||
use task::{BlockingState, Task};
|
||||
|
||||
use crate::pool::Pool;
|
||||
use crate::task::{BlockingState, Task};
|
||||
use futures::{Async, Poll};
|
||||
|
||||
use std::cell::UnsafeCell;
|
||||
use std::fmt;
|
||||
use std::ptr;
|
||||
@@ -111,7 +109,7 @@ impl Blocking {
|
||||
///
|
||||
/// The caller must ensure that `task` has not previously been queued to be
|
||||
/// notified when capacity becomes available.
|
||||
pub fn poll_blocking_capacity(&self, task: &Arc<Task>) -> Poll<(), ::BlockingError> {
|
||||
pub fn poll_blocking_capacity(&self, task: &Arc<Task>) -> Poll<(), crate::BlockingError> {
|
||||
// This requires atomically claiming blocking capacity and if none is
|
||||
// available, queuing &task.
|
||||
|
||||
@@ -482,7 +480,7 @@ impl From<State> for usize {
|
||||
}
|
||||
|
||||
impl fmt::Debug for State {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut fmt = fmt.debug_struct("State");
|
||||
|
||||
if self.is_ptr() {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use task::CanBlock;
|
||||
|
||||
use crate::task::CanBlock;
|
||||
use std::fmt;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
@@ -80,7 +79,7 @@ impl From<BlockingState> for usize {
|
||||
}
|
||||
|
||||
impl fmt::Debug for BlockingState {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt.debug_struct("BlockingState")
|
||||
.field("is_queued", &self.is_queued())
|
||||
.field("is_allocated", &self.is_allocated())
|
||||
|
||||
@@ -5,13 +5,11 @@ mod state;
|
||||
pub(crate) use self::blocking::{Blocking, CanBlock};
|
||||
use self::blocking_state::BlockingState;
|
||||
use self::state::State;
|
||||
|
||||
use notifier::Notifier;
|
||||
use pool::Pool;
|
||||
|
||||
use crate::notifier::Notifier;
|
||||
use crate::pool::Pool;
|
||||
use futures::executor::{self, Spawn};
|
||||
use futures::{self, Async, Future};
|
||||
|
||||
use log::trace;
|
||||
use std::cell::{Cell, UnsafeCell};
|
||||
use std::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed, Release};
|
||||
use std::sync::atomic::{AtomicPtr, AtomicUsize};
|
||||
@@ -60,7 +58,7 @@ pub(crate) enum Run {
|
||||
Complete,
|
||||
}
|
||||
|
||||
type BoxFuture = Box<Future<Item = (), Error = ()> + Send + 'static>;
|
||||
type BoxFuture = Box<dyn Future<Item = (), Error = ()> + Send + 'static>;
|
||||
|
||||
// ===== impl Task =====
|
||||
|
||||
@@ -299,7 +297,7 @@ impl Task {
|
||||
}
|
||||
|
||||
impl fmt::Debug for Task {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt.debug_struct("Task")
|
||||
.field("state", &self.state)
|
||||
.field("future", &"Spawn<BoxFuture>")
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
use builder::Builder;
|
||||
use pool::Pool;
|
||||
use sender::Sender;
|
||||
use shutdown::{Shutdown, ShutdownTrigger};
|
||||
|
||||
use crate::builder::Builder;
|
||||
use crate::pool::Pool;
|
||||
use crate::sender::Sender;
|
||||
use crate::shutdown::{Shutdown, ShutdownTrigger};
|
||||
use futures::sync::oneshot;
|
||||
use futures::{Future, Poll};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Work-stealing based thread pool for executing futures.
|
||||
@@ -53,12 +51,9 @@ impl ThreadPool {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::ThreadPool;
|
||||
/// use futures::future::{Future, lazy};
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// // Create a thread pool with default configuration values
|
||||
/// let thread_pool = ThreadPool::new();
|
||||
///
|
||||
@@ -69,7 +64,6 @@ impl ThreadPool {
|
||||
///
|
||||
/// // Gracefully shutdown the threadpool
|
||||
/// thread_pool.shutdown().wait().unwrap();
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// # Panics
|
||||
@@ -93,12 +87,9 @@ impl ThreadPool {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate tokio_threadpool;
|
||||
/// # extern crate futures;
|
||||
/// # use tokio_threadpool::ThreadPool;
|
||||
/// use futures::future::{Future, lazy};
|
||||
///
|
||||
/// # pub fn main() {
|
||||
/// // Create a thread pool with default configuration values
|
||||
/// let thread_pool = ThreadPool::new();
|
||||
///
|
||||
@@ -109,7 +100,6 @@ impl ThreadPool {
|
||||
///
|
||||
/// // Gracefully shutdown the threadpool
|
||||
/// thread_pool.shutdown().wait().unwrap();
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// # Panics
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use park::{BoxPark, BoxUnpark};
|
||||
use task::Task;
|
||||
use worker::state::{State, PUSHED_MASK};
|
||||
|
||||
use crate::park::{BoxPark, BoxUnpark};
|
||||
use crate::task::Task;
|
||||
use crate::worker::state::{State, PUSHED_MASK};
|
||||
use crossbeam_deque::{Steal, Stealer, Worker};
|
||||
use crossbeam_queue::SegQueue;
|
||||
use crossbeam_utils::CachePadded;
|
||||
use slab::Slab;
|
||||
use std::cell::UnsafeCell;
|
||||
use std::fmt;
|
||||
use std::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed, Release};
|
||||
@@ -9,11 +12,6 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use crossbeam_deque::{Steal, Stealer, Worker};
|
||||
use crossbeam_queue::SegQueue;
|
||||
use crossbeam_utils::CachePadded;
|
||||
use slab::Slab;
|
||||
|
||||
// TODO: None of the fields should be public
|
||||
//
|
||||
// It would also be helpful to split up the state across what fields /
|
||||
@@ -96,7 +94,7 @@ impl WorkerEntry {
|
||||
/// The `state` must have been obtained with an `Acquire` ordering.
|
||||
#[inline]
|
||||
pub fn notify(&self, mut state: State) -> bool {
|
||||
use worker::Lifecycle::*;
|
||||
use crate::worker::Lifecycle::*;
|
||||
|
||||
loop {
|
||||
let mut next = state;
|
||||
@@ -141,7 +139,7 @@ impl WorkerEntry {
|
||||
///
|
||||
/// Returns `Err` if the worker has already terminated.
|
||||
pub fn signal_stop(&self, mut state: State) {
|
||||
use worker::Lifecycle::*;
|
||||
use crate::worker::Lifecycle::*;
|
||||
|
||||
// Transition the worker state to signaled
|
||||
loop {
|
||||
@@ -317,7 +315,7 @@ impl WorkerEntry {
|
||||
}
|
||||
|
||||
impl fmt::Debug for WorkerEntry {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt.debug_struct("WorkerEntry")
|
||||
.field("state", &self.state.load(Relaxed))
|
||||
.field("next_sleeper", &"UnsafeCell<usize>")
|
||||
|
||||
@@ -6,16 +6,13 @@ pub(crate) use self::entry::WorkerEntry as Entry;
|
||||
pub(crate) use self::stack::Stack;
|
||||
pub(crate) use self::state::{Lifecycle, State};
|
||||
|
||||
use notifier::Notifier;
|
||||
use pool::{self, BackupId, Pool};
|
||||
use sender::Sender;
|
||||
use shutdown::ShutdownTrigger;
|
||||
use task::{self, CanBlock, Task};
|
||||
|
||||
use tokio_executor;
|
||||
|
||||
use crate::notifier::Notifier;
|
||||
use crate::pool::{self, BackupId, Pool};
|
||||
use crate::sender::Sender;
|
||||
use crate::shutdown::ShutdownTrigger;
|
||||
use crate::task::{self, CanBlock, Task};
|
||||
use futures::{Async, Poll};
|
||||
|
||||
use log::trace;
|
||||
use std::cell::Cell;
|
||||
use std::marker::PhantomData;
|
||||
use std::rc::Rc;
|
||||
@@ -23,6 +20,7 @@ use std::sync::atomic::Ordering::{AcqRel, Acquire};
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use tokio_executor;
|
||||
|
||||
/// Thread worker
|
||||
///
|
||||
@@ -150,7 +148,7 @@ impl Worker {
|
||||
}
|
||||
|
||||
/// Transition the current worker to a blocking worker
|
||||
pub(crate) fn transition_to_blocking(&self) -> Poll<(), ::BlockingError> {
|
||||
pub(crate) fn transition_to_blocking(&self) -> Poll<(), crate::BlockingError> {
|
||||
use self::CanBlock::*;
|
||||
|
||||
// If we get this far, then `current_task` has been set.
|
||||
@@ -447,7 +445,7 @@ impl Worker {
|
||||
}
|
||||
|
||||
fn run_task(&self, task: Arc<Task>, notify: &Arc<Notifier>) {
|
||||
use task::Run::*;
|
||||
use crate::task::Run::*;
|
||||
|
||||
// If this is the first time this task is being polled, register it so that we can keep
|
||||
// track of tasks that are in progress.
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use config::MAX_WORKERS;
|
||||
use worker;
|
||||
|
||||
use crate::config::MAX_WORKERS;
|
||||
use crate::worker;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed};
|
||||
use std::{fmt, usize};
|
||||
@@ -242,7 +241,7 @@ impl From<State> for usize {
|
||||
}
|
||||
|
||||
impl fmt::Debug for State {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let head = self.head();
|
||||
|
||||
let mut fmt = fmt.debug_struct("stack::State");
|
||||
|
||||
@@ -93,7 +93,7 @@ impl From<State> for usize {
|
||||
}
|
||||
|
||||
impl fmt::Debug for State {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt.debug_struct("worker::State")
|
||||
.field("lifecycle", &self.lifecycle())
|
||||
.field("is_pushed", &self.is_pushed())
|
||||
|
||||
Reference in New Issue
Block a user