activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1062062 - /activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Util/MessageDispatchChannel.cs
Date Fri, 21 Jan 2011 22:43:48 GMT
Author: tabish
Date: Fri Jan 21 22:43:48 2011
New Revision: 1062062

URL: http://svn.apache.org/viewvc?rev=1062062&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQNET-309

Modified:
    activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Util/MessageDispatchChannel.cs

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Util/MessageDispatchChannel.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Util/MessageDispatchChannel.cs?rev=1062062&r1=1062061&r2=1062062&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Util/MessageDispatchChannel.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Util/MessageDispatchChannel.cs
Fri Jan 21 22:43:48 2011
@@ -25,11 +25,18 @@ namespace Apache.NMS.Stomp.Util
     public class MessageDispatchChannel
     {
         private readonly Mutex mutex = new Mutex();
-        private readonly ManualResetEvent waiter = new ManualResetEvent(false);
+        private readonly ManualResetEvent wakeAll = new ManualResetEvent(false);
+        private readonly AutoResetEvent waiter = new AutoResetEvent(false);
+        private WaitHandle[] waiters;
         private bool closed;
         private bool running;
         private readonly LinkedList<MessageDispatch> channel = new LinkedList<MessageDispatch>();
 
+        public MessageDispatchChannel()
+        {
+            this.waiters = new WaitHandle[] { this.waiter, this.wakeAll };
+        }
+
         #region Properties
 
         public object SyncRoot
@@ -106,8 +113,7 @@ namespace Apache.NMS.Stomp.Util
                 if(!Closed)
                 {
                     this.running = true;
-                    this.waiter.Set();
-                    this.waiter.Reset();
+                    this.wakeAll.Reset();
                 }
             }
         }
@@ -117,8 +123,7 @@ namespace Apache.NMS.Stomp.Util
             lock(mutex)
             {
                 this.running = false;
-                this.waiter.Set();
-                this.waiter.Reset();
+                this.wakeAll.Set();
             }
         }
 
@@ -132,7 +137,7 @@ namespace Apache.NMS.Stomp.Util
                     this.closed = true;
                 }
 
-                this.waiter.Set();
+                this.wakeAll.Set();
             }
         }
 
@@ -142,7 +147,6 @@ namespace Apache.NMS.Stomp.Util
             {
                 this.channel.AddLast(dispatch);
                 this.waiter.Set();
-                this.waiter.Reset();
             }
         }
 
@@ -152,7 +156,6 @@ namespace Apache.NMS.Stomp.Util
             {
                 this.channel.AddFirst(dispatch);
                 this.waiter.Set();
-                this.waiter.Reset();
             }
         }
 
@@ -166,7 +169,8 @@ namespace Apache.NMS.Stomp.Util
             if( timeout != TimeSpan.Zero && !Closed && ( Empty || !Running
) )
             {
                 this.mutex.ReleaseMutex();
-                this.waiter.WaitOne((int)timeout.TotalMilliseconds, false);
+                this.waiter.Reset();
+                WaitHandle.WaitAny(this.waiters, (int)timeout.TotalMilliseconds, false);
                 this.mutex.WaitOne();
             }
 



Mime
View raw message