rt: remove internal runtime::ToHandle trait (#5002)

The internal `runtime::ToHandle` trait is no longer needed as the
runtime handle is used everywhere now.
This commit is contained in:
Carl Lerche
2022-09-12 16:18:17 -07:00
committed by GitHub
parent 1c823093cb
commit 3a4f18b93b
4 changed files with 8 additions and 32 deletions
+7 -7
View File
@@ -7,7 +7,7 @@ use crate::runtime::blocking::{shutdown, BlockingTask};
use crate::runtime::builder::ThreadNameFn;
use crate::runtime::context;
use crate::runtime::task::{self, JoinHandle};
use crate::runtime::{Builder, Callback, ToHandle};
use crate::runtime::{Builder, Callback, Handle};
use std::collections::{HashMap, VecDeque};
use std::fmt;
@@ -242,7 +242,7 @@ impl fmt::Debug for BlockingPool {
impl Spawner {
#[track_caller]
pub(crate) fn spawn_blocking<F, R>(&self, rt: &dyn ToHandle, func: F) -> JoinHandle<R>
pub(crate) fn spawn_blocking<F, R>(&self, rt: &Handle, func: F) -> JoinHandle<R>
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
@@ -270,7 +270,7 @@ impl Spawner {
all(loom, not(test)), // the function is covered by loom tests
test
), allow(dead_code))]
pub(crate) fn spawn_mandatory_blocking<F, R>(&self, rt: &dyn ToHandle, func: F) -> Option<JoinHandle<R>>
pub(crate) fn spawn_mandatory_blocking<F, R>(&self, rt: &Handle, func: F) -> Option<JoinHandle<R>>
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
@@ -305,7 +305,7 @@ impl Spawner {
func: F,
is_mandatory: Mandatory,
name: Option<&str>,
rt: &dyn ToHandle,
rt: &Handle,
) -> (JoinHandle<R>, Result<(), SpawnError>)
where
F: FnOnce() -> R + Send + 'static,
@@ -337,7 +337,7 @@ impl Spawner {
(handle, spawned)
}
fn spawn_task(&self, task: Task, rt: &dyn ToHandle) -> Result<(), SpawnError> {
fn spawn_task(&self, task: Task, rt: &Handle) -> Result<(), SpawnError> {
let mut shared = self.inner.shared.lock();
if shared.shutdown {
@@ -400,7 +400,7 @@ impl Spawner {
fn spawn_thread(
&self,
shutdown_tx: shutdown::Sender,
rt: &dyn ToHandle,
rt: &Handle,
id: usize,
) -> std::io::Result<thread::JoinHandle<()>> {
let mut builder = thread::Builder::new().name((self.inner.thread_name)());
@@ -409,7 +409,7 @@ impl Spawner {
builder = builder.stack_size(stack_size);
}
let rt = rt.to_handle();
let rt = rt.clone();
builder.spawn(move || {
// Only the reference should be moved into the closure
-11
View File
@@ -54,11 +54,6 @@ pub(crate) struct HandleInner {
pub(crate) blocking_spawner: blocking::Spawner,
}
/// Create a new runtime handle.
pub(crate) trait ToHandle {
fn to_handle(&self) -> Handle;
}
/// Runtime context guard.
///
/// Returned by [`Runtime::enter`] and [`Handle::enter`], the context guard exits
@@ -319,12 +314,6 @@ impl Handle {
}
}
impl ToHandle for Handle {
fn to_handle(&self) -> Handle {
self.clone()
}
}
cfg_metrics! {
use crate::runtime::RuntimeMetrics;
+1 -1
View File
@@ -222,7 +222,7 @@ cfg_rt! {
mod handle;
pub use handle::{EnterGuard, Handle, TryCurrentError};
pub(crate) use handle::{HandleInner, ToHandle};
pub(crate) use handle::HandleInner;
mod spawner;
use self::spawner::Spawner;
@@ -854,19 +854,6 @@ impl Shared {
}
}
impl crate::runtime::ToHandle for Arc<Shared> {
fn to_handle(&self) -> crate::runtime::Handle {
use crate::runtime::scheduler::multi_thread::Spawner;
use crate::runtime::{self, Handle};
Handle {
spawner: runtime::Spawner::MultiThread(Spawner {
shared: self.clone(),
}),
}
}
}
cfg_metrics! {
impl Shared {
pub(super) fn injection_queue_depth(&self) -> usize {