Skip to content

Commit 99b47d1

Browse files
committed
Turbopack: add parallel execution helpers
1 parent 0339574 commit 99b47d1

File tree

5 files changed

+733
-56
lines changed

5 files changed

+733
-56
lines changed

turbopack/crates/turbo-tasks/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#![feature(never_type)]
3838
#![feature(downcast_unchecked)]
3939
#![feature(ptr_metadata)]
40+
#![feature(sync_unsafe_cell)]
41+
#![feature(vec_into_raw_parts)]
4042

4143
pub mod backend;
4244
mod capture_future;
@@ -64,13 +66,14 @@ mod no_move_vec;
6466
mod once_map;
6567
mod output;
6668
pub mod panic_hooks;
69+
pub mod parallel;
6770
pub mod persisted_graph;
6871
pub mod primitives;
6972
mod raw_vc;
7073
mod read_options;
7174
mod read_ref;
7275
pub mod registry;
73-
mod scope;
76+
pub mod scope;
7477
mod serialization_invalidation;
7578
pub mod small_duration;
7679
mod spawn;
@@ -115,7 +118,6 @@ pub use raw_vc::{CellId, RawVc, ReadRawVcFuture, ResolveTypeError};
115118
pub use read_options::ReadCellOptions;
116119
pub use read_ref::ReadRef;
117120
use rustc_hash::FxHasher;
118-
pub use scope::scope;
119121
pub use serialization_invalidation::SerializationInvalidator;
120122
pub use shrink_to_fit::ShrinkToFit;
121123
pub use spawn::{JoinHandle, spawn, spawn_blocking, spawn_thread};

turbopack/crates/turbo-tasks/src/manager.rs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,27 +1058,30 @@ impl<B: Backend + 'static> TurboTasks<B> {
10581058
}
10591059

10601060
pub async fn stop_and_wait(&self) {
1061-
self.backend.stopping(self);
1062-
self.stopped.store(true, Ordering::Release);
1063-
{
1064-
let listener = self
1065-
.event
1066-
.listen_with_note(|| || "wait for stop".to_string());
1067-
if self.currently_scheduled_tasks.load(Ordering::Acquire) != 0 {
1068-
listener.await;
1061+
turbo_tasks_future_scope(self.pin(), async move {
1062+
self.backend.stopping(self);
1063+
self.stopped.store(true, Ordering::Release);
1064+
{
1065+
let listener = self
1066+
.event
1067+
.listen_with_note(|| || "wait for stop".to_string());
1068+
if self.currently_scheduled_tasks.load(Ordering::Acquire) != 0 {
1069+
listener.await;
1070+
}
10691071
}
1070-
}
1071-
{
1072-
let listener = self.event_background.listen();
1073-
if self
1074-
.currently_scheduled_background_jobs
1075-
.load(Ordering::Acquire)
1076-
!= 0
10771072
{
1078-
listener.await;
1073+
let listener = self.event_background.listen();
1074+
if self
1075+
.currently_scheduled_background_jobs
1076+
.load(Ordering::Acquire)
1077+
!= 0
1078+
{
1079+
listener.await;
1080+
}
10791081
}
1080-
}
1081-
self.backend.stop(self);
1082+
self.backend.stop(self);
1083+
})
1084+
.await;
10821085
}
10831086

10841087
#[track_caller]
@@ -1675,6 +1678,10 @@ pub fn turbo_tasks() -> Arc<dyn TurboTasksApi> {
16751678
TURBO_TASKS.with(|arc| arc.clone())
16761679
}
16771680

1681+
pub fn try_turbo_tasks() -> Option<Arc<dyn TurboTasksApi>> {
1682+
TURBO_TASKS.try_with(|arc| arc.clone()).ok()
1683+
}
1684+
16781685
pub fn with_turbo_tasks<T>(func: impl FnOnce(&Arc<dyn TurboTasksApi>) -> T) -> T {
16791686
TURBO_TASKS.with(|arc| func(arc))
16801687
}

0 commit comments

Comments
 (0)