From a8037457849fe5d89918f08b7d95ca8fafbc6871 Mon Sep 17 00:00:00 2001 From: Be Date: Sun, 28 Jan 2024 18:55:20 -0600 Subject: [PATCH] move async_executor and job_token modules into new parallel module (#923) to make parallelization related code more organized --- src/lib.rs | 12 +++++------- src/{ => parallel}/async_executor.rs | 4 ++-- src/{job_token.rs => parallel/job_token/mod.rs} | 8 ++++---- src/{ => parallel}/job_token/unix.rs | 0 src/{ => parallel}/job_token/windows.rs | 0 src/parallel/mod.rs | 2 ++ 6 files changed, 13 insertions(+), 13 deletions(-) rename src/{ => parallel}/async_executor.rs (98%) rename src/{job_token.rs => parallel/job_token/mod.rs} (97%) rename src/{ => parallel}/job_token/unix.rs (100%) rename src/{ => parallel}/job_token/windows.rs (100%) create mode 100644 src/parallel/mod.rs diff --git a/src/lib.rs b/src/lib.rs index a555a6469..98af4ff1f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,11 +66,9 @@ use std::process::{Child, Command, Stdio}; use std::sync::{Arc, Mutex}; use std::thread::{self, JoinHandle}; -#[cfg(feature = "parallel")] -mod async_executor; -#[cfg(feature = "parallel")] -mod job_token; mod os_pipe; +#[cfg(feature = "parallel")] +mod parallel; // These modules are all glue to support reading the MSVC version from // the registry and from COM interfaces #[cfg(windows)] @@ -1318,7 +1316,7 @@ impl Build { fn compile_objects(&self, objs: &[Object], print: Option<&PrintThread>) -> Result<(), Error> { use std::cell::Cell; - use async_executor::{block_on, YieldOnce}; + use parallel::async_executor::{block_on, YieldOnce}; if objs.len() <= 1 { for obj in objs { @@ -1330,7 +1328,7 @@ impl Build { } // Limit our parallelism globally with a jobserver. - let tokens = crate::job_token::JobTokenServer::new(); + let tokens = parallel::job_token::JobTokenServer::new(); // When compiling objects in parallel we do a few dirty tricks to speed // things up: @@ -1355,7 +1353,7 @@ impl Build { Command, String, KillOnDrop, - crate::job_token::JobToken, + parallel::job_token::JobToken, )>::new()); let is_disconnected = Cell::new(false); let has_made_progress = Cell::new(false); diff --git a/src/async_executor.rs b/src/parallel/async_executor.rs similarity index 98% rename from src/async_executor.rs rename to src/parallel/async_executor.rs index ad9e62a65..4fbf14639 100644 --- a/src/async_executor.rs +++ b/src/parallel/async_executor.rs @@ -23,7 +23,7 @@ const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new( const NOOP_RAW_WAKER: RawWaker = RawWaker::new(ptr::null(), &NOOP_WAKER_VTABLE); #[derive(Default)] -pub(super) struct YieldOnce(bool); +pub(crate) struct YieldOnce(bool); impl Future for YieldOnce { type Output = (); @@ -44,7 +44,7 @@ impl Future for YieldOnce { /// Here we use our own homebrew async executor since cc is used in the build /// script of many popular projects, pulling in additional dependencies would /// significantly slow down its compilation. -pub(super) fn block_on( +pub(crate) fn block_on( mut fut1: Fut1, mut fut2: Fut2, has_made_progress: &Cell, diff --git a/src/job_token.rs b/src/parallel/job_token/mod.rs similarity index 97% rename from src/job_token.rs rename to src/parallel/job_token/mod.rs index 4b4fa989e..475b8f139 100644 --- a/src/job_token.rs +++ b/src/parallel/job_token/mod.rs @@ -3,14 +3,14 @@ use std::{mem::MaybeUninit, sync::Once}; use crate::Error; #[cfg(unix)] -#[path = "job_token/unix.rs"] +#[path = "unix.rs"] mod sys; #[cfg(windows)] -#[path = "job_token/windows.rs"] +#[path = "windows.rs"] mod sys; -pub(super) struct JobToken(); +pub(crate) struct JobToken(); impl Drop for JobToken { fn drop(&mut self) { @@ -21,7 +21,7 @@ impl Drop for JobToken { } } -pub(super) enum JobTokenServer { +pub(crate) enum JobTokenServer { Inherited(inherited_jobserver::JobServer), InProcess(inprocess_jobserver::JobServer), } diff --git a/src/job_token/unix.rs b/src/parallel/job_token/unix.rs similarity index 100% rename from src/job_token/unix.rs rename to src/parallel/job_token/unix.rs diff --git a/src/job_token/windows.rs b/src/parallel/job_token/windows.rs similarity index 100% rename from src/job_token/windows.rs rename to src/parallel/job_token/windows.rs diff --git a/src/parallel/mod.rs b/src/parallel/mod.rs new file mode 100644 index 000000000..e970fd411 --- /dev/null +++ b/src/parallel/mod.rs @@ -0,0 +1,2 @@ +pub(crate) mod async_executor; +pub(crate) mod job_token;