activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r898071 - /activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Util/MessageDispatchChannel.cs
Date Mon, 11 Jan 2010 21:26:07 GMT
Author: tabish
Date: Mon Jan 11 21:26:06 2010
New Revision: 898071

URL: http://svn.apache.org/viewvc?rev=898071&view=rev
Log:
port the MessageDispatchChannel to build on .NET CF 2.0

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

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Util/MessageDispatchChannel.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Util/MessageDispatchChannel.cs?rev=898071&r1=898070&r2=898071&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Util/MessageDispatchChannel.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Util/MessageDispatchChannel.cs
Mon Jan 11 21:26:06 2010
@@ -28,6 +28,7 @@
     public class MessageDispatchChannel
     {
         private readonly Mutex mutex = new Mutex();
+        private readonly ManualResetEvent waiter = new ManualResetEvent(false);
         private bool closed;
         private bool running;
         private LinkedList<MessageDispatch> channel = new LinkedList<MessageDispatch>();
@@ -108,7 +109,8 @@
                 if(!Closed)
                 {
                     this.running = true;
-                    Monitor.PulseAll(this.mutex);
+                    this.waiter.Set();
+                    this.waiter.Reset();
                 }
             }
         }
@@ -118,7 +120,8 @@
             lock(mutex)
             {
                 this.running = false;
-                Monitor.PulseAll(this.mutex);
+                this.waiter.Set();
+                this.waiter.Reset();
             }
         }
 
@@ -132,7 +135,7 @@
                     this.closed = true;
                 }
 
-                Monitor.PulseAll(this.mutex);
+                this.waiter.Set();
             }
         }
 
@@ -141,7 +144,8 @@
             lock(this.mutex)
             {
                 this.channel.AddLast(dispatch);
-                Monitor.Pulse(this.mutex);
+                this.waiter.Set();
+                this.waiter.Reset();
             }
         }
 
@@ -150,27 +154,33 @@
             lock(this.mutex)
             {
                 this.channel.AddFirst(dispatch);
-                Monitor.Pulse(this.mutex);
+                this.waiter.Set();
+                this.waiter.Reset();
             }
         }
 
         public MessageDispatch Dequeue(TimeSpan timeout)
         {
-            lock(this.mutex)
-            {
-                // Wait until the channel is ready to deliver messages.
-                if( timeout != TimeSpan.Zero && !Closed && ( Empty || !Running
) )
-                {
-                    Monitor.Wait(this.mutex, timeout);
-                }
+            MessageDispatch result = null;
 
-                if( Closed || !Running || Empty )
-                {
-                    return null;
-                }
+            this.mutex.WaitOne();
+
+            // Wait until the channel is ready to deliver messages.
+            if( timeout != TimeSpan.Zero && !Closed && ( Empty || !Running
) )
+            {
+                this.mutex.ReleaseMutex();
+                this.waiter.WaitOne(timeout, false);
+                this.mutex.WaitOne();
+            }
 
-                return DequeueNoWait();
+            if( !Closed && Running && !Empty )
+            {
+                result = DequeueNoWait();
             }
+
+            this.mutex.ReleaseMutex();
+
+            return result;
         }
 
         public MessageDispatch DequeueNoWait()



Mime
View raw message