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/>.
36 EnvJSFd = "REDO_JS_FD"
45 flagJobs = flag.Uint64("j", 1, fmt.Sprintf("number of parallel jobs (0=inf) (%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-- {
77 if v := os.Getenv(EnvJobs); v != "" {
79 jobs, err = strconv.ParseUint(v, 10, 64)
81 log.Fatalln("can not parse", EnvJobs, err)
92 JSR, JSW, err = os.Pipe()
96 for i := uint64(0); i < jobs; i++ {
97 jsRelease("initial fill")
101 func jsReleaseNoLock() {
102 if n, err := JSW.Write([]byte{0}); err != nil || n != 1 {
103 panic("can not write JSW")
107 func jsRelease(ctx string) int {
111 trace(CJS, "release from %s", ctx)
120 func jsAcquire(ctx string) {
124 trace(CJS, "acquire for %s", ctx)
125 if n, err := JSR.Read([]byte{0}); err != nil || n != 1 {
126 panic("can not read JSR")
131 trace(CJS, "acquired for %s", ctx)