]> Cypherpunks.ru repositories - goredo.git/blobdiff - js.go
Download link for 2.6.2 release
[goredo.git] / js.go
diff --git a/js.go b/js.go
index 1f2ec3985a463333781e738b291bcc00ab4d5e70..0aa43d9393cbc07cbc0adc98ca56ef87303578ff 100644 (file)
--- a/js.go
+++ b/js.go
@@ -1,19 +1,17 @@
-/*
-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
 
@@ -82,11 +80,12 @@ func init() {
 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)
@@ -98,9 +97,9 @@ func jsStart(jobsEnv string) {
        }
        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)
@@ -152,7 +151,7 @@ func jsInit() {
        func() {
                defer func() {
                        if err := recover(); err != nil {
-                               log.Fatalln(err)
+                               log.Fatal(err)
                        }
                }()
                JSR = mustParseFd(match[2], "JSR")
@@ -180,7 +179,7 @@ func jsRelease(ctx string, token byte) {
        if JSW == nil {
                return
        }
-       trace(CJS, "release from %s", ctx)
+       tracef(CJS, "release from %s", ctx)
        jsTokensM.Lock()
        jsTokens[token]--
        jsReleaseNoLock(token)
@@ -201,7 +200,7 @@ func jsAcquire(ctx string) byte {
        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)
@@ -209,6 +208,6 @@ func jsAcquire(ctx string) byte {
        jsTokensM.Lock()
        jsTokens[token[0]]++
        jsTokensM.Unlock()
-       trace(CJS, "acquired for %s", ctx)
+       tracef(CJS, "acquired for %s", ctx)
        return token[0]
 }