/* goredo -- redo implementation on pure Go Copyright (C) 2020 Sergey Matveev 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 . */ // Jobserver package main import "os" var ( JSR *os.File JSW *os.File ) func jsInit() { jsrRaw := os.Getenv(RedoJSRFdEnv) jswRaw := os.Getenv(RedoJSWFdEnv) if (jsrRaw == "" && jswRaw != "") || (jsrRaw != "" && jswRaw == "") { panic("both JSR and JSW must be set") } if jsrRaw == "NO" { // infinite jobs return } if jsrRaw != "" { JSR = mustParseFd(jsrRaw, "JSR") JSW = mustParseFd(jswRaw, "JSW") jsRelease("ifchange entered") return } if *JobsN == 0 { // infinite jobs return } var err error JSR, JSW, err = os.Pipe() if err != nil { panic(err) } for i := uint(0); i < *JobsN; i++ { jsRelease("initial fill") } } func jsRelease(ctx string) { if JSW == nil { return } trace(CJS, "release from %s", ctx) if n, err := JSW.Write([]byte{0}); err != nil || n != 1 { panic("can not write JSW") } } func jsAcquire(ctx string) { if JSR == nil { return } trace(CJS, "acquire for %s", ctx) if n, err := JSR.Read([]byte{0}); err != nil || n != 1 { panic("can not read JSR") } trace(CJS, "acquired for %s", ctx) }