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 2010/01/28 16:54:24 UTC
svn commit: r904141 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent:
CountDownLatch.cpp CountDownLatch.h
Author: tabish
Date: Thu Jan 28 15:54:24 2010
New Revision: 904141
URL: http://svn.apache.org/viewvc?rev=904141&view=rev
Log:
Improve the CountDownLatch API and documentation.
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/CountDownLatch.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/CountDownLatch.h
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/CountDownLatch.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/CountDownLatch.cpp?rev=904141&r1=904140&r2=904141&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/CountDownLatch.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/CountDownLatch.cpp Thu Jan 28 15:54:24 2010
@@ -19,18 +19,17 @@
using namespace decaf;
using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
using namespace decaf::util;
using namespace decaf::util::concurrent;
////////////////////////////////////////////////////////////////////////////////
-CountDownLatch::CountDownLatch( int count )
-{
+CountDownLatch::CountDownLatch( int count ) {
this->count = count;
}
////////////////////////////////////////////////////////////////////////////////
-CountDownLatch::~CountDownLatch()
-{
+CountDownLatch::~CountDownLatch() {
try {
synchronized( &mutex ) {
@@ -41,7 +40,9 @@
}
////////////////////////////////////////////////////////////////////////////////
-void CountDownLatch::await() throw ( lang::Exception ) {
+void CountDownLatch::await()
+ throw ( decaf::lang::exceptions::InterruptedException,
+ decaf::lang::Exception ) {
try {
@@ -53,12 +54,16 @@
mutex.wait();
}
}
- DECAF_CATCH_RETHROW( lang::Exception )
- DECAF_CATCHALL_THROW( lang::Exception )
+ DECAF_CATCH_RETHROW( decaf::lang::exceptions::InterruptedException )
+ DECAF_CATCH_RETHROW( decaf::lang::Exception )
+ DECAF_CATCHALL_THROW( decaf::lang::Exception )
}
////////////////////////////////////////////////////////////////////////////////
-bool CountDownLatch::await( unsigned long timeOut ) throw ( lang::Exception ) {
+bool CountDownLatch::await( unsigned long timeOut )
+ throw ( decaf::lang::exceptions::InterruptedException,
+ decaf::lang::Exception ) {
+
try {
synchronized( &mutex ) {
@@ -73,8 +78,22 @@
return true;
}
- DECAF_CATCH_RETHROW( lang::Exception )
- DECAF_CATCHALL_THROW( lang::Exception )
+ DECAF_CATCH_RETHROW( decaf::lang::exceptions::InterruptedException )
+ DECAF_CATCH_RETHROW( decaf::lang::Exception )
+ DECAF_CATCHALL_THROW( decaf::lang::Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CountDownLatch::await( long long timeout, const TimeUnit& unit )
+ throw ( decaf::lang::exceptions::InterruptedException,
+ decaf::lang::Exception ) {
+
+ try{
+ return this->await( unit.toMillis( timeout ) );
+ }
+ DECAF_CATCH_RETHROW( decaf::lang::exceptions::InterruptedException )
+ DECAF_CATCH_RETHROW( decaf::lang::Exception )
+ DECAF_CATCHALL_THROW( decaf::lang::Exception )
}
////////////////////////////////////////////////////////////////////////////////
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/CountDownLatch.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/CountDownLatch.h?rev=904141&r1=904140&r2=904141&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/CountDownLatch.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/CountDownLatch.h Thu Jan 28 15:54:24 2010
@@ -19,7 +19,9 @@
#define _DECAF_CONCURRENT_COUNTDOWNLATCH_H_
#include <decaf/util/concurrent/Mutex.h>
+#include <decaf/util/concurrent/TimeUnit.h>
#include <decaf/util/Config.h>
+#include <decaf/lang/exceptions/InterruptedException.h>
#include <decaf/lang/Exception.h>
namespace decaf{
@@ -50,17 +52,99 @@
virtual ~CountDownLatch();
/**
- * Waits for the Count to be zero, and then returns
- * @throws Exception
- */
- virtual void await() throw ( lang::Exception );
-
- /**
- * 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 bool await( unsigned long timeOut ) throw ( lang::Exception );
+ * Causes the current thread to wait until the latch has counted down to zero, unless
+ * the thread is interrupted.
+ *
+ * If the current count is zero then this method returns immediately.
+ *
+ * If the current count is greater than zero then the current thread becomes disabled
+ * for thread scheduling purposes and lies dormant until one of two things happen:
+ *
+ * * The count reaches zero due to invocations of the countDown() method; or
+ * * Some other thread interrupts the current thread.
+ *
+ * If the current thread:
+ *
+ * * has its interrupted status set on entry to this method; or
+ * * is interrupted while waiting,
+ *
+ * then InterruptedException is thrown and the current thread's interrupted status
+ * is cleared.
+ *
+ * @throws InterruptedException - if the current thread is interrupted while waiting.
+ * @throws Exception - if any other error occurs.
+ */
+ virtual void await() throw ( decaf::lang::exceptions::InterruptedException,
+ decaf::lang::Exception );
+
+ /**
+ * Causes the current thread to wait until the latch has counted down to zero, unless the
+ * thread is interrupted, or the specified waiting time elapses.
+ *
+ * If the current count is zero then this method returns immediately with the value true.
+ *
+ * If the current count is greater than zero then the current thread becomes disabled for
+ * thread scheduling purposes and lies dormant until one of three things happen:
+ *
+ * * The count reaches zero due to invocations of the countDown() method; or
+ * * Some other thread interrupts the current thread; or
+ * * The specified waiting time elapses.
+ *
+ * If the count reaches zero then the method returns with the value true.
+ *
+ * If the current thread:
+ *
+ * * has its interrupted status set on entry to this method; or
+ * * is interrupted while waiting,
+ *
+ * then InterruptedException is thrown and the current thread's interrupted status is cleared.
+ *
+ * If the specified waiting time elapses then the value false is returned. If the time is
+ * less than or equal to zero, the method will not wait at all.
+ *
+ * @param timeout - Time in milliseconds to wait for the count to reach zero.
+ *
+ * @throws InterruptedException - if the current thread is interrupted while waiting.
+ * @throws Exception - if any other error occurs.
+ */
+ virtual bool await( unsigned long timeOut )
+ throw ( decaf::lang::exceptions::InterruptedException,
+ decaf::lang::Exception );
+
+ /**
+ * Causes the current thread to wait until the latch has counted down to zero, unless the
+ * thread is interrupted, or the specified waiting time elapses.
+ *
+ * If the current count is zero then this method returns immediately with the value true.
+ *
+ * If the current count is greater than zero then the current thread becomes disabled for
+ * thread scheduling purposes and lies dormant until one of three things happen:
+ *
+ * * The count reaches zero due to invocations of the countDown() method; or
+ * * Some other thread interrupts the current thread; or
+ * * The specified waiting time elapses.
+ *
+ * If the count reaches zero then the method returns with the value true.
+ *
+ * If the current thread:
+ *
+ * * has its interrupted status set on entry to this method; or
+ * * is interrupted while waiting,
+ *
+ * then InterruptedException is thrown and the current thread's interrupted status is cleared.
+ *
+ * If the specified waiting time elapses then the value false is returned. If the time is
+ * less than or equal to zero, the method will not wait at all.
+ *
+ * @param timeout - Time to wait for the count to reach zero.
+ * @param unit - The units that the timeout specifies.
+ *
+ * @throws InterruptedException - if the current thread is interrupted while waiting.
+ * @throws Exception - if any other error occurs.
+ */
+ virtual bool await( long long timeout, const TimeUnit& unit )
+ throw ( decaf::lang::exceptions::InterruptedException,
+ decaf::lang::Exception );
/**
* Counts down the latch, releasing all waiting threads when