activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r814892 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/activemq/core/ main/activemq/util/ main/decaf/internal/util/concurrent/ main/decaf/io/ main/decaf/net/ main/decaf/util/ main/decaf/util/concurrent/ test/decaf/io/ test/decaf/u...
Date Mon, 14 Sep 2009 22:30:32 GMT
Author: tabish
Date: Mon Sep 14 22:30:31 2009
New Revision: 814892

URL: http://svn.apache.org/viewvc?rev=814892&view=rev
Log:
Do an initial refactor of the mutex class to remove the APR and other members from the header
and hide that all in the Impl.  Add a tryLock method to Synchronizable.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/MessageDispatchChannel.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveValueNode.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/SynchronizableImpl.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/SynchronizableImpl.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BlockingByteArrayInputStream.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayOutputStream.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterInputStream.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterOutputStream.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketInputStream.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOutputStream.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractCollection.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlMap.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlQueue.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentStlMap.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Synchronizable.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedInputStreamTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ByteArrayInputStreamTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ByteArrayOutputStreamTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/DataInputStreamTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/DataOutputStreamTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/FilterInputStreamTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/MessageDispatchChannel.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/MessageDispatchChannel.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/MessageDispatchChannel.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/MessageDispatchChannel.h
Mon Sep 14 22:30:31 2009
@@ -147,6 +147,10 @@
             channel.lock();
         }
 
