2 goredo -- redo implementation on pure Go
3 Copyright (C) 2020 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/>.
35 EnvJSFd = "REDO_JS_FD"
44 flagJobs = flag.Uint64("j", 1, "number of parallel jobs (0=inf) (REDO_JOBS)")
48 jsRaw := os.Getenv(EnvJSFd)
54 cols := strings.Split(jsRaw, ",")
56 log.Fatalln("invalid", EnvJSFd, "format")
58 JSR = mustParseFd(cols[0], "JSR")
59 JSW = mustParseFd(cols[1], "JSW")
60 jsRelease("ifchange entered")
62 killed := make(chan os.Signal, 0)
63 signal.Notify(killed, syscall.SIGTERM, syscall.SIGINT)
67 for ; jsTokens > 0; jsTokens-- {
76 if v := os.Getenv(EnvJobs); v != "" {
78 jobs, err = strconv.ParseUint(v, 10, 64)
80 log.Fatalln("can not parse", EnvJobs, err)
91 JSR, JSW, err = os.Pipe()
95 for i := uint64(0); i < jobs; i++ {
96 jsRelease("initial fill")
100 func jsReleaseNoLock() {
101 if n, err := JSW.Write([]byte{0}); err != nil || n != 1 {
102 panic("can not write JSW")
106 func jsRelease(ctx string) int {
110 trace(CJS, "release from %s", ctx)
119 func jsAcquire(ctx string) {
123 trace(CJS, "acquire for %s", ctx)
124 if n, err := JSR.Read([]byte{0}); err != nil || n != 1 {
125 panic("can not read JSR")
130 trace(CJS, "acquired for %s", ctx)