2 goredo -- djb's redo implementation on pure Go
3 Copyright (C) 2020-2021 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
36 EnvJSFd = "REDO_JS_FD"
45 flagJobs = flag.Int("j", -1, fmt.Sprintf("number of parallel jobs (0=inf, <0=1) (%s)", EnvJobs))
49 jsRaw := os.Getenv(EnvJSFd)
55 cols := strings.Split(jsRaw, ",")
57 log.Fatalln("invalid", EnvJSFd, "format")
59 JSR = mustParseFd(cols[0], "JSR")
60 JSW = mustParseFd(cols[1], "JSW")
61 jsRelease("ifchange entered")
63 killed := make(chan os.Signal, 0)
64 signal.Notify(killed, syscall.SIGTERM, syscall.SIGINT)
68 for ; jsTokens > 0; jsTokens-- {
80 } else if *flagJobs > 0 {
81 jobs = uint64(*flagJobs)
82 } else if v := os.Getenv(EnvJobs); v != "" {
83 jobs, err = strconv.ParseUint(v, 10, 64)
85 log.Fatalln("can not parse", EnvJobs, err)
93 JSR, JSW, err = os.Pipe()
97 for i := uint64(0); i < jobs; i++ {
98 jsRelease("initial fill")
102 func jsReleaseNoLock() {
103 if n, err := JSW.Write([]byte{0}); err != nil || n != 1 {
104 log.Fatalln("can not write JSW:", err)
108 func jsRelease(ctx string) int {
112 trace(CJS, "release from %s", ctx)
121 func jsAcquire(ctx string) {
125 trace(CJS, "acquire for %s", ctx)
126 if n, err := JSR.Read([]byte{0}); err != nil || n != 1 {
127 log.Fatalln("can not read JSR:", err)
132 trace(CJS, "acquired for %s", ctx)