willis: Simplify logic for throttling.
chan will not block until maxGoCount is reached, so the condition is a noop.
BUG=None
TEST=go run willis.go
Change-Id: I823205ec6d9d0d12b7a1e30ba71f2acf89201076
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2340177
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Tested-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
diff --git a/contrib/willis.go b/contrib/willis.go
index 9e01754..b264bc5 100644
--- a/contrib/willis.go
+++ b/contrib/willis.go
@@ -385,14 +385,9 @@
repoList := strings.Split(repos, "\n")
- throttlingNeeded := maxGoCount < len(repoList)
- var ch chan bool
- if throttlingNeeded {
- // Create a channel to use it as a throttle to prevent from starting
- // too many git queries concurrently.
- ch = make(chan bool, maxGoCount)
- fmt.Printf("Throttling at %d concurrent checks\n", maxGoCount)
- }
+ // Create a channel to use it as a throttle to prevent from starting
+ // too many git queries concurrently.
+ ch := make(chan bool, maxGoCount)
var wg sync.WaitGroup
for _, line := range repoList {
@@ -402,14 +397,10 @@
defer func() {
runningCounter--
countMtx.Unlock()
- if throttlingNeeded {
- <-ch
- }
+ <-ch
wg.Done()
}()
- if throttlingNeeded {
- ch <- true
- }
+ ch <- true
countMtx.Lock()
startedCounter++
runningCounter++