Merge pull request #827 from joaomoreno/mutex

Support Windows mutexes

fixes #822
This commit is contained in:
João Moreno 2015-11-30 18:25:42 +01:00
commit 3d93cc4fd5
4 changed files with 42 additions and 2 deletions

16
npm-shrinkwrap.json generated
View file

@ -460,6 +460,22 @@
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz"
}
}
},
"windows-mutex": {
"version": "0.1.3",
"from": "windows-mutex@0.1.3",
"dependencies": {
"bindings": {
"version": "1.2.1",
"from": "bindings@>=1.2.1 <2.0.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.2.1.tgz"
},
"nan": {
"version": "2.1.0",
"from": "nan@>=2.1.0 <3.0.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.1.0.tgz"
}
}
}
}
}

View file

@ -12,7 +12,7 @@
},
"scripts": {
"test": "node node_modules/mocha/bin/_mocha",
"preinstall": "node build/npm/preinstall.js",
"preinstall": "node build/npm/preinstall.js",
"postinstall": "npm --prefix extensions/csharp-o/ install extensions/csharp-o/ && npm --prefix extensions/vscode-api-tests/ install extensions/vscode-api-tests/"
},
"dependencies": {
@ -89,5 +89,8 @@
"ghooks": {
"pre-commit": "node build/gulpfile.hygiene.js"
}
},
"optionalDependencies": {
"windows-mutex": "^0.1.3"
}
}

View file

@ -0,0 +1,12 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare module 'windows-mutex' {
export class Mutex {
constructor(name: string);
isActive(): boolean;
release(): void;
}
}

View file

@ -9,7 +9,6 @@ import app = require('app');
import fs = require('fs');
import dialog = require('dialog');
import shell = require('shell');
import nls = require('vs/nls');
import {assign} from 'vs/base/common/objects';
import platform = require('vs/base/common/platform');
@ -233,6 +232,15 @@ function setupIPC(): TPromise<Server> {
return setup(true);
}
function setupMutex() {
try {
var Mutex = (<any> require.__$__nodeRequire('windows-mutex')).Mutex;
new Mutex('vscode');
} catch (e) {
// noop
}
}
// On some platforms we need to manually read from the global environment variables
// and assign them to the process environment (e.g. when doubleclick app on Mac)
getUserEnvironment()
@ -241,6 +249,7 @@ getUserEnvironment()
return timebomb()
.then(setupIPC)
.then(ipcServer => { setupMutex(); return ipcServer; })
.then(ipcServer => main(ipcServer, userEnv));
})
.done(null, quit);