-/*
-goredo -- djb's redo implementation on pure Go
-Copyright (C) 2020-2021 Sergey Matveev <stargrave@stargrave.org>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 3 of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
+// goredo -- djb's redo implementation on pure Go
+// Copyright (C) 2020-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Jobserver
func jsStart(jobsEnv string) {
jobs := uint64(1)
var err error
- if *flagJobs == 0 {
+ switch {
+ case *flagJobs == 0:
jobs = 0
- } else if *flagJobs > 0 {
+ case *flagJobs > 0:
jobs = uint64(*flagJobs)
- } else if jobsEnv != "" {
+ case jobsEnv != "":
jobs, err = strconv.ParseUint(jobsEnv, 10, 64)
if err != nil {
log.Fatalln("can not parse", EnvJobs, err)
}
JSR, JSW, err = os.Pipe()
if err != nil {
- log.Fatalln(err)
+ log.Fatal(err)
}
- trace(CJS, "initial fill with %d", jobs)
+ tracef(CJS, "initial fill with %d", jobs)
jsTokens[BMakeGoodToken] = int(jobs)
for ; jobs > 0; jobs-- {
jsReleaseNoLock(BMakeGoodToken)
func() {
defer func() {
if err := recover(); err != nil {
- log.Fatalln(err)
+ log.Fatal(err)
}
}()
JSR = mustParseFd(match[2], "JSR")
if JSW == nil {
return
}
- trace(CJS, "release from %s", ctx)
+ tracef(CJS, "release from %s", ctx)
jsTokensM.Lock()
jsTokens[token]--
jsReleaseNoLock(token)
if JSR == nil {
return BMakeGoodToken
}
- trace(CJS, "acquire for %s", ctx)
+ tracef(CJS, "acquire for %s", ctx)
token := []byte{0}
if n, err := JSR.Read(token); err != nil || n != 1 {
log.Fatalln("can not read JSR:", err)
jsTokensM.Lock()
jsTokens[token[0]]++
jsTokensM.Unlock()
- trace(CJS, "acquired for %s", ctx)
+ tracef(CJS, "acquired for %s", ctx)
return token[0]
}