Split tokio-threadpool lib.rs into files (#233)

* Builder -> src/builder.rs
* Callback -> src/callback.rs
* Config -> src/config.rs
* Futures2Wake -> src/futures2_wake.rs
* Inner -> src/inner.rs
* Notifier-> src/notifier.rs
* Sender -> src/sender.rs
* Shutdown -> src/shutdown.rs
* ShutdownTask -> src/shutdown_task.rs
* SleepStack -> src/sleep_stack.rs
* State -> src/state.rs
* ThreadPool -> src/thread_pool.rs
* Worker -> src/worker.rs
* WorkerEntry -> src/worker_entry.rs
* WorkerState -> src/worker_state.rs
This commit is contained in:
Roman
2018-03-27 15:56:21 -07:00
committed by Carl Lerche
parent a612736f54
commit ad189826f4
17 changed files with 2374 additions and 2257 deletions
+55
View File
@@ -0,0 +1,55 @@
use inner::Inner;
use task::Task;
use std::mem;
use std::sync::Weak;
use futures::executor::Notify;
/// Implements the future `Notify` API.
///
/// This is how external events are able to signal the task, informing it to try
/// to poll the future again.
#[derive(Debug)]
pub(crate) struct Notifier {
pub inner: Weak<Inner>,
}
impl Notify for Notifier {
fn notify(&self, id: usize) {
trace!("Notifier::notify; id=0x{:x}", id);
let id = id as usize;
let task = unsafe { Task::from_notify_id_ref(&id) };
if !task.schedule() {
trace!(" -> task already scheduled");
// task is already scheduled, there is nothing more to do
return;
}
// TODO: Check if the pool is still running
// Bump the ref count
let task = task.clone();
if let Some(inner) = self.inner.upgrade() {
let _ = inner.submit(task, &inner);
}
}
fn clone_id(&self, id: usize) -> usize {
unsafe {
let handle = Task::from_notify_id_ref(&id);
mem::forget(handle.clone());
}
id
}
fn drop_id(&self, id: usize) {
unsafe {
let _ = Task::from_notify_id(id);
}
}
}