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 2012/06/06 16:32:50 UTC

svn commit: r1346916 [1/3] - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/decaf/util/concurrent/locks/ test/decaf/util/concurrent/locks/

Author: tabish
Date: Wed Jun  6 14:32:50 2012
New Revision: 1346916

URL: http://svn.apache.org/viewvc?rev=1346916&view=rev
Log:
Unit tests for ReentrantReadWriteLock and a couple of fixes. 

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/Lock.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/Lock.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/Lock.h?rev=1346916&r1=1346915&r2=1346916&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/Lock.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/Lock.h Wed Jun  6 14:32:50 2012
@@ -281,6 +281,10 @@ namespace locks {
          */
         virtual Condition* newCondition() = 0;
 
+        /**
+         * @returns a string representation of the Lock useful for debugging purposes.
+         */
+        virtual std::string toString() const = 0;
     };
 
 }}}}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.cpp?rev=1346916&r1=1346915&r2=1346916&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.cpp Wed Jun  6 14:32:50 2012
@@ -488,7 +488,7 @@ namespace {
         }
     };
 
-    class ReadLock : public Lock {
+    class ReadLock : public decaf::util::concurrent::locks::Lock {
     public:
 
         Sync* sync;
@@ -656,11 +656,11 @@ namespace {
          */
         virtual std::string toString() const {
             int r = sync->getReadLockCount();
-            return std::string("[Read locks = ") + Integer::toString(r) + "]";
+            return std::string("ReadLock ") + "[Read locks = " + Integer::toString(r) + "]";
         }
     };
 
-    class WriteLock : public Lock {
+    class WriteLock : public decaf::util::concurrent::locks::Lock {
     public:
 
         Sync* sync;
@@ -886,8 +886,8 @@ namespace {
          */
         virtual std::string toString() const {
             Thread* o = sync->getOwner();
-            return std::string("Lock") + ((o == NULL) ? "[Unlocked]" :
-                                                        "[Locked by thread " + o->getName() + "]");
+            return std::string("WriteLock ") + ((o == NULL) ?
+                "[Unlocked]" : "[Locked by thread " + o->getName() + "]");
         }
 
         /**
@@ -923,8 +923,8 @@ namespace locks {
     class ReentrantReadWriteLockImpl {
     public:
 
-        Lock* readLock;
-        Lock* writeLock;
+        decaf::util::concurrent::locks::Lock* readLock;
+        decaf::util::concurrent::locks::Lock* writeLock;
         Sync* sync;
 
         ReentrantReadWriteLockImpl(bool fair) : readLock(NULL), writeLock(NULL), sync(NULL) {
@@ -965,13 +965,13 @@ ReentrantReadWriteLock::~ReentrantReadWr
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Lock& ReentrantReadWriteLock::readLock() {
-    throw "";
+decaf::util::concurrent::locks::Lock& ReentrantReadWriteLock::readLock() {
+    return *(this->impl->readLock);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Lock& ReentrantReadWriteLock::writeLock() {
-    throw "";
+decaf::util::concurrent::locks::Lock& ReentrantReadWriteLock::writeLock() {
+    return *(this->impl->writeLock);
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.h?rev=1346916&r1=1346915&r2=1346916&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.h Wed Jun  6 14:32:50 2012
@@ -62,12 +62,12 @@ namespace locks {
         /**
          * {@inheritDoc}
          */
-        virtual Lock& readLock();
+        virtual decaf::util::concurrent::locks::Lock& readLock();
 
         /**
          * {@inheritDoc}
          */
-        virtual Lock& writeLock();
+        virtual decaf::util::concurrent::locks::Lock& writeLock();
 
         /**
          * Returns true if this lock has fairness set true.
@@ -160,21 +160,6 @@ namespace locks {
          */
         std::string toString() const;
 
-    protected:
-
-        /**
-         * Creates and returns a new Collection object that contains all the threads that may be waiting
-         * on the given Condition object instance at the time this method is called.
-         *
-         * @returns a Collection pointer that contains waiting threads on given Condition object.
-         *          The caller owns the returned pointer.
-         *
-         * @throws NullPointerException if the ConditionObject pointer is NULL.
-         * @throws IllegalArgumentException if the ConditionObject is not associated with this Synchronizer.
-         * @throws IllegalMonitorStateException if the caller does not hold exclusive synchronization.
-         */
-        decaf::util::Collection<decaf::lang::Thread*>* getWaitingThreads(Condition* condition) const;
-
         /**
          * Queries whether any threads are waiting to acquire the read or write lock.
          * Note that because cancellations may occur at any time, a true return does
@@ -214,6 +199,19 @@ namespace locks {
     protected:
 
         /**
+         * Creates and returns a new Collection object that contains all the threads that may be waiting
+         * on the given Condition object instance at the time this method is called.
+         *
+         * @returns a Collection pointer that contains waiting threads on given Condition object.
+         *          The caller owns the returned pointer.
+         *
+         * @throws NullPointerException if the ConditionObject pointer is NULL.
+         * @throws IllegalArgumentException if the ConditionObject is not associated with this Synchronizer.
+         * @throws IllegalMonitorStateException if the caller does not hold exclusive synchronization.
+         */
+        decaf::util::Collection<decaf::lang::Thread*>* getWaitingThreads(Condition* condition) const;
+
+        /**
          * Returns a collection containing threads that may be waiting to acquire either
          * the read or write lock.  Because the actual set of threads may change dynamically
          * while constructing this result, the returned collection is only a best-effort