From commits-return-12749-apmail-activemq-commits-archive=activemq.apache.org@activemq.apache.org Mon Jan 11 21:26:31 2010 Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 40441 invoked from network); 11 Jan 2010 21:26:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 11 Jan 2010 21:26:31 -0000 Received: (qmail 36527 invoked by uid 500); 11 Jan 2010 21:26:31 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 36483 invoked by uid 500); 11 Jan 2010 21:26:31 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 36474 invoked by uid 99); 11 Jan 2010 21:26:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Jan 2010 21:26:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Jan 2010 21:26:29 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DF335238897D; Mon, 11 Jan 2010 21:26:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100111212607.DF335238897D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 channel = new LinkedList(); @@ -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()