Skip to content

Commit

Permalink
move async_executor and job_token modules into new parallel module (#923
Browse files Browse the repository at this point in the history
)

to make parallelization related code more organized
  • Loading branch information
Be-ing authored Jan 29, 2024
1 parent 4d36cfa commit a803745
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
12 changes: 5 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 {
Expand All @@ -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:
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/async_executor.rs → src/parallel/async_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ();
Expand All @@ -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<Fut1, Fut2>(
pub(crate) fn block_on<Fut1, Fut2>(
mut fut1: Fut1,
mut fut2: Fut2,
has_made_progress: &Cell<bool>,
Expand Down
8 changes: 4 additions & 4 deletions src/job_token.rs → src/parallel/job_token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -21,7 +21,7 @@ impl Drop for JobToken {
}
}

pub(super) enum JobTokenServer {
pub(crate) enum JobTokenServer {
Inherited(inherited_jobserver::JobServer),
InProcess(inprocess_jobserver::JobServer),
}
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions src/parallel/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub(crate) mod async_executor;
pub(crate) mod job_token;

0 comments on commit a803745

Please sign in to comment.