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 2007/02/10 02:07:14 UTC
svn commit: r505598 - in /activemq/activemq-cpp/trunk/activemq-cpp/src:
main/activemq/concurrent/ main/activemq/connector/openwire/
test/activemq/concurrent/
Author: tabish
Date: Fri Feb 9 17:07:13 2007
New Revision: 505598
URL: http://svn.apache.org/viewvc?view=rev&rev=505598
Log:
http://issues.apache.org/activemq/browse/AMQCPP-30
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/CountDownLatch.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/CountDownLatch.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.h
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/concurrent/CountDownLatchTest.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/concurrent/CountDownLatchTest.h
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/CountDownLatch.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/CountDownLatch.cpp?view=diff&rev=505598&r1=505597&r2=505598
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/CountDownLatch.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/CountDownLatch.cpp Fri Feb 9 17:07:13 2007
@@ -56,16 +56,20 @@
}
////////////////////////////////////////////////////////////////////////////////
-void CountDownLatch::await( unsigned long timeOut ) throw ( cms::CMSException ) {
+bool CountDownLatch::await( unsigned long timeOut ) throw ( cms::CMSException ) {
try {
synchronized( &mutex ) {
if( count == 0 ){
- return;
+ return true;
}
mutex.wait( timeOut );
+
+ return count == 0;
}
+
+ return true;
}
AMQ_CATCH_RETHROW( exceptions::ActiveMQException )
AMQ_CATCHALL_THROW( exceptions::ActiveMQException )
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/CountDownLatch.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/CountDownLatch.h?view=diff&rev=505598&r1=505597&r2=505598
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/CountDownLatch.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/CountDownLatch.h Fri Feb 9 17:07:13 2007
@@ -56,8 +56,9 @@
/**
* Waits for the Count to hit zero, or a timeout.
* @param timeOut - time in milliseconds to wait.
+ * @returns true if the wait made it to count zero, otherwise false
*/
- virtual void await( unsigned long timeOut ) throw ( cms::CMSException );
+ virtual bool await( unsigned long timeOut ) throw ( cms::CMSException );
/**
* Counts down the latch, releasing all waiting threads when
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.cpp?view=diff&rev=505598&r1=505597&r2=505598
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.cpp Fri Feb 9 17:07:13 2007
@@ -20,6 +20,7 @@
using namespace activemq;
using namespace activemq::exceptions;
using namespace activemq::transport;
+using namespace activemq::concurrent;
using namespace activemq::connector;
using namespace activemq::connector::openwire;
@@ -27,7 +28,9 @@
OpenWireFormatNegotiator::OpenWireFormatNegotiator( OpenWireFormat* openWireFormat,
Transport* next,
const bool own ) :
- TransportFilter( next, own )
+ TransportFilter( next, own ),
+ wireInfoSentDownLatch(1),
+ readyCountDownLatch(1)
{
this->firstTime = true;
this->openWireFormat = openWireFormat;
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.h?view=diff&rev=505598&r1=505597&r2=505598
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.h Fri Feb 9 17:07:13 2007
@@ -21,6 +21,7 @@
#include <activemq/transport/TransportFilter.h>
#include <activemq/transport/Command.h>
#include <activemq/concurrent/Mutex.h>
+#include <activemq/concurrent/CountDownLatch.h>
#include <activemq/concurrent/Concurrent.h>
#include <activemq/connector/openwire/OpenWireFormat.h>
@@ -41,6 +42,12 @@
* Have we started already?
*/
bool firstTime;
+
+ /**
+ * Latch to count down till we receive the wireFormat info
+ */
+ concurrent::CountDownLatch wireInfoSentDownLatch;
+ concurrent::CountDownLatch readyCountDownLatch;
/**
* The OpenWireFormat object that we use in negotiation.
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/concurrent/CountDownLatchTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/concurrent/CountDownLatchTest.cpp?view=diff&rev=505598&r1=505597&r2=505598
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/concurrent/CountDownLatchTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/concurrent/CountDownLatchTest.cpp Fri Feb 9 17:07:13 2007
@@ -41,3 +41,25 @@
CPPUNIT_ASSERT( true );
}
+
+////////////////////////////////////////////////////////////////////////////////
+void CountDownLatchTest::test2()
+{
+ CountDownLatch latch( 75 );
+
+ CPPUNIT_ASSERT( latch.getCount() == 75 );
+
+ MyThread thread;
+ thread.latch = &latch;
+ thread.start();
+
+ CPPUNIT_ASSERT( latch.await( 2 ) == false );
+
+ latch.await();
+
+ CPPUNIT_ASSERT( latch.getCount() == 0 );
+
+ thread.join();
+
+ CPPUNIT_ASSERT( true );
+}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/concurrent/CountDownLatchTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/concurrent/CountDownLatchTest.h?view=diff&rev=505598&r1=505597&r2=505598
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/concurrent/CountDownLatchTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/concurrent/CountDownLatchTest.h Fri Feb 9 17:07:13 2007
@@ -31,6 +31,7 @@
CPPUNIT_TEST_SUITE( CountDownLatchTest );
CPPUNIT_TEST( test );
+ CPPUNIT_TEST( test2 );
CPPUNIT_TEST_SUITE_END();
protected:
@@ -51,7 +52,7 @@
while( latch->getCount() > 0 ) {
latch->countDown();
- Thread::sleep( 10 );
+ Thread::sleep( 20 );
}
}
@@ -63,6 +64,7 @@
virtual ~CountDownLatchTest() {}
virtual void test();
+ virtual void test2();
};
}}