Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(861)

Side by Side Diff: src/cmd/go/build.go

Issue 6943043: cmd/go: unblock all workers on signal (Closed)
Patch Set: diff -r 3fe40a41018d https://code.google.com/p/go Created 11 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/cmd/go/signal.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "container/heap" 9 "container/heap"
10 "errors" 10 "errors"
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 // results as soon as possible. The priorities assigned 541 // results as soon as possible. The priorities assigned
542 // ensure that, all else being equal, the execution prefers 542 // ensure that, all else being equal, the execution prefers
543 // to do what it would have done first in a simple depth-first 543 // to do what it would have done first in a simple depth-first
544 // dependency order traversal. 544 // dependency order traversal.
545 all := actionList(root) 545 all := actionList(root)
546 for i, a := range all { 546 for i, a := range all {
547 a.priority = i 547 a.priority = i
548 } 548 }
549 549
550 b.readySema = make(chan bool, len(all)) 550 b.readySema = make(chan bool, len(all))
551 done := make(chan bool)
552 551
553 // Initialize per-action execution state. 552 // Initialize per-action execution state.
554 for _, a := range all { 553 for _, a := range all {
555 for _, a1 := range a.deps { 554 for _, a1 := range a.deps {
556 a1.triggers = append(a1.triggers, a) 555 a1.triggers = append(a1.triggers, a)
557 } 556 }
558 a.pending = len(a.deps) 557 a.pending = len(a.deps)
559 if a.pending == 0 { 558 if a.pending == 0 {
560 b.ready.push(a) 559 b.ready.push(a)
561 b.readySema <- true 560 b.readySema <- true
(...skipping 27 matching lines...) Expand all
589 a0.failed = true 588 a0.failed = true
590 } 589 }
591 if a0.pending--; a0.pending == 0 { 590 if a0.pending--; a0.pending == 0 {
592 b.ready.push(a0) 591 b.ready.push(a0)
593 b.readySema <- true 592 b.readySema <- true
594 } 593 }
595 } 594 }
596 595
597 if a == root { 596 if a == root {
598 close(b.readySema) 597 close(b.readySema)
599 done <- true
600 } 598 }
601 } 599 }
602 600
601 var wg sync.WaitGroup
602
603 // Kick off goroutines according to parallelism. 603 // Kick off goroutines according to parallelism.
604 // If we are using the -n flag (just printing commands) 604 // If we are using the -n flag (just printing commands)
605 // drop the parallelism to 1, both to make the output 605 // drop the parallelism to 1, both to make the output
606 // deterministic and because there is no real work anyway. 606 // deterministic and because there is no real work anyway.
607 par := buildP 607 par := buildP
608 if buildN { 608 if buildN {
609 par = 1 609 par = 1
610 } 610 }
611 for i := 0; i < par; i++ { 611 for i := 0; i < par; i++ {
612 wg.Add(1)
612 go func() { 613 go func() {
613 » » » for _ = range b.readySema { 614 » » » defer wg.Done()
614 » » » » // Receiving a value from b.sema entitles 615 » » » for {
615 » » » » // us to take from the ready queue. 616 » » » » select {
616 » » » » b.exec.Lock() 617 » » » » case _, ok := <-b.readySema:
617 » » » » a := b.ready.pop() 618 » » » » » if !ok {
618 » » » » b.exec.Unlock() 619 » » » » » » return
619 » » » » handle(a) 620 » » » » » }
621 » » » » » // Receiving a value from b.readySema en titles
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 // build is the action for building a single package or command. 638 // build is the action for building a single package or command.
628 func (b *builder) build(a *action) (err error) { 639 func (b *builder) build(a *action) (err error) {
629 defer func() { 640 defer func() {
630 if err != nil && err != errPrintedOutput { 641 if err != nil && err != errPrintedOutput {
631 err = fmt.Errorf("go build %s: %v", a.p.ImportPath, err) 642 err = fmt.Errorf("go build %s: %v", a.p.ImportPath, err)
632 } 643 }
633 }() 644 }()
634 if buildN { 645 if buildN {
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 if goarch != "amd64" || goos != "linux" && goos != "darwin" && goos != " windows" { 1862 if goarch != "amd64" || goos != "linux" && goos != "darwin" && goos != " windows" {
1852 fmt.Fprintf(os.Stderr, "go %s: -race is only supported on linux/ amd64, darwin/amd64 and windows/amd64\n", flag.Args()[0]) 1863 fmt.Fprintf(os.Stderr, "go %s: -race is only supported on linux/ amd64, darwin/amd64 and windows/amd64\n", flag.Args()[0])
1853 os.Exit(2) 1864 os.Exit(2)
1854 } 1865 }
1855 buildGcflags = append(buildGcflags, "-b") 1866 buildGcflags = append(buildGcflags, "-b")
1856 buildLdflags = append(buildLdflags, "-b") 1867 buildLdflags = append(buildLdflags, "-b")
1857 buildCcflags = append(buildCcflags, "-DRACE") 1868 buildCcflags = append(buildCcflags, "-DRACE")
1858 buildContext.InstallTag = "race" 1869 buildContext.InstallTag = "race"
1859 buildContext.BuildTags = append(buildContext.BuildTags, "race") 1870 buildContext.BuildTags = append(buildContext.BuildTags, "race")
1860 } 1871 }
OLDNEW
« no previous file with comments | « no previous file | src/cmd/go/signal.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b