##// END OF EJS Templates
minor refactoring
cin -
r116:da56ba7b1aab v2
parent child
Show More
@@ -0,0 +1,48
1 using System;
2 using Implab.Parallels;
3 using System.Threading;
4
5 namespace Implab {
6 public class ComponentContainer : IComponentContainer, IDisposable {
7 static readonly ComponentContainer _appContainer;
8
9 static ComponentContainer() {
10 _appContainer = new ComponentContainer();
11 AppDomain.CurrentDomain.ProcessExit += HandleProcessExit;
12 }
13
14 public static ComponentContainer Global {
15 get {
16 return _appContainer;
17 }
18 }
19
20 bool m_disposed;
21 readonly MTQueue<IDisposable> m_components = new MTQueue<IDisposable>();
22
23 public void Add(IDisposable item) {
24 Safe.ArgumentNotNull(item, "item");
25 Thread.MemoryBarrier();
26 if (m_disposed) {
27 item.Dispose();
28 } else {
29 m_components.Enqueue(item);
30 if (m_disposed && m_components.TryDequeue(out item))
31 item.Dispose();
32 }
33 }
34
35 public void Dispose() {
36 m_disposed = true;
37 IDisposable item;
38 while (m_components.TryDequeue(out item))
39 item.Dispose();
40 }
41
42 static void HandleProcessExit (object sender, EventArgs e)
43 {
44 _appContainer.Dispose();
45 }
46 }
47 }
48
@@ -14,3 +14,4 Implab.Fx.Test/obj/
14 14 Implab.Diagnostics.Interactive/bin/
15 15 Implab.Diagnostics.Interactive/obj/
16 16 MonoPlay/bin/
17 MonoPlay/obj/
@@ -146,10 +146,10
146 146 <Compile Include="Diagnostics\LogEventArgsT.cs" />
147 147 <Compile Include="Diagnostics\Extensions.cs" />
148 148 <Compile Include="IComponentContainer.cs" />
149 <Compile Include="MTComponentContainer.cs" />
150 149 <Compile Include="PromiseEventType.cs" />
151 150 <Compile Include="Parallels\MTCustomQueue.cs" />
152 151 <Compile Include="Parallels\MTCustomQueueNode.cs" />
152 <Compile Include="ComponentContainer.cs" />
153 153 </ItemGroup>
154 154 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
155 155 <ItemGroup />
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now