Skip to content

Commit b8c24a7

Browse files
committed
Use threads only for git processes on windows
On Ubuntu, threads can cause seg faults, see: HaxeFoundation/neko#281
1 parent 8fb8206 commit b8c24a7

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

src/haxelib/api/Vcs.hx

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -192,28 +192,39 @@ abstract class Vcs implements IVcs {
192192
// just in case process hangs waiting for stdin
193193
p.stdin.close();
194194

195-
final streamsLock = new sys.thread.Lock();
196-
function readFrom(stream:haxe.io.Input, to: {value: String}) {
197-
to.value = stream.readAll().toString();
198-
streamsLock.release();
199-
}
200-
201-
final out = {value: ""};
202-
final err = {value: ""};
203-
Thread.create(readFrom.bind(p.stdout, out));
204-
Thread.create(readFrom.bind(p.stderr, err));
195+
final ret = if (Sys.systemName() == "Windows") {
196+
final streamsLock = new sys.thread.Lock();
197+
function readFrom(stream:haxe.io.Input, to:{value:String}) {
198+
to.value = stream.readAll().toString();
199+
streamsLock.release();
200+
}
205201

206-
final code = p.exitCode();
207-
for (_ in 0...2) {
208-
// wait until we finish reading from both streams
209-
streamsLock.wait();
210-
}
202+
final out = {value: ""};
203+
final err = {value: ""};
204+
Thread.create(readFrom.bind(p.stdout, out));
205+
Thread.create(readFrom.bind(p.stderr, err));
211206

212-
final ret = {
213-
code: code,
214-
out: out.value,
215-
err: err.value
207+
final code = p.exitCode();
208+
for (_ in 0...2) {
209+
// wait until we finish reading from both streams
210+
streamsLock.wait();
211+
}
212+
{
213+
code: code,
214+
out: out.value,
215+
err: err.value
216+
};
217+
} else {
218+
final out = p.stdout.readAll().toString();
219+
final err = p.stderr.readAll().toString();
220+
final code = p.exitCode();
221+
{
222+
code: code,
223+
out: out,
224+
err: err
225+
};
216226
};
227+
217228
p.close();
218229
return ret;
219230
}

0 commit comments

Comments
 (0)