Skip to content

Commit

Permalink
rt: rename internal runtime::Kind to Scheduler (#5017)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
carllerche committed Sep 15, 2022
1 parent 57e08e7 commit 198e2d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions tokio/src/runtime/builder.rs
Expand Up @@ -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())?;
Expand Down Expand Up @@ -869,7 +869,7 @@ impl Builder {
});

Ok(Runtime {
kind: Kind::CurrentThread(scheduler),
scheduler: Scheduler::CurrentThread(scheduler),
handle: Handle { inner },
blocking_pool,
})
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -996,7 +996,7 @@ cfg_rt_multi_thread! {
launch.launch();

Ok(Runtime {
kind: Kind::MultiThread(scheduler),
scheduler: Scheduler::MultiThread(scheduler),
handle,
blocking_pool,
})
Expand Down
20 changes: 10 additions & 10 deletions tokio/src/runtime/mod.rs
Expand Up @@ -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,
Expand All @@ -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),

Expand Down Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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()) {
Expand All @@ -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.
},
Expand Down

0 comments on commit 198e2d8

Please sign in to comment.