// TODO: This is to avoid triggering "dead code" warnings many other places // in the codebase. Remove this during a later cleanup #[cfg(not(feature = "rt"))] #[allow(dead_code)]
Disabled,
}
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", feature = "time"))] /// Returns true if both handles belong to the same runtime instance. pub(crate) fn is_same_runtime(&self, other: &Handle) -> bool { match (self, other) {
(Handle::CurrentThread(a), Handle::CurrentThread(b)) => Arc::ptr_eq(a, b), #[cfg(feature = "rt-multi-thread")]
(Handle::MultiThread(a), Handle::MultiThread(b)) => Arc::ptr_eq(a, b), #[cfg(feature = "rt-multi-thread")]
_ => false, // different runtime types
}
}
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", feature = "time"))] /// Returns true if the runtime is shutting down. pub(crate) fn is_shutdown(&self) -> bool { matchself {
Handle::CurrentThread(_) => panic!("the alternative timer implementation is not supported on CurrentThread runtime"),
Handle::MultiThread(h) => h.is_shutdown(),
}
}
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", feature = "time"))] /// Push a timer entry that was created outside of this runtime /// into the runtime-global queue. The pushed timer will be /// processed by a random worker thread. pub(crate) fn push_remote_timer(&self, entry_hdl: crate::runtime::time_alt::EntryHandle) { matchself {
Handle::CurrentThread(_) => panic!("the alternative timer implementation is not supported on CurrentThread runtime"),
Handle::MultiThread(h) => h.push_remote_timer(entry_hdl),
}
}
/// Returns true if this is a local runtime and the runtime is owned by the current thread. pub(crate) fn can_spawn_local_on_local_runtime(&self) -> bool { matchself {
Handle::CurrentThread(h) => h.local_tid.map(|x| std::thread::current().id() == x).unwrap_or(false),
/// Spawn a local task /// /// # Safety /// /// This should only be called in `LocalRuntime` if the runtime has been verified to be owned /// by the current thread. #[allow(irrefutable_let_patterns)] #[track_caller] pub(crate) unsafefn spawn_local<F>(&self, future: F, id: Id, spawned_at: SpawnLocation) -> JoinHandle<F::Output> where
F: Future + 'static,
F::Output: 'static,
{ iflet Handle::CurrentThread(h) = self { // Safety: caller guarantees that this is a `LocalRuntime`. unsafe { current_thread::Handle::spawn_local(h, future, id, spawned_at) }
} else {
panic!("Only current_thread and LocalSet have spawn_local internals implemented")
}
}
pub(crate) fn shutdown(&self) { match *self {
Handle::CurrentThread(_) => {},
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.