Skip to content

Commit

Permalink
fixed deadlock with stats
Browse files Browse the repository at this point in the history
  • Loading branch information
inorton committed May 27, 2014
1 parent acfad81 commit 10a885c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CClash/CClashServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public CClashResponse ProcessRequest(CClashRequest req)
rv.exitcode = 0;
cache.SetupStats(); // commits stats to disk

rv.stdout = StatOutputs.GetStatsString(req.compiler);
rv.stdout = StatOutputs.GetStatsString(req.compiler, cache);
break;

case Command.Run:
Expand Down
18 changes: 12 additions & 6 deletions CClash/CClashServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ void Connect()

try
{
if (!ncs.IsConnected)
ncs.Connect(100);
ncs.ReadMode = PipeTransmissionMode.Message;
ConnectClient();
return;
}
catch (IOException ex)
Expand All @@ -50,8 +48,7 @@ void Connect()
{
}


// start the server, but lets not try to use it here, the next instance can
// start the server
try {

var p = new Process();
Expand All @@ -63,12 +60,21 @@ void Connect()
p.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
throw new CClashWarningException("starting new server");
System.Threading.Thread.Sleep(1000);
ConnectClient();
} catch (Exception e) {
Logging.Emit("error starting cclash server process", e.Message);
throw new CClashErrorException("could not start/connect to server");
}
}

private void ConnectClient()
{
if (!ncs.IsConnected)
ncs.Connect(100);
ncs.ReadMode = PipeTransmissionMode.Message;
}

public ICacheInfo Stats
{
get
Expand Down
15 changes: 13 additions & 2 deletions CClash/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public static int Main(string[] args)
var compiler = Compiler.Find();
if (Settings.ServiceMode)
{
for (int i = 0; i < 3; i++ ) {
for (int i = 0; i < 3; i++)
{
try
{
var cc = new CClashServerClient(Settings.CacheDirectory);
Expand All @@ -84,6 +85,11 @@ public static int Main(string[] args)
return 0;
}
}
catch (CClashErrorException ex)
{
Logging.Error(ex.Message);
return -1;
}
catch (CClashWarningException)
{
System.Threading.Thread.Sleep(2000);
Expand All @@ -97,7 +103,12 @@ public static int Main(string[] args)
}
else
{
Console.Out.WriteLine(StatOutputs.GetStatsString(compiler));
using (ICompilerCache cc =
CompilerCacheFactory.Get(Settings.DirectMode, Settings.CacheDirectory, compiler, Environment.CurrentDirectory, Compiler.GetEnvironmentDictionary()
))
{
Console.Out.WriteLine(StatOutputs.GetStatsString(compiler, cc));
}
}
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions CClash/StatOutputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace CClash
{
public class StatOutputs
{
public static string GetStatsString(string compiler)
public static string GetStatsString(string compiler, ICompilerCache cache)
{
var sb = new StringBuilder();
sb.WriteLine("compiler: {0}", compiler);
Expand All @@ -27,7 +27,7 @@ public static string GetStatsString(string compiler)
}
if (compiler != null)
{
using (var cache = new DirectCompilerCache(Settings.CacheDirectory))
if (cache != null)
{
var mseclost = cache.Stats.MSecLost;
var msecsaved = cache.Stats.MSecSaved;
Expand Down
Binary file modified cclash.v11.suo
Binary file not shown.

0 comments on commit 10a885c

Please sign in to comment.