From b8c24a783000c609ae3b45c27aab423d9e0d7193 Mon Sep 17 00:00:00 2001 From: tobil4sk Date: Tue, 4 Apr 2023 14:37:16 +0100 Subject: [PATCH] Use threads only for git processes on windows On Ubuntu, threads can cause seg faults, see: https://github.com/HaxeFoundation/neko/issues/281 --- src/haxelib/api/Vcs.hx | 49 ++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/haxelib/api/Vcs.hx b/src/haxelib/api/Vcs.hx index e83955d4..dd147b72 100644 --- a/src/haxelib/api/Vcs.hx +++ b/src/haxelib/api/Vcs.hx @@ -192,28 +192,39 @@ abstract class Vcs implements IVcs { // just in case process hangs waiting for stdin p.stdin.close(); - final streamsLock = new sys.thread.Lock(); - function readFrom(stream:haxe.io.Input, to: {value: String}) { - to.value = stream.readAll().toString(); - streamsLock.release(); - } - - final out = {value: ""}; - final err = {value: ""}; - Thread.create(readFrom.bind(p.stdout, out)); - Thread.create(readFrom.bind(p.stderr, err)); + final ret = if (Sys.systemName() == "Windows") { + final streamsLock = new sys.thread.Lock(); + function readFrom(stream:haxe.io.Input, to:{value:String}) { + to.value = stream.readAll().toString(); + streamsLock.release(); + } - final code = p.exitCode(); - for (_ in 0...2) { - // wait until we finish reading from both streams - streamsLock.wait(); - } + final out = {value: ""}; + final err = {value: ""}; + Thread.create(readFrom.bind(p.stdout, out)); + Thread.create(readFrom.bind(p.stderr, err)); - final ret = { - code: code, - out: out.value, - err: err.value + final code = p.exitCode(); + for (_ in 0...2) { + // wait until we finish reading from both streams + streamsLock.wait(); + } + { + code: code, + out: out.value, + err: err.value + }; + } else { + final out = p.stdout.readAll().toString(); + final err = p.stderr.readAll().toString(); + final code = p.exitCode(); + { + code: code, + out: out, + err: err + }; }; + p.close(); return ret; }