From 979942a90658cface519e31e7542c60692c73652 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sun, 1 Feb 2015 13:09:39 -0600 Subject: [PATCH] Fix concurrent compiles. Also configure 2 by default --- etc/config/gcc-explorer.defaults.properties | 1 + lib/compile.js | 26 +++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/etc/config/gcc-explorer.defaults.properties b/etc/config/gcc-explorer.defaults.properties index 9474129f..8a351697 100644 --- a/etc/config/gcc-explorer.defaults.properties +++ b/etc/config/gcc-explorer.defaults.properties @@ -9,3 +9,4 @@ cacheMb=200 #androidNdk=/opt/google/android-ndk-r9c language=C++ options=-O2 +maxConcurrentCompiles=2 diff --git a/lib/compile.js b/lib/compile.js index 985733f3..3558e13c 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -88,7 +88,7 @@ Compile.prototype.runCompiler = function (compiler, options) { stderr += data; }); return new Promise(function (resolve, reject) { - child.on('error', function(e) { + child.on('error', function (e) { reject(e); }); child.on('exit', function (code) { @@ -120,7 +120,7 @@ Compile.prototype.compile = function (source, compiler, options, filters) { } self.cacheMisses++; - var tempFileAndDirPromise = self.compileQueue.add(function () { + var tempFileAndDirPromise = Promise.resolve().then(function () { return self.newTempDir().then(function (dirPath) { var inputFilename = path.join(dirPath, props.get("gcc-explorer", "compileFilename")); return self.writeFile(inputFilename, source).then(function () { @@ -176,16 +176,18 @@ Compile.prototype.compile = function (source, compiler, options, filters) { }); }); - return compileToAsmPromise.then(function (result) { - if (result.dirPath) { - fs.remove(result.dirPath); - result.dirPath = undefined; - } - if (result.okToCache) { - self.cache.set(key, result); - self.cacheStats(); - } - return result; + return self.compileQueue.add(function () { + return compileToAsmPromise.then(function (result) { + if (result.dirPath) { + fs.remove(result.dirPath); + result.dirPath = undefined; + } + if (result.okToCache) { + self.cache.set(key, result); + self.cacheStats(); + } + return result; + }); }); };