# HG changeset patch # User cin # Date 1412078735 -14400 # Node ID abe260860bd61257c11e57c400c3807e5c9b3d85 # Parent 34bb2f32634dd0ebafc6e1d772b6e4131cc4db97 fixed JSONXmlReader disposing under ugly mono ObjectPool is made abstract diff -r 34bb2f32634d -r abe260860bd6 Implab.Diagnostics.Interactive/InteractiveListener.cs --- a/Implab.Diagnostics.Interactive/InteractiveListener.cs Tue Sep 30 08:20:45 2014 +0400 +++ b/Implab.Diagnostics.Interactive/InteractiveListener.cs Tue Sep 30 16:05:35 2014 +0400 @@ -17,7 +17,7 @@ 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 @@ 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 -r 34bb2f32634d -r abe260860bd6 Implab/Implab.csproj --- a/Implab/Implab.csproj Tue Sep 30 08:20:45 2014 +0400 +++ b/Implab/Implab.csproj Tue Sep 30 16:05:35 2014 +0400 @@ -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 -r 34bb2f32634d -r abe260860bd6 Implab/JSON/JSONXmlReader.cs --- a/Implab/JSON/JSONXmlReader.cs Tue Sep 30 08:20:45 2014 +0400 +++ b/Implab/JSON/JSONXmlReader.cs Tue Sep 30 16:05:35 2014 +0400 @@ -301,6 +301,9 @@ } protected override void Dispose(bool disposing) { + #if MONO + disposing = true; + #endif if (disposing) { m_parser.Dispose(); } diff -r 34bb2f32634d -r abe260860bd6 Implab/ObjectPool.cs --- a/Implab/ObjectPool.cs Tue Sep 30 08:20:45 2014 +0400 +++ b/Implab/ObjectPool.cs Tue Sep 30 16:05:35 2014 +0400 @@ -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 @@ 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);