summaryrefslogtreecommitdiff
path: root/oryxc/src/compiler.rs
diff options
context:
space:
mode:
Diffstat (limited to 'oryxc/src/compiler.rs')
-rw-r--r--oryxc/src/compiler.rs26
1 files changed, 15 insertions, 11 deletions
diff --git a/oryxc/src/compiler.rs b/oryxc/src/compiler.rs
index e81da63..8bad9bd 100644
--- a/oryxc/src/compiler.rs
+++ b/oryxc/src/compiler.rs
@@ -6,7 +6,7 @@ use std::io::{
};
use std::sync::atomic::{
AtomicU32,
- AtomicUsize,
+ AtomicUsize,
Ordering,
};
use std::sync::{
@@ -105,8 +105,9 @@ pub enum JobType {
},
}
+mkidtype!(JobId);
pub struct Job {
- id: u32,
+ id: JobId,
kind: JobType,
}
@@ -147,7 +148,7 @@ impl<'a> CompilerState<'a> {
/// Build a new job of type KIND.
#[inline(always)]
fn job_new(&self, kind: JobType) -> Job {
- let id = self.genid();
+ let id = JobId(self.genid());
return Job { id, kind };
}
@@ -166,6 +167,15 @@ impl<'a> CompilerState<'a> {
fn job_complete(&self) -> usize {
return self.njobs.fetch_sub(1, Ordering::Release) - 1;
}
+
+ /// Push all jobs that depend on JOB to QUEUE, clearing the dep list.
+ fn job_push_deps(&self, job: JobId, queue: &Worker<Job>) {
+ if let Some((_, deps)) = self.deps.remove(&(job.0 as usize)) {
+ for x in deps {
+ self.job_push(&queue, x);
+ }
+ }
+ }
}
/// Initialize compiler state and drive all source files through the
@@ -188,7 +198,7 @@ where
);
files.push(Arc::clone(&fdata));
initial_jobs.push(Job {
- id: i as u32,
+ id: JobId(i as u32),
kind: JobType::Lex { file: id, fdata },
});
}
@@ -440,13 +450,7 @@ fn worker_loop(
ok = false;
}
- let jid = job.id as usize;
- if let Some((_, deps)) = c_state.deps.remove(&jid) {
- for j in deps {
- c_state.job_push(&queue, j);
- }
- }
-
+ c_state.job_push_deps(job.id, &queue);
if c_state.job_complete() == 0 {
c_state.wake_all();
return ok;