@@ -17,14 +17,6 @@ import (
17
17
// concurrency or performance issues.
18
18
const jobRunnerDebug = false
19
19
20
- type jobState uint8
21
-
22
- const (
23
- jobStateQueued jobState = iota // not yet running
24
- jobStateRunning // running
25
- jobStateFinished // finished running
26
- )
27
-
28
20
// compileJob is a single compiler job, comparable to a single Makefile target.
29
21
// It is used to orchestrate various compiler tasks that can be run in parallel
30
22
// but that have dependencies and thus have limitations in how they can be run.
@@ -55,12 +47,11 @@ func dummyCompileJob(result string) *compileJob {
55
47
// ordered as such in the job dependencies.
56
48
func runJobs (job * compileJob , sema chan struct {}) error {
57
49
if sema == nil {
58
- // Have a default, if the semaphore isn't set. This is useful for
59
- // tests.
50
+ // Have a default, if the semaphore isn't set. This is useful for tests.
60
51
sema = make (chan struct {}, runtime .NumCPU ())
61
52
}
62
53
if cap (sema ) == 0 {
63
- return errors .New ("cannot 0 jobs at a time" )
54
+ return errors .New ("cannot run 0 jobs at a time" )
64
55
}
65
56
66
57
// Create a slice of jobs to run, where all dependencies are run in order.
@@ -81,10 +72,10 @@ func runJobs(job *compileJob, sema chan struct{}) error {
81
72
82
73
waiting := make (map [* compileJob ]map [* compileJob ]struct {}, len (jobs ))
83
74
dependents := make (map [* compileJob ][]* compileJob , len (jobs ))
84
- jidx := make (map [* compileJob ]int )
75
+ compileJobs := make (map [* compileJob ]int )
85
76
var ready intHeap
86
77
for i , job := range jobs {
87
- jidx [job ] = i
78
+ compileJobs [job ] = i
88
79
if len (job .dependencies ) == 0 {
89
80
// This job is ready to run.
90
81
ready .Push (i )
@@ -105,8 +96,7 @@ func runJobs(job *compileJob, sema chan struct{}) error {
105
96
// Create a channel to accept notifications of completion.
106
97
doneChan := make (chan * compileJob )
107
98
108
- // Send each job in the jobs slice to a worker, taking care of job
109
- // dependencies.
99
+ // Send each job in the jobs slice to a worker, taking care of job dependencies.
110
100
numRunningJobs := 0
111
101
var totalTime time.Duration
112
102
start := time .Now ()
@@ -156,7 +146,7 @@ func runJobs(job *compileJob, sema chan struct{}) error {
156
146
delete (wait , completed )
157
147
if len (wait ) == 0 {
158
148
// This job is now ready to run.
159
- ready .Push (jidx [j ])
149
+ ready .Push (compileJobs [j ])
160
150
delete (waiting , j )
161
151
}
162
152
}
0 commit comments