Skip to content

Commit

Permalink
2006-03-27 Robert Jordan <robertj@gmx.net>
Browse files Browse the repository at this point in the history
	* CachingCompiler.cs:  change the compilation locking scheme
	from "one mcs per process" to "one mcs per file".


svn path=/trunk/mcs/; revision=58595
  • Loading branch information
robert-j committed Mar 27, 2006
1 parent 7274f80 commit 009188a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
71 changes: 67 additions & 4 deletions mcs/class/System.Web/System.Web.Compilation/CachingCompiler.cs
Expand Up @@ -34,6 +34,7 @@
using System.Collections.Specialized;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Web.UI;
using System.Web.Caching;
using System.Web.Configuration;
Expand All @@ -43,7 +44,7 @@ namespace System.Web.Compilation
class CachingCompiler
{
static string dynamicBase = AppDomain.CurrentDomain.SetupInformation.DynamicBase;
static object compilationLock = new object ();
static Hashtable compilationTickets = new Hashtable ();
const string cachePrefix = "@@Assembly";
const string cacheTypePrefix = "@@@Type";

Expand Down Expand Up @@ -77,7 +78,15 @@ public static CompilerResults Compile (BaseCompiler compiler)
if (results != null)
return results;

lock (compilationLock) {
object ticket;
bool acquired = AcquireCompilationTicket (key, out ticket);

try {
Monitor.Enter (ticket);

if (!acquired)
Monitor.Wait (ticket);

results = (CompilerResults) cache [key];
#if NET_2_0
if (!compiler.IsRebuildingPartial)
Expand All @@ -89,6 +98,12 @@ public static CompilerResults Compile (BaseCompiler compiler)
results = comp.CompileAssemblyFromDom (compiler.CompilerParameters, compiler.Unit);
string [] deps = (string []) compiler.Parser.Dependencies.ToArray (typeof (string));
cache.InsertPrivate (key, results, new CacheDependency (deps));

Monitor.PulseAll (ticket);
} finally {
Monitor.Exit (ticket);
if (acquired)
ReleaseCompilationTicket (key);
}

return results;
Expand All @@ -102,7 +117,15 @@ public static CompilerResults Compile (WebServiceCompiler compiler)
if (results != null)
return results;

lock (compilationLock) {
object ticket;
bool acquired = AcquireCompilationTicket (key, out ticket);

try {
Monitor.Enter (ticket);

if (!acquired)
Monitor.Wait (ticket);

results = (CompilerResults) cache [key];
if (results != null)
return results;
Expand All @@ -113,6 +136,12 @@ public static CompilerResults Compile (WebServiceCompiler compiler)
results = compiler.Compiler.CompileAssemblyFromFile (options, compiler.InputFile);
string [] deps = (string []) parser.Dependencies.ToArray (typeof (string));
cache.InsertPrivate (key, results, new CacheDependency (deps));

Monitor.PulseAll (ticket);
} finally {
Monitor.Exit (ticket);
if (acquired)
ReleaseCompilationTicket (key);
}

return results;
Expand Down Expand Up @@ -141,7 +170,15 @@ internal static CompilerParameters GetOptions (ICollection assemblies)
if (!Directory.Exists (dynamicBase))
Directory.CreateDirectory (dynamicBase);

lock (compilationLock) {
object ticket;
bool acquired = AcquireCompilationTicket (cachePrefix + key, out ticket);

try {
Monitor.Enter (ticket);

if (!acquired)
Monitor.Wait (ticket);

results = (CompilerResults) cache [cachePrefix + key];
if (results != null)
return results;
Expand Down Expand Up @@ -175,6 +212,12 @@ internal static CompilerParameters GetOptions (ICollection assemblies)

string [] deps = (string []) realdeps.ToArray (typeof (string));
cache.InsertPrivate (cachePrefix + key, results, new CacheDependency (deps));

Monitor.PulseAll (ticket);
} finally {
Monitor.Exit (ticket);
if (acquired)
ReleaseCompilationTicket (cachePrefix + key);
}

return results;
Expand All @@ -199,6 +242,26 @@ internal static CompilerParameters GetOptions (ICollection assemblies)
InsertType (type, file);
return type;
}

static bool AcquireCompilationTicket (string key, out object ticket)
{
lock (compilationTickets.SyncRoot) {
ticket = compilationTickets [key];
if (ticket == null) {
ticket = new object ();
compilationTickets [key] = ticket;
return true;
}
}
return false;
}

static void ReleaseCompilationTicket (string key)
{
lock (compilationTickets.SyncRoot) {
compilationTickets.Remove (key);
}
}
}
}

5 changes: 5 additions & 0 deletions mcs/class/System.Web/System.Web.Compilation/ChangeLog
@@ -1,3 +1,8 @@
2006-03-27 Robert Jordan <robertj@gmx.net>

* CachingCompiler.cs: change the compilation locking scheme
from "one mcs per process" to "one mcs per file".

2006-03-24 Gonzalo Paniagua Javier <gonzalo@ximian.com>

* System.Web.Compilation/TemplateControlCompiler.cs: handle the new
Expand Down

0 comments on commit 009188a

Please sign in to comment.