# HG changeset patch # User cin # Date 1419294039 -10800 # Node ID da56ba7b1aab57f94aec653b8ea6e6bea849ddd2 # Parent ffd3702968c7c701fa40dc8fc318d6399c5b258c minor refactoring diff -r ffd3702968c7 -r da56ba7b1aab .hgignore --- a/.hgignore Sun Dec 21 13:52:08 2014 +0300 +++ b/.hgignore Tue Dec 23 03:20:39 2014 +0300 @@ -14,3 +14,4 @@ Implab.Diagnostics.Interactive/bin/ Implab.Diagnostics.Interactive/obj/ MonoPlay/bin/ +MonoPlay/obj/ diff -r ffd3702968c7 -r da56ba7b1aab Implab/ComponentContainer.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab/ComponentContainer.cs Tue Dec 23 03:20:39 2014 +0300 @@ -0,0 +1,48 @@ +using System; +using Implab.Parallels; +using System.Threading; + +namespace Implab { + public class ComponentContainer : IComponentContainer, IDisposable { + static readonly ComponentContainer _appContainer; + + static ComponentContainer() { + _appContainer = new ComponentContainer(); + AppDomain.CurrentDomain.ProcessExit += HandleProcessExit; + } + + public static ComponentContainer Global { + get { + return _appContainer; + } + } + + bool m_disposed; + readonly MTQueue m_components = new MTQueue(); + + public void Add(IDisposable item) { + Safe.ArgumentNotNull(item, "item"); + Thread.MemoryBarrier(); + if (m_disposed) { + item.Dispose(); + } else { + m_components.Enqueue(item); + if (m_disposed && m_components.TryDequeue(out item)) + item.Dispose(); + } + } + + public void Dispose() { + m_disposed = true; + IDisposable item; + while (m_components.TryDequeue(out item)) + item.Dispose(); + } + + static void HandleProcessExit (object sender, EventArgs e) + { + _appContainer.Dispose(); + } + } +} + diff -r ffd3702968c7 -r da56ba7b1aab Implab/Implab.csproj --- a/Implab/Implab.csproj Sun Dec 21 13:52:08 2014 +0300 +++ b/Implab/Implab.csproj Tue Dec 23 03:20:39 2014 +0300 @@ -146,10 +146,10 @@ - + diff -r ffd3702968c7 -r da56ba7b1aab Implab/MTComponentContainer.cs --- a/Implab/MTComponentContainer.cs Sun Dec 21 13:52:08 2014 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -using System; -using Implab.Parallels; -using System.Threading; - -namespace Implab { - public class MTComponentContainer : IComponentContainer, IDisposable { - static readonly MTComponentContainer _appContainer; - - static MTComponentContainer() { - _appContainer = new MTComponentContainer(); - AppDomain.CurrentDomain.ProcessExit += HandleProcessExit; - } - - public static MTComponentContainer AppContainer { - get { - return _appContainer; - } - } - - bool m_disposed; - readonly MTQueue m_components = new MTQueue(); - - public void Add(IDisposable item) { - Safe.ArgumentNotNull(item, "item"); - Thread.MemoryBarrier(); - if (m_disposed) { - item.Dispose(); - } else { - m_components.Enqueue(item); - if (m_disposed && m_components.TryDequeue(out item)) - item.Dispose(); - } - } - - public void Dispose() { - m_disposed = true; - IDisposable item; - while (m_components.TryDequeue(out item)) - item.Dispose(); - } - - static void HandleProcessExit (object sender, EventArgs e) - { - _appContainer.Dispose(); - } - } -} -