Skip to content

Commit

Permalink
Add global mutex to prevent concurrent use
Browse files Browse the repository at this point in the history
  • Loading branch information
bording authored and arturcic committed Apr 28, 2021
1 parent e67db0b commit f2791bb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/GitVersion.App/GitVersionExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using GitVersion.Configuration;
using GitVersion.Extensions;
using GitVersion.Logging;
Expand Down Expand Up @@ -56,8 +57,16 @@ public int Execute(GitVersionOptions gitVersionOptions)

private int RunGitVersionTool(GitVersionOptions gitVersionOptions)
{
var mutexName = gitVersionOptions.WorkingDirectory.Replace("\\", "");
using var mutex = new Mutex(true, $@"Global\{mutexName}", out var acquired);

try
{
if (!acquired)
{
mutex.WaitOne();
}

var variables = gitVersionCalculateTool.CalculateVersionVariables();

var configuration = configProvider.Provide(overrideConfig: gitVersionOptions.ConfigInfo.OverrideConfig);
Expand Down Expand Up @@ -92,6 +101,10 @@ private int RunGitVersionTool(GitVersionOptions gitVersionOptions)
}
return 1;
}
finally
{
mutex.ReleaseMutex();
}

return 0;
}
Expand Down

0 comments on commit f2791bb

Please sign in to comment.