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
This commit is contained in:
Carl Lerche
2022-09-15 15:10:08 -07:00
committed by GitHub
parent 57e08e7147
commit 198e2d8e79
2 changed files with 14 additions and 14 deletions
+4 -4
View File
@@ -832,7 +832,7 @@ impl Builder {
}
fn build_current_thread_runtime(&mut self) -> io::Result<Runtime> {
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<Runtime> {
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,
})
+10 -10
View File
@@ -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.
},