File tree 7 files changed +82
-10
lines changed 7 files changed +82
-10
lines changed Original file line number Diff line number Diff line change @@ -1183,6 +1183,7 @@ static char *buildorder[] = {
1183
1183
"pkg/go/ast" ,
1184
1184
"pkg/go/parser" ,
1185
1185
"pkg/os/exec" ,
1186
+ "pkg/os/signal" ,
1186
1187
"pkg/net/url" ,
1187
1188
"pkg/text/template/parse" ,
1188
1189
"pkg/text/template" ,
Original file line number Diff line number Diff line change @@ -548,7 +548,6 @@ func (b *builder) do(root *action) {
548
548
}
549
549
550
550
b .readySema = make (chan bool , len (all ))
551
- done := make (chan bool )
552
551
553
552
// Initialize per-action execution state.
554
553
for _ , a := range all {
@@ -596,10 +595,11 @@ func (b *builder) do(root *action) {
596
595
597
596
if a == root {
598
597
close (b .readySema )
599
- done <- true
600
598
}
601
599
}
602
600
601
+ var wg sync.WaitGroup
602
+
603
603
// Kick off goroutines according to parallelism.
604
604
// If we are using the -n flag (just printing commands)
605
605
// drop the parallelism to 1, both to make the output
@@ -609,19 +609,30 @@ func (b *builder) do(root *action) {
609
609
par = 1
610
610
}
611
611
for i := 0 ; i < par ; i ++ {
612
+ wg .Add (1 )
612
613
go func () {
613
- for _ = range b .readySema {
614
- // Receiving a value from b.sema entitles
615
- // us to take from the ready queue.
616
- b .exec .Lock ()
617
- a := b .ready .pop ()
618
- b .exec .Unlock ()
619
- handle (a )
614
+ defer wg .Done ()
615
+ for {
616
+ select {
617
+ case _ , ok := <- b .readySema :
618
+ if ! ok {
619
+ return
620
+ }
621
+ // Receiving a value from b.readySema entitles
622
+ // us to take from the ready queue.
623
+ b .exec .Lock ()
624
+ a := b .ready .pop ()
625
+ b .exec .Unlock ()
626
+ handle (a )
627
+ case <- interrupted :
628
+ setExitStatus (1 )
629
+ return
630
+ }
620
631
}
621
632
}()
622
633
}
623
634
624
- <- done
635
+ wg . Wait ()
625
636
}
626
637
627
638
// build is the action for building a single package or command.
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ func runStdin(cmdargs ...interface{}) {
84
84
cmd .Stdin = os .Stdin
85
85
cmd .Stdout = os .Stdout
86
86
cmd .Stderr = os .Stderr
87
+ startSigHandlers ()
87
88
if err := cmd .Run (); err != nil {
88
89
errorf ("%v" , err )
89
90
}
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package main
6
+
7
+ import (
8
+ "os"
9
+ "os/signal"
10
+ "sync"
11
+ )
12
+
13
+ // interrupted is closed, if go process is interrupted.
14
+ var interrupted = make (chan struct {})
15
+
16
+ // processSignals setups signal handler.
17
+ func processSignals () {
18
+ sig := make (chan os.Signal )
19
+ signal .Notify (sig , signalsToIgnore ... )
20
+ go func () {
21
+ <- sig
22
+ close (interrupted )
23
+ }()
24
+ }
25
+
26
+ var onceProcessSignals sync.Once
27
+
28
+ // startSigHandlers start signal handlers.
29
+ func startSigHandlers () {
30
+ onceProcessSignals .Do (processSignals )
31
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ // +build plan9 windows
6
+
7
+ package main
8
+
9
+ import (
10
+ "os"
11
+ )
12
+
13
+ var signalsToIgnore = []os.Signal {os .Interrupt }
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ // +build darwin freebsd linux netbsd openbsd
6
+
7
+ package main
8
+
9
+ import (
10
+ "os"
11
+ "syscall"
12
+ )
13
+
14
+ var signalsToIgnore = []os.Signal {os .Interrupt , syscall .SIGQUIT }
Original file line number Diff line number Diff line change @@ -644,6 +644,7 @@ func (b *builder) runTest(a *action) error {
644
644
// running.
645
645
tick := time .NewTimer (testKillTimeout )
646
646
if err == nil {
647
+ startSigHandlers ()
647
648
done := make (chan error )
648
649
go func () {
649
650
done <- cmd .Wait ()
You can’t perform that action at this time.
0 commit comments