You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2011/01/21 23:43:48 UTC

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

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();
             }