threadpool: refactor pool shutdown (#769)

This commit is contained in:
Stjepan Glavina
2018-11-20 21:43:23 +01:00
committed by GitHub
parent 9c037044c4
commit 3235749006
7 changed files with 162 additions and 127 deletions
+11 -1
View File
@@ -14,6 +14,7 @@ pub(crate) use self::state::{
use pool::{self, Pool, BackupId};
use notifier::Notifier;
use sender::Sender;
use shutdown::ShutdownTrigger;
use task::{self, Task, CanBlock};
use tokio_executor;
@@ -60,6 +61,9 @@ pub struct Worker {
// Set when the worker should finalize on drop
should_finalize: Cell<bool>,
// Completes the shutdown process when the `ThreadPool` and all `Worker`s get dropped.
trigger: Arc<ShutdownTrigger>,
// Keep the value on the current thread.
_p: PhantomData<Rc<()>>,
}
@@ -86,7 +90,12 @@ pub struct WorkerId(pub(crate) usize);
thread_local!(static CURRENT_WORKER: Cell<*const Worker> = Cell::new(0 as *const _));
impl Worker {
pub(crate) fn new(id: WorkerId, backup_id: BackupId, pool: Arc<Pool>) -> Worker {
pub(crate) fn new(
id: WorkerId,
backup_id: BackupId,
pool: Arc<Pool>,
trigger: Arc<ShutdownTrigger>,
) -> Worker {
Worker {
pool,
id,
@@ -94,6 +103,7 @@ impl Worker {
current_task: CurrentTask::new(),
is_blocking: Cell::new(false),
should_finalize: Cell::new(false),
trigger,
_p: PhantomData,
}
}