@@ -17,7 +17,7 namespace Implab.Diagnostics.Interactive | |||||
17 | readonly Promise<object> m_guiStarted = new Promise<object>(); |
|
17 | readonly Promise<object> m_guiStarted = new Promise<object>(); | |
18 |
|
18 | |||
19 | readonly IPromise m_guiFinished; |
|
19 | readonly IPromise m_guiFinished; | |
20 | readonly IPromise m_workerFinished = new Promise<object>(); |
|
20 | // readonly IPromise m_workerFinished = new Promise<object>(); | |
21 |
|
21 | |||
22 | readonly MTQueue<TraceViewItem> m_queue = new MTQueue<TraceViewItem>(); |
|
22 | readonly MTQueue<TraceViewItem> m_queue = new MTQueue<TraceViewItem>(); | |
23 | readonly AutoResetEvent m_queueEvent = new AutoResetEvent(false); |
|
23 | readonly AutoResetEvent m_queueEvent = new AutoResetEvent(false); | |
@@ -31,7 +31,7 namespace Implab.Diagnostics.Interactive | |||||
31 |
|
31 | |||
32 | public InteractiveListener(bool global) : base(global) { |
|
32 | public InteractiveListener(bool global) : base(global) { | |
33 | m_guiFinished = AsyncPool.InvokeNewThread(GuiThread); |
|
33 | m_guiFinished = AsyncPool.InvokeNewThread(GuiThread); | |
34 | m_workerFinished = AsyncPool.InvokeNewThread(QueueThread); |
|
34 | /*m_workerFinished = */AsyncPool.InvokeNewThread(QueueThread); | |
35 |
|
35 | |||
36 | m_guiStarted.Join(); |
|
36 | m_guiStarted.Join(); | |
37 | } |
|
37 | } |
@@ -46,6 +46,25 | |||||
46 | <ConsolePause>false</ConsolePause> |
|
46 | <ConsolePause>false</ConsolePause> | |
47 | <DefineConstants>NET_4_5</DefineConstants> |
|
47 | <DefineConstants>NET_4_5</DefineConstants> | |
48 | </PropertyGroup> |
|
48 | </PropertyGroup> | |
|
49 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|AnyCPU' "> | |||
|
50 | <DebugSymbols>true</DebugSymbols> | |||
|
51 | <DebugType>full</DebugType> | |||
|
52 | <Optimize>false</Optimize> | |||
|
53 | <OutputPath>bin\Debug</OutputPath> | |||
|
54 | <DefineConstants>TRACE;DEBUG;NET_4_5;MONO</DefineConstants> | |||
|
55 | <ErrorReport>prompt</ErrorReport> | |||
|
56 | <WarningLevel>4</WarningLevel> | |||
|
57 | <RunCodeAnalysis>true</RunCodeAnalysis> | |||
|
58 | <ConsolePause>false</ConsolePause> | |||
|
59 | </PropertyGroup> | |||
|
60 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMono|AnyCPU' "> | |||
|
61 | <Optimize>true</Optimize> | |||
|
62 | <OutputPath>bin\Release</OutputPath> | |||
|
63 | <DefineConstants>NET_4_5;MONO;</DefineConstants> | |||
|
64 | <ErrorReport>prompt</ErrorReport> | |||
|
65 | <WarningLevel>4</WarningLevel> | |||
|
66 | <ConsolePause>false</ConsolePause> | |||
|
67 | </PropertyGroup> | |||
49 | <ItemGroup> |
|
68 | <ItemGroup> | |
50 | <Reference Include="System" /> |
|
69 | <Reference Include="System" /> | |
51 | <Reference Include="System.Xml" /> |
|
70 | <Reference Include="System.Xml" /> |
@@ -301,6 +301,9 namespace Implab.JSON { | |||||
301 | } |
|
301 | } | |
302 |
|
302 | |||
303 | protected override void Dispose(bool disposing) { |
|
303 | protected override void Dispose(bool disposing) { | |
|
304 | #if MONO | |||
|
305 | disposing = true; | |||
|
306 | #endif | |||
304 | if (disposing) { |
|
307 | if (disposing) { | |
305 | m_parser.Dispose(); |
|
308 | m_parser.Dispose(); | |
306 | } |
|
309 | } |
@@ -1,31 +1,26 | |||||
1 | using System; |
|
1 | using System; | |
2 | using Implab.Parallels; |
|
2 | using Implab.Parallels; | |
3 | using System.Threading; |
|
3 | using System.Threading; | |
|
4 | using System.Diagnostics; | |||
|
5 | using System.Diagnostics.CodeAnalysis; | |||
4 |
|
6 | |||
5 | namespace Implab { |
|
7 | namespace Implab { | |
6 | public class ObjectPool<T> : IDisposable { |
|
8 | public abstract class ObjectPool<T> : IDisposable { | |
7 | readonly Func<T> m_factory; |
|
|||
8 | readonly Action<T> m_cleanup; |
|
|||
9 | readonly int m_size; |
|
9 | readonly int m_size; | |
10 | readonly MTQueue<T> m_queue = new MTQueue<T>(); |
|
10 | readonly MTQueue<T> m_queue = new MTQueue<T>(); | |
11 |
|
11 | |||
|
12 | [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes")] | |||
|
13 | static readonly bool _isValueType = typeof(T).IsValueType; | |||
|
14 | ||||
12 | bool m_disposed; |
|
15 | bool m_disposed; | |
13 |
|
16 | |||
14 | int m_count; |
|
17 | int m_count; | |
15 |
|
18 | |||
16 | public ObjectPool(Func<T> factory, Action<T> cleanup, int size) { |
|
19 | protected ObjectPool(int size) { | |
17 | Safe.ArgumentNotNull(factory, "factory"); |
|
|||
18 | Safe.ArgumentInRange(size, 1, size, "size"); |
|
|||
19 |
|
||||
20 | m_factory = factory; |
|
|||
21 | m_cleanup = cleanup; |
|
|||
22 | m_size = size; |
|
20 | m_size = size; | |
23 | } |
|
21 | } | |
24 |
|
22 | |||
25 |
p |
|
23 | protected ObjectPool() : this(Environment.ProcessorCount+1) { | |
26 | } |
|
|||
27 |
|
||||
28 | public ObjectPool(Func<T> factory) : this(factory,null,Environment.ProcessorCount+1) { |
|
|||
29 | } |
|
24 | } | |
30 |
|
25 | |||
31 | public ObjectPoolWrapper<T> AllocateAuto() { |
|
26 | public ObjectPoolWrapper<T> AllocateAuto() { | |
@@ -35,24 +30,32 namespace Implab { | |||||
35 |
|
30 | |||
36 | public T Allocate() { |
|
31 | public T Allocate() { | |
37 | if (m_disposed) |
|
32 | if (m_disposed) | |
38 |
throw new ObjectDisposedException( |
|
33 | throw new ObjectDisposedException(ToString()); | |
39 |
|
34 | |||
40 | T instance; |
|
35 | T instance; | |
41 | if (m_queue.TryDequeue(out instance)) { |
|
36 | if (m_queue.TryDequeue(out instance)) { | |
42 | Interlocked.Decrement(ref m_count); |
|
37 | Interlocked.Decrement(ref m_count); | |
43 | } else { |
|
38 | } else { | |
44 |
instance = |
|
39 | instance = CreateInstance(); | |
|
40 | Debug.Assert(!Object.Equals(instance, default(T)) || _isValueType); | |||
45 | } |
|
41 | } | |
46 | return instance; |
|
42 | return instance; | |
47 | } |
|
43 | } | |
48 |
|
44 | |||
|
45 | protected abstract T CreateInstance(); | |||
|
46 | ||||
|
47 | protected virtual void CleanupInstance(T instance) { | |||
|
48 | } | |||
|
49 | ||||
49 | public void Release(T instance) { |
|
50 | public void Release(T instance) { | |
|
51 | if ( Object.Equals(instance,default(T)) && !_isValueType) | |||
|
52 | return; | |||
|
53 | ||||
50 | Thread.MemoryBarrier(); |
|
54 | Thread.MemoryBarrier(); | |
51 | if (m_count < m_size && !m_disposed) { |
|
55 | if (m_count < m_size && !m_disposed) { | |
52 | Interlocked.Increment(ref m_count); |
|
56 | Interlocked.Increment(ref m_count); | |
53 |
|
57 | |||
54 |
|
|
58 | CleanupInstance(instance); | |
55 | m_cleanup(instance); |
|
|||
56 |
|
59 | |||
57 | m_queue.Enqueue(instance); |
|
60 | m_queue.Enqueue(instance); | |
58 |
|
61 |
General Comments 0
You need to be logged in to leave comments.
Login now