activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r818614 - /activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/MemoryUsage.cs
Date Thu, 24 Sep 2009 20:08:55 GMT
Author: tabish
Date: Thu Sep 24 20:08:53 2009
New Revision: 818614

URL: http://svn.apache.org/viewvc?rev=818614&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQNET-189

Attempts to make the MemoryUsage class work on the Compact Framework.

Modified:
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/MemoryUsage.cs

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/MemoryUsage.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/MemoryUsage.cs?rev=818614&r1=818613&r2=818614&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/MemoryUsage.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/MemoryUsage.cs Thu Sep
24 20:08:53 2009
@@ -26,9 +26,11 @@
     /// </summary>
     public class MemoryUsage
     {
+        private readonly Atomic<bool> stopped = new Atomic<bool>(false);
         private long limit = 0;
         private long usage = 0;
-        private readonly object myLock = new object();
+        private readonly object mutex = new object();
+        AutoResetEvent waitHandle = new AutoResetEvent(false);
 
         public MemoryUsage()
         {
@@ -73,16 +75,11 @@
         /// </param>
         public void WaitForSpace( TimeSpan timeout )
         {
-            lock(this.myLock)
+            while(this.IsFull() && !stopped.Value)
             {
-                while(this.IsFull())
+                if( !waitHandle.WaitOne( (int)timeout.TotalMilliseconds, false ) )
                 {
-#if !NETCF
-                    if( !Monitor.Wait(this.myLock, timeout ) )
-#endif
-                    {
-                        return;
-                    }
+                    return;
                 }
             }
         }
@@ -113,7 +110,7 @@
                 return;
             }
 
-            lock(this.myLock)
+            lock(this.mutex)
             {
                 this.Usage += value;
             }
@@ -125,14 +122,14 @@
         /// <param name="value">
         /// A <see cref="System.Int64"/>
         /// </param>
-        public void DecreaseUsage( long value )
+        public void DecreaseUsage(long value)
         {
             if(value == 0)
             {
                 return;
             }
 
-            lock(this.myLock)
+            lock(this.mutex)
             {
                 if( value > this.Usage )
                 {
@@ -142,18 +139,23 @@
                 {
                     this.Usage -= value;
                 }
-
-#if !NETCF
-                Monitor.PulseAll(this.myLock);
-#endif
             }
+            
+            waitHandle.Set();            
         }
 
+        /// <summary>
+        /// Checks if the Usage Windows has become full, is so returns true
+        /// otherwise returns false.
+        /// </summary>
+        /// <returns>
+        /// A <see cref="System.Boolean"/>
+        /// </returns>
         public bool IsFull()
         {
             bool result = false;
 
-            lock(this.myLock)
+            lock(this.mutex)
             {
                 result = this.Usage >= this.Limit;
             }
@@ -163,12 +165,8 @@
 
         public void Stop()
         {
-            lock(this.myLock)
-            {
-#if !NETCF
-                Monitor.PulseAll(this.myLock);
-#endif
-            }
+            this.stopped.Value = true;
+            this.waitHandle.Set();
         }
     }
 }



Mime
View raw message