From 198e2d8e794c62e1f1d5581e0cc13ff524570191 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 15 Sep 2022 15:10:08 -0700 Subject: [PATCH] rt: rename internal `runtime::Kind` to `Scheduler` (#5017) The `runtime::Kind` enum doesn't really represent the runtime flavor, but is an enumeration of the different scheduler types. This patch renames the enum to reflect this. At a later time, it is likely the `Scheduler` enum will be moved to `tokio::runtime::scheduler`, but that is punted to a later PR. This rename is to make space for other enums --- tokio/src/runtime/builder.rs | 8 ++++---- tokio/src/runtime/mod.rs | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tokio/src/runtime/builder.rs b/tokio/src/runtime/builder.rs index 00588786eea..45f40033782 100644 --- a/tokio/src/runtime/builder.rs +++ b/tokio/src/runtime/builder.rs @@ -832,7 +832,7 @@ impl Builder { } fn build_current_thread_runtime(&mut self) -> io::Result { - use crate::runtime::{Config, CurrentThread, HandleInner, Kind}; + use crate::runtime::{Config, CurrentThread, HandleInner, Scheduler}; use std::sync::Arc; let (driver, resources) = driver::Driver::new(self.get_cfg())?; @@ -869,7 +869,7 @@ impl Builder { }); Ok(Runtime { - kind: Kind::CurrentThread(scheduler), + scheduler: Scheduler::CurrentThread(scheduler), handle: Handle { inner }, blocking_pool, }) @@ -952,7 +952,7 @@ cfg_rt_multi_thread! { impl Builder { fn build_threaded_runtime(&mut self) -> io::Result { use crate::loom::sys::num_cpus; - use crate::runtime::{Config, HandleInner, Kind, MultiThread}; + use crate::runtime::{Config, HandleInner, Scheduler, MultiThread}; use std::sync::Arc; let core_threads = self.worker_threads.unwrap_or_else(num_cpus); @@ -996,7 +996,7 @@ cfg_rt_multi_thread! { launch.launch(); Ok(Runtime { - kind: Kind::MultiThread(scheduler), + scheduler: Scheduler::MultiThread(scheduler), handle, blocking_pool, }) diff --git a/tokio/src/runtime/mod.rs b/tokio/src/runtime/mod.rs index 96d6a3b8ac9..5bd0a9b66d2 100644 --- a/tokio/src/runtime/mod.rs +++ b/tokio/src/runtime/mod.rs @@ -297,8 +297,8 @@ cfg_rt! { /// [`Builder`]: struct@Builder #[derive(Debug)] pub struct Runtime { - /// Task executor - kind: Kind, + /// Task scheduler + scheduler: Scheduler, /// Handle to runtime, also contains driver handles handle: Handle, @@ -307,9 +307,9 @@ cfg_rt! { blocking_pool: BlockingPool, } - /// The runtime executor is either a multi-thread or a current-thread executor. + /// The runtime scheduler is either a multi-thread or a current-thread executor. #[derive(Debug)] - enum Kind { + enum Scheduler { /// Execute all tasks on the current-thread. CurrentThread(CurrentThread), @@ -491,10 +491,10 @@ cfg_rt! { let _enter = self.enter(); - match &self.kind { - Kind::CurrentThread(exec) => exec.block_on(future), + match &self.scheduler { + Scheduler::CurrentThread(exec) => exec.block_on(future), #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] - Kind::MultiThread(exec) => exec.block_on(future), + Scheduler::MultiThread(exec) => exec.block_on(future), } } @@ -609,8 +609,8 @@ cfg_rt! { #[allow(clippy::single_match)] // there are comments in the error branch, so we don't want if-let impl Drop for Runtime { fn drop(&mut self) { - match &mut self.kind { - Kind::CurrentThread(current_thread) => { + match &mut self.scheduler { + Scheduler::CurrentThread(current_thread) => { // This ensures that tasks spawned on the current-thread // runtime are dropped inside the runtime's context. match self::context::try_enter(self.handle.clone()) { @@ -624,7 +624,7 @@ cfg_rt! { } }, #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] - Kind::MultiThread(_) => { + Scheduler::MultiThread(_) => { // The threaded scheduler drops its tasks on its worker threads, which is // already in the runtime's context. },