Skip to content

Commit

Permalink
dont let mutex be garbage collected
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Dec 1, 2015
1 parent bbeb32a commit 9b6bff1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/vs/workbench/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {getUserEnvironment} from 'vs/base/node/env';
import {Promise, TPromise} from 'vs/base/common/winjs.base';
import {GitAskpassService} from 'vs/workbench/parts/git/electron-main/askpassService';
import {spawnSharedProcess} from 'vs/workbench/electron-main/sharedProcess';
import { Mutex } from 'windows-mutex';

export class LaunchService {
public start(args: env.ICommandLineArguments, userEnv: env.IProcessEnvironment): Promise {
Expand Down Expand Up @@ -81,10 +82,20 @@ function quit(arg?: any) {
process.exit(exitCode);
}


function main(ipcServer: Server, userEnv: env.IProcessEnvironment): void {
env.log('### VSCode main.js ###');
env.log(env.appRoot, env.cliArgs);

// Setup Windows mutex
let windowsMutex: Mutex = null;
try {
var Mutex = (<any> require.__$__nodeRequire('windows-mutex')).Mutex;
windowsMutex = new Mutex('vscode');
} catch (e) {
// noop
}

// Register IPC services
ipcServer.registerService('LaunchService', new LaunchService());
ipcServer.registerService('GitAskpassService', new GitAskpassService());
Expand Down Expand Up @@ -118,6 +129,7 @@ function main(ipcServer: Server, userEnv: env.IProcessEnvironment): void {
}

sharedProcess.kill();
windowsMutex && windowsMutex.release();
});

// Lifecycle
Expand Down Expand Up @@ -233,12 +245,6 @@ function setupIPC(): TPromise<Server> {
}

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
Expand Down

0 comments on commit 9b6bff1

Please sign in to comment.