mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-28 00:00:11 +02:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user