+        virtual bool tryLock() throw( decaf::lang::Exception ) {
+            return channel.tryLock();
+        }
+
         virtual void unlock() throw( decaf::lang::Exception ){
             channel.unlock();
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveValueNode.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveValueNode.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveValueNode.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveValueNode.cpp
Mon Sep 14 22:30:31 2009
@@ -23,6 +23,13 @@
 #include <decaf/util/StlMap.h>
 #include <decaf/util/StlList.h>
 
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
 using namespace std;
 using namespace activemq;
 using namespace activemq::util;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/SynchronizableImpl.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/SynchronizableImpl.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/SynchronizableImpl.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/SynchronizableImpl.cpp
Mon Sep 14 22:30:31 2009
@@ -34,6 +34,11 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+bool SynchronizableImpl::tryLock() throw( lang::Exception ) {
+    return mutex.tryLock();
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void SynchronizableImpl::unlock() throw( lang::Exception ) {
     mutex.unlock();
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/SynchronizableImpl.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/SynchronizableImpl.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/SynchronizableImpl.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/SynchronizableImpl.h
Mon Sep 14 22:30:31 2009
@@ -45,6 +45,8 @@
 
         virtual void lock() throw( lang::Exception );
 
+        virtual bool tryLock() throw( lang::Exception );
+
         virtual void unlock() throw( lang::Exception );
 
         virtual void wait() throw( lang::Exception );

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BlockingByteArrayInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BlockingByteArrayInputStream.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BlockingByteArrayInputStream.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BlockingByteArrayInputStream.h
Mon Sep 14 22:30:31 2009
@@ -199,6 +199,10 @@
             mutex.lock();
         }
 
+        virtual bool tryLock() throw( lang::Exception ) {
+            return mutex.tryLock();
+        }
+
         virtual void unlock() throw( lang::Exception ){
             mutex.unlock();
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp Mon
Sep 14 22:30:31 2009
@@ -18,6 +18,13 @@
 #include "BufferedInputStream.h"
 #include <algorithm>
 
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
 using namespace std;
 using namespace decaf;
 using namespace decaf::io;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.cpp Mon
Sep 14 22:30:31 2009
@@ -18,6 +18,13 @@
 #include "BufferedOutputStream.h"
 #include <algorithm>
 
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
 using namespace std;
 using namespace decaf;
 using namespace decaf::io;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.h Mon
Sep 14 22:30:31 2009
@@ -201,6 +201,10 @@
             mutex.lock();
         }
 
+        virtual bool tryLock() throw( lang::Exception ) {
+            return mutex.tryLock();
+        }
+
         virtual void unlock() throw( lang::Exception ){
             mutex.unlock();
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayOutputStream.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayOutputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayOutputStream.h Mon
Sep 14 22:30:31 2009
@@ -154,6 +154,10 @@
             mutex.lock();
         }
 
+        virtual bool tryLock() throw( lang::Exception ) {
+            return mutex.tryLock();
+        }
+
         virtual void unlock() throw( lang::Exception ){
             mutex.unlock();
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp Mon Sep
14 22:30:31 2009
@@ -17,6 +17,13 @@
 
 #include <decaf/io/DataInputStream.h>
 
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
 using namespace std;
 using namespace decaf;
 using namespace decaf::io;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterInputStream.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterInputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterInputStream.h Mon Sep
14 22:30:31 2009
@@ -285,6 +285,10 @@
             mutex.lock();
         }
 
+        virtual bool tryLock() throw( lang::Exception ) {
+            return mutex.tryLock();
+        }
+
         virtual void unlock() throw( lang::Exception ){
             mutex.unlock();
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterOutputStream.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterOutputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterOutputStream.h Mon Sep
14 22:30:31 2009
@@ -216,6 +216,10 @@
             mutex.lock();
         }
 
+        virtual bool tryLock() throw( lang::Exception ) {
+            return mutex.tryLock();
+        }
+
         virtual void unlock() throw( lang::Exception ){
             mutex.unlock();
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketInputStream.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketInputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketInputStream.h Mon Sep
14 22:30:31 2009
@@ -155,6 +155,10 @@
             mutex.lock();
         }
 
+        virtual bool tryLock() throw( lang::Exception ) {
+            return mutex.tryLock();
+        }
+
         virtual void unlock() throw( lang::Exception ){
             mutex.unlock();
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOutputStream.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOutputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOutputStream.h Mon Sep
14 22:30:31 2009
@@ -94,6 +94,10 @@
             mutex.lock();
         }
 
+        virtual bool tryLock() throw( lang::Exception ) {
+            return mutex.tryLock();
+        }
+
         virtual void unlock() throw( lang::Exception ){
             mutex.unlock();
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractCollection.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractCollection.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractCollection.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractCollection.h Mon
Sep 14 22:30:31 2009
@@ -423,6 +423,10 @@
             mutex.lock();
         }
 
+        virtual bool tryLock() throw( lang::Exception ) {
+            return mutex.tryLock();
+        }
+
         virtual void unlock() throw( lang::Exception ) {
             mutex.unlock();
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Date.cpp Mon Sep 14 22:30:31
2009
@@ -20,6 +20,8 @@
 #include <decaf/lang/exceptions/UnsupportedOperationException.h>
 #include <decaf/lang/System.h>
 
+#include <apr_time.h>
+
 using namespace std;
 using namespace decaf;
 using namespace decaf::util;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlMap.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlMap.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlMap.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlMap.h Mon Sep 14 22:30:31
2009
@@ -280,6 +280,10 @@
             mutex.lock();
         }
 
+        virtual bool tryLock() throw( lang::Exception ) {
+            return mutex.tryLock();
+        }
+
         virtual void unlock() throw( lang::Exception ) {
             mutex.unlock();
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlQueue.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlQueue.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlQueue.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlQueue.h Mon Sep 14 22:30:31
2009
@@ -253,6 +253,10 @@
             mutex.lock();
         }
 
+        virtual bool tryLock() throw( lang::Exception ) {
+            return mutex.tryLock();
+        }
+
         virtual void unlock() throw( lang::Exception ){
             mutex.unlock();
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentStlMap.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentStlMap.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentStlMap.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentStlMap.h
Mon Sep 14 22:30:31 2009
@@ -462,6 +462,10 @@
             mutex.lock();
         }
 
+        virtual bool tryLock() throw( lang::Exception ) {
+            return mutex.tryLock();
+        }
+
         virtual void unlock() throw( lang::Exception ) {
             mutex.unlock();
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp Mon
Sep 14 22:30:31 2009
@@ -19,6 +19,12 @@
 
 #include <apr_errno.h>
 #include <apr_time.h>
+#include <apr_thread_mutex.h>
+#include <apr_thread_cond.h>
+
+#include <decaf/internal/AprPool.h>
+
+#include <list>
 
 using namespace decaf;
 using namespace decaf::internal;
@@ -26,11 +32,45 @@
 using namespace decaf::util::concurrent;
 
 ////////////////////////////////////////////////////////////////////////////////
+namespace decaf{
+namespace util{
+namespace concurrent{
+
+    class MutexProperties {
+    public:
+
+        MutexProperties() {
+            this->mutex = NULL;
+            this->lock_owner = 0;
+            this->lock_count = 0;
+        }
+
+        // Our one and only APR Pool
+        internal::AprPool aprPool;
+
+        // The mutex object.
+        apr_thread_mutex_t* mutex;
+
+        // List of waiting threads
+        std::list<apr_thread_cond_t*> eventQ;
+
+        // Lock Status Members
+        volatile long long lock_owner;
+        volatile long long lock_count;
+
+    };
+
+}}}
+
+////////////////////////////////////////////////////////////////////////////////
 Mutex::Mutex() {
 
-    apr_thread_mutex_create( &mutex, APR_THREAD_MUTEX_NESTED, aprPool.getAprPool() );
-    this->lock_owner = 0;
-    this->lock_count = 0;
+    this->properties.reset( new MutexProperties );
+
+    // Allocate the OS Mutex Implementation.
+    apr_thread_mutex_create( &( properties->mutex ),
+                             APR_THREAD_MUTEX_NESTED,
+                             properties->aprPool.getAprPool() );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -42,23 +82,49 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+bool Mutex::isLockOwner() const {
+    return properties->lock_owner == lang::Thread::getId();
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void Mutex::lock() throw( lang::Exception ) {
 
     long long threadId = lang::Thread::getId();
 
-    if( threadId == lock_owner ) {
-        lock_count++;
+    if( threadId == properties->lock_owner ) {
+        properties->lock_count++;
     } else {
-        apr_thread_mutex_lock( mutex );
-        lock_owner = threadId;
-        lock_count = 1;
+        apr_thread_mutex_lock( properties->mutex );
+        properties->lock_owner = threadId;
+        properties->lock_count = 1;
     }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+bool Mutex::tryLock() throw( lang::Exception ) {
+
+    long long threadId = lang::Thread::getId();
+
+    if( threadId == properties->lock_owner ) {
+        properties->lock_count++;
+    } else {
+
+        if( apr_thread_mutex_trylock( properties->mutex ) == APR_SUCCESS ) {
+            properties->lock_owner = threadId;
+            properties->lock_count = 1;
+        } else {
+            return false;
+        }
+    }
+
+    return true;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
 void Mutex::unlock() throw( lang::Exception ) {
 
-    if( lock_owner == 0 ) {
+    if( properties->lock_owner == 0 ) {
         return;
     }
 
@@ -68,11 +134,11 @@
             "Mutex::unlock - Failed, not Lock Owner!" );
     }
 
-    lock_count--;
+    properties->lock_count--;
 
-    if(lock_count == 0) {
-        lock_owner = 0;
-        apr_thread_mutex_unlock( mutex );
+    if( properties->lock_count == 0 ) {
+        properties->lock_owner = 0;
+        apr_thread_mutex_unlock( properties->mutex );
     }
 }
 
@@ -94,31 +160,31 @@
     // Save the current owner as we are going to unlock and release for
     // someone else to lock on potentially.  When we come back and
     // re-lock we want to restore to the state we were in before.
-    long long lock_owner = this->lock_owner;
-    long long lock_count = this->lock_count;
+    long long lock_owner = this->properties->lock_owner;
+    long long lock_count = this->properties->lock_count;
 
-    this->lock_owner = 0;
-    this->lock_count = 0;
+    this->properties->lock_owner = 0;
+    this->properties->lock_count = 0;
 
     // Create this threads wait event
     apr_thread_cond_t* waitEvent = NULL;
     apr_pool_t *subPool = NULL;
-    apr_pool_create_ex( &subPool, aprPool.getAprPool(), NULL, NULL );
+    apr_pool_create_ex( &subPool, properties->aprPool.getAprPool(), NULL, NULL );
     apr_thread_cond_create( &waitEvent, subPool );
 
     // Store the event in the queue so that a notify can
     // call it and wake up the thread.
-    eventQ.push_back( waitEvent );
+    properties->eventQ.push_back( waitEvent );
 
     if( millisecs != WAIT_INFINITE ) {
         apr_interval_time_t wait = millisecs * 1000;
-        apr_thread_cond_timedwait( waitEvent, mutex, wait );
+        apr_thread_cond_timedwait( waitEvent, properties->mutex, wait );
     } else {
-        apr_thread_cond_wait( waitEvent, mutex );
+        apr_thread_cond_wait( waitEvent, properties->mutex );
     }
 
     // Be Sure that the event is now removed
-    eventQ.remove( waitEvent );
+    properties->eventQ.remove( waitEvent );
 
     // Destroy our wait event now, the notify method will have removed it
     // from the event queue.
@@ -126,8 +192,8 @@
     apr_pool_destroy( subPool );
 
     // restore the owner
-    this->lock_owner = lock_owner;
-    this->lock_count = lock_count;
+    this->properties->lock_owner = lock_owner;
+    this->properties->lock_count = lock_count;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -145,9 +211,9 @@
             "Mutex::Notify - Failed, not Lock Owner!" );
     }
 
-    if( !eventQ.empty() ) {
-        apr_thread_cond_t* event = eventQ.front();
-        eventQ.remove( event );
+    if( !properties->eventQ.empty() ) {
+        apr_thread_cond_t* event = properties->eventQ.front();
+        properties->eventQ.remove( event );
         apr_thread_cond_signal( event );
     }
 }
@@ -161,9 +227,9 @@
             "Mutex::NotifyAll - Failed, not Lock Owner!" );
     }
 
-    while( !eventQ.empty() ) {
-        apr_thread_cond_t* event = eventQ.front();
-        eventQ.remove( event );
+    while( !properties->eventQ.empty() ) {
+        apr_thread_cond_t* event = properties->eventQ.front();
+        properties->eventQ.remove( event );
         apr_thread_cond_signal( event );
     }
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.h Mon Sep
14 22:30:31 2009
@@ -22,39 +22,24 @@
 #include <decaf/util/concurrent/Concurrent.h>
 #include <decaf/lang/Thread.h>
 #include <decaf/util/Config.h>
-#include <decaf/internal/AprPool.h>
 
-#include <apr_thread_mutex.h>
-#include <apr_thread_cond.h>
-
-#include <list>
-#include <assert.h>
+#include <memory>
 
 namespace decaf{
 namespace util{
 namespace concurrent{
 
+    class MutexProperties;
+
     /**
      * Creates a pthread_mutex_t object. The object is created
      * such that successive locks from the same thread is allowed
      * and will be successful.
-     * @see  pthread_mutex_t
      */
     class DECAF_API Mutex : public Synchronizable {
     private:
 
-        // Our one and only APR Pool
-        internal::AprPool aprPool;
-
-        // The mutex object.
-        apr_thread_mutex_t* mutex;
-
-        // List of waiting threads
-        std::list<apr_thread_cond_t*> eventQ;
-
-        // Lock Status Members
-        volatile long long lock_owner;
-        volatile long long lock_count;
+        std::auto_ptr<MutexProperties> properties;
 
     private:
 
@@ -69,6 +54,8 @@
 
         virtual void lock() throw( lang::Exception );
 
+        virtual bool tryLock() throw( lang::Exception );
+
         virtual void unlock() throw( lang::Exception );
 
         virtual void wait() throw( lang::Exception );
@@ -87,9 +74,7 @@
          * Check if the calling thread is the Lock Owner
          * @retun true if the caller is the lock owner
          */
-        bool isLockOwner(){
-            return lock_owner == lang::Thread::getId();
-        }
+        bool isLockOwner() const;
 
     };
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Synchronizable.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Synchronizable.h?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Synchronizable.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Synchronizable.h
Mon Sep 14 22:30:31 2009
@@ -43,6 +43,15 @@
         virtual void lock() throw( lang::Exception ) = 0;
 
         /**
+         * Attempts to Lock the object, if the lock is already held by another
+         * thread than this method returns false.
+         *
+         * @return true if the lock was acquired, false if it is already held by another
thread.
+         * @throws Exception
+         */
+        virtual bool tryLock() throw( lang::Exception ) = 0;
+
+        /**
          * Unlocks the object.
          * @throws Exception
          */

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedInputStreamTest.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedInputStreamTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedInputStreamTest.cpp
Mon Sep 14 22:30:31 2009
@@ -19,6 +19,13 @@
 #include <decaf/io/ByteArrayInputStream.h>
 #include <decaf/lang/exceptions/NullPointerException.h>
 
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
 using namespace std;
 using namespace decaf;
 using namespace decaf::lang;
@@ -132,6 +139,9 @@
 
         virtual void lock() throw( lang::Exception ) {
         }
+        virtual bool tryLock() throw( lang::Exception ) {
+            return false;
+        }
         virtual void unlock() throw( lang::Exception ) {
         }
         virtual void wait() throw( lang::Exception ) {

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp
Mon Sep 14 22:30:31 2009
@@ -83,6 +83,9 @@
 
         virtual void lock() throw( lang::Exception ) {
         }
+        virtual bool tryLock() throw( lang::Exception ) {
+            return false;
+        }
         virtual void unlock() throw( lang::Exception ) {
         }
         virtual void wait() throw( lang::Exception ) {

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ByteArrayInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ByteArrayInputStreamTest.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ByteArrayInputStreamTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ByteArrayInputStreamTest.cpp
Mon Sep 14 22:30:31 2009
@@ -17,6 +17,13 @@
 
 #include "ByteArrayInputStreamTest.h"
 
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
 using namespace std;
 using namespace decaf;
 using namespace decaf::lang;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ByteArrayOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ByteArrayOutputStreamTest.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ByteArrayOutputStreamTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ByteArrayOutputStreamTest.cpp
Mon Sep 14 22:30:31 2009
@@ -17,6 +17,13 @@
 
 #include "ByteArrayOutputStreamTest.h"
 
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
 using namespace std;
 using namespace decaf;
 using namespace decaf::lang;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/DataInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/DataInputStreamTest.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/DataInputStreamTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/DataInputStreamTest.cpp Mon
Sep 14 22:30:31 2009
@@ -19,6 +19,13 @@
 
 #include <decaf/lang/Integer.h>
 
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
 using namespace std;
 using namespace decaf;
 using namespace decaf::lang;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/DataOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/DataOutputStreamTest.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/DataOutputStreamTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/DataOutputStreamTest.cpp Mon
Sep 14 22:30:31 2009
@@ -17,6 +17,13 @@
 
 #include "DataOutputStreamTest.h"
 
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
 using namespace std;
 using namespace decaf;
 using namespace decaf::lang;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/FilterInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/FilterInputStreamTest.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/FilterInputStreamTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/FilterInputStreamTest.cpp Mon
Sep 14 22:30:31 2009
@@ -129,6 +129,9 @@
 
         virtual void lock() throw( lang::Exception ) {
         }
+        virtual bool tryLock() throw( lang::Exception ) {
+            return false;
+        }
         virtual void unlock() throw( lang::Exception ) {
         }
         virtual void wait() throw( lang::Exception ) {

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp Mon Sep 14
22:30:31 2009
@@ -255,6 +255,10 @@
         mutex.lock();
     }
 
+    virtual bool tryLock() throw( lang::Exception ) {
+        return mutex.tryLock();
+    }
+
     virtual void unlock() throw( lang::Exception ) {
         mutex.unlock();
     }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp?rev=814892&r1=814891&r2=814892&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp
Mon Sep 14 22:30:31 2009
@@ -38,6 +38,9 @@
     virtual void lock() throw(lang::Exception){
         mutex.lock();
     }
+    virtual bool tryLock() throw( lang::Exception ) {
+        return mutex.tryLock();
+    }
     virtual void unlock() throw(lang::Exception){
         mutex.unlock();
     }
@@ -103,6 +106,9 @@
     virtual void unlock() throw(lang::Exception){
         mutex.unlock();
     }
+    virtual bool tryLock() throw( lang::Exception ) {
+        return mutex.tryLock();
+    }
     virtual void wait() throw(lang::Exception){
         mutex.wait();
     }
@@ -182,6 +188,9 @@
     virtual void lock() throw(lang::Exception){
         mutex.lock();
     }
+    virtual bool tryLock() throw( lang::Exception ) {
+        return mutex.tryLock();
+    }
     virtual void unlock() throw(lang::Exception){
         mutex.unlock();
     }
@@ -259,6 +268,9 @@
     virtual void lock() throw(lang::Exception){
         mutex->lock();
     }
+    virtual bool tryLock() throw( lang::Exception ) {
+        return mutex->tryLock();
+    }
     virtual void unlock() throw(lang::Exception){
         mutex->unlock();
     }
@@ -475,6 +487,9 @@
     virtual void lock() throw(lang::Exception){
         mutex->lock();
     }
+    virtual bool tryLock() throw( lang::Exception ) {
+        return mutex->tryLock();
+    }
     virtual void unlock() throw(lang::Exception){
         mutex->unlock();
     }



Mime
View raw message