Mercurial > pub > ImplabNet
changeset 116:da56ba7b1aab v2
minor refactoring
author | cin |
---|---|
date | Tue, 23 Dec 2014 03:20:39 +0300 |
parents | ffd3702968c7 |
children | 8beee0d11de6 |
files | .hgignore Implab/ComponentContainer.cs Implab/Implab.csproj Implab/MTComponentContainer.cs |
diffstat | 4 files changed, 50 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- 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/
--- /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<IDisposable> m_components = new MTQueue<IDisposable>(); + + 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(); + } + } +} +
--- 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 @@ <Compile Include="Diagnostics\LogEventArgsT.cs" /> <Compile Include="Diagnostics\Extensions.cs" /> <Compile Include="IComponentContainer.cs" /> - <Compile Include="MTComponentContainer.cs" /> <Compile Include="PromiseEventType.cs" /> <Compile Include="Parallels\MTCustomQueue.cs" /> <Compile Include="Parallels\MTCustomQueueNode.cs" /> + <Compile Include="ComponentContainer.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ItemGroup />
--- 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<IDisposable> m_components = new MTQueue<IDisposable>(); - - 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(); - } - } -} -