Skip to content

Commit 6868364

Browse files
committed
Add semaphore
1 parent f2b0f9d commit 6868364

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ use anyhow::{Result, anyhow};
1717
use auto_hash_map::AutoMap;
1818
use rustc_hash::FxHasher;
1919
use serde::{Deserialize, Serialize};
20-
use tokio::{runtime::Handle, select, sync::mpsc::Receiver, task_local};
20+
use tokio::{
21+
runtime::Handle,
22+
select,
23+
sync::{Semaphore, mpsc::Receiver},
24+
task_local,
25+
};
2126
use tokio_util::task::TaskTracker;
2227
use tracing::{Instrument, Level, Span, info_span, instrument, trace_span};
2328
use turbo_tasks_malloc::TurboMalloc;
@@ -386,6 +391,8 @@ pub struct TurboTasks<B: Backend + 'static> {
386391
event_background: Event,
387392
program_start: Instant,
388393
compilation_events: CompilationEventQueue,
394+
395+
semaphore: Semaphore,
389396
}
390397

391398
/// Information about a non-local task. A non-local task can contain multiple "local" tasks, which
@@ -479,6 +486,8 @@ task_local! {
479486
static CURRENT_TASK_STATE: Arc<RwLock<CurrentTaskState>>;
480487
}
481488

489+
const MAX_TASK_COUNT: usize = 1024 * 1024 * 256;
490+
482491
impl<B: Backend + 'static> TurboTasks<B> {
483492
// TODO better lifetime management for turbo tasks
484493
// consider using unsafe for the task_local turbo tasks
@@ -512,6 +521,7 @@ impl<B: Backend + 'static> TurboTasks<B> {
512521
event_background: Event::new(|| "TurboTasks::event_background".to_string()),
513522
program_start: Instant::now(),
514523
compilation_events: CompilationEventQueue::default(),
524+
semaphore: Semaphore::new(MAX_TASK_COUNT),
515525
});
516526
this.backend.startup(&*this);
517527
this

0 commit comments

Comments
 (0)