diff Implab/Components/DisposablePool.cs @ 153:b933ec88446e v2

docs
author cin
date Fri, 12 Feb 2016 00:59:29 +0300
parents 240aa6994018
children c52691faaf21
line wrap: on
line diff
--- a/Implab/Components/DisposablePool.cs	Thu Feb 11 01:56:27 2016 +0300
+++ b/Implab/Components/DisposablePool.cs	Fri Feb 12 00:59:29 2016 +0300
@@ -4,7 +4,16 @@
 using System.Diagnostics;
 using System.Diagnostics.CodeAnalysis;
 
-namespace Implab {
+namespace Implab.Components {
+    /// <summary>
+    /// The base class for implementing pools of disposable objects.
+    /// </summary>
+    /// <remarks>
+    /// <para>This class maintains a set of pre-created objects and which are frequently allocated and released
+    /// by clients. The pool maintains maximum number of unsued object, any object above this limit is disposed,
+    /// if the pool is empty it will create new objects on demand.</para>
+    /// <para>Instances of this class are thread-safe.</para>
+    /// </remarks>
     public abstract class DisposablePool<T> : IDisposable {
         readonly int m_size;
         readonly AsyncQueue<T> m_queue = new AsyncQueue<T>();
@@ -62,8 +71,9 @@
                     ((IDisposable)instance).Dispose() ;
 
             } else {
-                if (instance is IDisposable)
-                    ((IDisposable)instance).Dispose();
+                var disposable = instance as IDisposable;
+                if (disposable != null)
+                    disposable.Dispose();
             }
         }
 
@@ -71,9 +81,11 @@
             if (disposing) {
                 m_disposed = true;
                 T instance;
-                while (m_queue.TryDequeue(out instance))
-                    if (instance is IDisposable)
-                        ((IDisposable)instance).Dispose();
+                while (m_queue.TryDequeue(out instance)) {
+                    var disposable = instance as IDisposable;
+                    if (disposable != null)
+                        disposable.Dispose();
+                }
             }
         }