diff --git a/Implab.Diagnostics.Interactive/InteractiveListener.cs b/Implab.Diagnostics.Interactive/InteractiveListener.cs --- a/Implab.Diagnostics.Interactive/InteractiveListener.cs +++ b/Implab.Diagnostics.Interactive/InteractiveListener.cs @@ -17,7 +17,7 @@ namespace Implab.Diagnostics.Interactive readonly Promise m_guiStarted = new Promise(); readonly IPromise m_guiFinished; - readonly IPromise m_workerFinished = new Promise(); + // readonly IPromise m_workerFinished = new Promise(); readonly MTQueue m_queue = new MTQueue(); readonly AutoResetEvent m_queueEvent = new AutoResetEvent(false); @@ -31,7 +31,7 @@ namespace Implab.Diagnostics.Interactive public InteractiveListener(bool global) : base(global) { m_guiFinished = AsyncPool.InvokeNewThread(GuiThread); - m_workerFinished = AsyncPool.InvokeNewThread(QueueThread); + /*m_workerFinished = */AsyncPool.InvokeNewThread(QueueThread); m_guiStarted.Join(); } diff --git a/Implab/Implab.csproj b/Implab/Implab.csproj --- a/Implab/Implab.csproj +++ b/Implab/Implab.csproj @@ -46,6 +46,25 @@ false NET_4_5 + + true + full + false + bin\Debug + TRACE;DEBUG;NET_4_5;MONO + prompt + 4 + true + false + + + true + bin\Release + NET_4_5;MONO; + prompt + 4 + false + diff --git a/Implab/JSON/JSONXmlReader.cs b/Implab/JSON/JSONXmlReader.cs --- a/Implab/JSON/JSONXmlReader.cs +++ b/Implab/JSON/JSONXmlReader.cs @@ -301,6 +301,9 @@ namespace Implab.JSON { } protected override void Dispose(bool disposing) { + #if MONO + disposing = true; + #endif if (disposing) { m_parser.Dispose(); } diff --git a/Implab/ObjectPool.cs b/Implab/ObjectPool.cs --- a/Implab/ObjectPool.cs +++ b/Implab/ObjectPool.cs @@ -1,31 +1,26 @@ using System; using Implab.Parallels; using System.Threading; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace Implab { - public class ObjectPool : IDisposable { - readonly Func m_factory; - readonly Action m_cleanup; + public abstract class ObjectPool : IDisposable { readonly int m_size; readonly MTQueue m_queue = new MTQueue(); + [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes")] + static readonly bool _isValueType = typeof(T).IsValueType; + bool m_disposed; int m_count; - public ObjectPool(Func factory, Action cleanup, int size) { - Safe.ArgumentNotNull(factory, "factory"); - Safe.ArgumentInRange(size, 1, size, "size"); - - m_factory = factory; - m_cleanup = cleanup; + protected ObjectPool(int size) { m_size = size; } - public ObjectPool(Func factory, Action cleanup) : this(factory,cleanup,Environment.ProcessorCount+1) { - } - - public ObjectPool(Func factory) : this(factory,null,Environment.ProcessorCount+1) { + protected ObjectPool() : this(Environment.ProcessorCount+1) { } public ObjectPoolWrapper AllocateAuto() { @@ -35,24 +30,32 @@ namespace Implab { public T Allocate() { if (m_disposed) - throw new ObjectDisposedException(this.ToString()); + throw new ObjectDisposedException(ToString()); T instance; if (m_queue.TryDequeue(out instance)) { Interlocked.Decrement(ref m_count); } else { - instance = m_factory(); + instance = CreateInstance(); + Debug.Assert(!Object.Equals(instance, default(T)) || _isValueType); } return instance; } + protected abstract T CreateInstance(); + + protected virtual void CleanupInstance(T instance) { + } + public void Release(T instance) { + if ( Object.Equals(instance,default(T)) && !_isValueType) + return; + Thread.MemoryBarrier(); if (m_count < m_size && !m_disposed) { Interlocked.Increment(ref m_count); - if (m_cleanup != null) - m_cleanup(instance); + CleanupInstance(instance); m_queue.Enqueue(instance);