Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Pryor <jpryor@novell.com>2008-09-09 19:08:29 +0400
committerJonathan Pryor <jpryor@novell.com>2008-09-09 19:08:29 +0400
commit6f6b6088515f9a4b70f2d5262aabe91eacc05c31 (patch)
treec516bfb0acaa1f08cef9d39c3a5b751ac289cc69 /mcs/class/System/System.Diagnostics/TraceImpl.cs
parent2642c934a7e58f1b4a234861128e3305503f90dc (diff)
* TraceImpl.cs:
- Remove the "lock-free" code, which (come to think of it) would be faulty in a multithreaded environment anyway because the "other" threads won't wait (block) until initialization is complete... - Add InitOnce() calls to all public properties, so that `Debug.AutoFlush=true' will cause InitOnce() to be loaded, lest a `Debug.AutoFlush=true; Debug.Listeners.Add(...)` sequence cause .AutoFlush=true to be ignored as the InitOnce implied by .Add() will "overwrite" the .AutoFlush. - Split up TraceListenerCollection creation from DefaultTraceListener addition, as TraceListenerCollection.Add() calls back into TraceImpl, so if these aren't separate we get an infinite loop and never actually initialize anything. - Fixes #424370. * TraceListenerCollection.cs: Add a TraceListenerCollection(bool) constructor, which provides a way to NOT add the DefaultTraceListener (needed by TraceImpl; see above). svn path=/trunk/mcs/; revision=112596
Diffstat (limited to 'mcs/class/System/System.Diagnostics/TraceImpl.cs')
-rw-r--r--mcs/class/System/System.Diagnostics/TraceImpl.cs72
1 files changed, 41 insertions, 31 deletions
diff --git a/mcs/class/System/System.Diagnostics/TraceImpl.cs b/mcs/class/System/System.Diagnostics/TraceImpl.cs
index 977788b6294..fa23e383633 100644
--- a/mcs/class/System/System.Diagnostics/TraceImpl.cs
+++ b/mcs/class/System/System.Diagnostics/TraceImpl.cs
@@ -39,9 +39,7 @@ namespace System.Diagnostics {
internal class TraceImpl {
-#if NO_LOCK_FREE
- private static object lock_ = new object ();
-#endif
+ private static object initLock = new object ();
private static bool autoFlush;
@@ -89,12 +87,21 @@ namespace System.Diagnostics {
}
public static bool AutoFlush {
- get {return autoFlush;}
- set {autoFlush = value;}
+ get {
+ InitOnce ();
+ return autoFlush;
+ }
+ set {
+ InitOnce ();
+ autoFlush = value;
+ }
}
public static int IndentLevel {
- get {return indentLevel;}
+ get {
+ InitOnce ();
+ return indentLevel;
+ }
set {
lock (ListenersSyncRoot) {
indentLevel = value;
@@ -107,7 +114,10 @@ namespace System.Diagnostics {
}
public static int IndentSize {
- get {return indentSize;}
+ get {
+ InitOnce ();
+ return indentSize;
+ }
set {
lock (ListenersSyncRoot) {
indentSize = value;
@@ -119,13 +129,13 @@ namespace System.Diagnostics {
}
}
- private static object listeners;
+ private static TraceListenerCollection listeners;
public static TraceListenerCollection Listeners {
get {
InitOnce ();
- return (TraceListenerCollection) listeners;
+ return listeners;
}
}
@@ -140,14 +150,23 @@ namespace System.Diagnostics {
static CorrelationManager correlation_manager = new CorrelationManager ();
public static CorrelationManager CorrelationManager {
- get { return correlation_manager; }
+ get {
+ InitOnce ();
+ return correlation_manager;
+ }
}
#endif
[MonoLimitation ("the property exists but it does nothing.")]
public static bool UseGlobalLock {
- get { return use_global_lock; }
- set { use_global_lock = value; }
+ get {
+ InitOnce ();
+ return use_global_lock;
+ }
+ set {
+ InitOnce ();
+ use_global_lock = value;
+ }
}
// Initialize the world.
@@ -169,27 +188,18 @@ namespace System.Diagnostics {
private static object InitOnce ()
{
object d = null;
-#if !NO_LOCK_FREE
- // The lock-free version
- if (listeners == null) {
- TraceListenerCollection c = new TraceListenerCollection ();
- Thread.MemoryBarrier ();
- while (Interlocked.CompareExchange (ref listeners, c, null) == null) {
- // Read in the .config file and get the ball rolling...
- d = DiagnosticsConfiguration.Settings;
- }
- Thread.MemoryBarrier ();
- }
-#else
- // The lock version (saved for posterity and potential debugging)
- lock (lock_) {
- if (listeners == null) {
- listeners = new TraceListenerCollection ();
- // Read in the .config file and get the ball rolling...
- d = DiagnosticsConfiguration.Settings;
+
+ if (initLock != null) {
+ lock (initLock) {
+ if (listeners == null) {
+ listeners = new TraceListenerCollection (false);
+ listeners.Add (new DefaultTraceListener ());
+ d = DiagnosticsConfiguration.Settings;
+ initLock = null;
+ }
}
}
-#endif
+
return d;
}