Skip to content

Commit

Permalink
rt: move Runtime into its own file (#5159)
Browse files Browse the repository at this point in the history
This removes the `Runtime` implementation from a cfg macro so it can be
formatted.
  • Loading branch information
carllerche committed Nov 2, 2022
1 parent 467adec commit 26791a6
Show file tree
Hide file tree
Showing 5 changed files with 445 additions and 426 deletions.
1 change: 1 addition & 0 deletions tokio/src/lib.rs
@@ -1,6 +1,7 @@
#![allow(
clippy::cognitive_complexity,
clippy::large_enum_variant,
clippy::module_inception,
clippy::needless_doctest_main
)]
#![warn(
Expand Down
22 changes: 10 additions & 12 deletions tokio/src/runtime/builder.rs
Expand Up @@ -872,7 +872,7 @@ impl Builder {

fn build_current_thread_runtime(&mut self) -> io::Result<Runtime> {
use crate::runtime::scheduler::{self, CurrentThread};
use crate::runtime::{Config, Scheduler};
use crate::runtime::{runtime::Scheduler, Config};

let (driver, driver_handle) = driver::Driver::new(self.get_cfg())?;

Expand Down Expand Up @@ -905,13 +905,15 @@ impl Builder {
},
);

let handle = scheduler::Handle::CurrentThread(scheduler.handle().clone());
let handle = Handle {
inner: scheduler::Handle::CurrentThread(scheduler.handle().clone()),
};

Ok(Runtime {
scheduler: Scheduler::CurrentThread(scheduler),
handle: Handle { inner: handle },
Ok(Runtime::from_parts(
Scheduler::CurrentThread(scheduler),
handle,
blocking_pool,
})
))
}
}

Expand Down Expand Up @@ -991,7 +993,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, Scheduler};
use crate::runtime::{Config, runtime::Scheduler};
use crate::runtime::scheduler::{self, MultiThread};

let core_threads = self.worker_threads.unwrap_or_else(num_cpus);
Expand Down Expand Up @@ -1032,11 +1034,7 @@ cfg_rt_multi_thread! {
let _enter = handle.enter();
launch.launch();

Ok(Runtime {
scheduler: Scheduler::MultiThread(scheduler),
handle,
blocking_pool,
})
Ok(Runtime::from_parts(Scheduler::MultiThread(scheduler), handle, blocking_pool))
}
}
}
Expand Down

0 comments on commit 26791a6

Please sign in to comment.