forked from libre-chip/fayalite
fix JobGraph::run to not busy-wait
This commit is contained in:
parent
0b82178740
commit
0be9f9ce23
1 changed files with 9 additions and 1 deletions
|
|
@ -703,8 +703,12 @@ impl JobGraph {
|
|||
}
|
||||
let mut running_jobs = HashMap::default();
|
||||
let (finished_jobs_sender, finished_jobs_receiver) = mpsc::channel();
|
||||
let mut next_finished_job = None;
|
||||
loop {
|
||||
while let Some(finished_job) = finished_jobs_receiver.try_recv().ok() {
|
||||
if let Some(finished_job) = next_finished_job
|
||||
.take()
|
||||
.or_else(|| finished_jobs_receiver.try_recv().ok())
|
||||
{
|
||||
let Some(RunningJob { job, thread }) = running_jobs.remove(&finished_job)
|
||||
else {
|
||||
unreachable!();
|
||||
|
|
@ -736,6 +740,7 @@ impl JobGraph {
|
|||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if let Some(WaitingJobState {
|
||||
job_node_id,
|
||||
|
|
@ -791,12 +796,15 @@ impl JobGraph {
|
|||
.expect("failed to spawn thread for job"),
|
||||
},
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if running_jobs.is_empty() {
|
||||
assert!(item_name_to_waiting_jobs_map.is_empty());
|
||||
assert!(ready_jobs.is_empty());
|
||||
return Ok(());
|
||||
}
|
||||
// nothing to do yet, block to avoid busy waiting
|
||||
next_finished_job = finished_jobs_receiver.recv().ok();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue