activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1042231 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent: Mutex.cpp Mutex.h
Date Sat, 04 Dec 2010 20:04:18 GMT
Author: tabish
Date: Sat Dec  4 20:04:18 2010
New Revision: 1042231

URL: http://svn.apache.org/viewvc?rev=1042231&view=rev
Log:
Allow a Mutex to have a unique name.

Modified:
    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

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=1042231&r1=1042230&r2=1042231&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 Sat
Dec  4 20:04:18 2010
@@ -19,6 +19,7 @@
 
 #include <decaf/internal/util/concurrent/MutexImpl.h>
 #include <decaf/internal/util/concurrent/ConditionImpl.h>
+#include <decaf/lang/Integer.h>
 
 #include <list>
 
@@ -28,6 +29,7 @@ using namespace decaf::internal::util;
 using namespace decaf::internal::util::concurrent;
 using namespace decaf::util;
 using namespace decaf::util::concurrent;
+using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -38,21 +40,40 @@ namespace concurrent{
     class MutexProperties {
     public:
 
-        MutexProperties() {}
+        MutexProperties( const std::string& name ) : mutex( NULL ), condition( NULL ),
name( name ) {
+            if( this->name.empty() ) {
+                this->name = std::string( "Mutex-" ) + Integer::toString( ++id );
+            }
+        }
 
         // The Platform Mutex object and an associated Condition Object
         // for use in the wait / notify pattern.
         MutexHandle* mutex;
         ConditionHandle* condition;
+        std::string name;
+
+        static unsigned int id;
 
     };
 
+    unsigned int MutexProperties::id = 0;
+
 }}}
 
 ////////////////////////////////////////////////////////////////////////////////
-Mutex::Mutex() {
+Mutex::Mutex() : Synchronizable(), properties( NULL ) {
+
+    this->properties = new MutexProperties("");
+
+    // Allocate the OS Mutex Implementation.
+    this->properties->mutex = MutexImpl::create();
+    this->properties->condition = ConditionImpl::create( this->properties->mutex
);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Mutex::Mutex( const std::string& name ) : Synchronizable(), properties( NULL ) {
 
-    this->properties = new MutexProperties();
+    this->properties = new MutexProperties( name );
 
     // Allocate the OS Mutex Implementation.
     this->properties->mutex = MutexImpl::create();
@@ -61,6 +82,7 @@ Mutex::Mutex() {
 
 ////////////////////////////////////////////////////////////////////////////////
 Mutex::~Mutex() {
+
     unlock();
 
     ConditionImpl::destroy( this->properties->condition );
@@ -70,32 +92,37 @@ Mutex::~Mutex() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Mutex::lock() {
+std::string Mutex::getName() const {
+    return this->properties->name;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Mutex::toString() const {
+    return this->properties->name;
+}
 
+////////////////////////////////////////////////////////////////////////////////
+void Mutex::lock() {
     MutexImpl::lock( this->properties->mutex );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 bool Mutex::tryLock() {
-
     return MutexImpl::trylock( this->properties->mutex );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void Mutex::unlock() {
-
     MutexImpl::unlock( this->properties->mutex );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void Mutex::wait() {
-
     ConditionImpl::wait( this->properties->condition );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void Mutex::wait( long long millisecs ) {
-
     wait( millisecs, 0 );
 }
 
@@ -117,12 +144,10 @@ void Mutex::wait( long long millisecs, i
 
 ////////////////////////////////////////////////////////////////////////////////
 void Mutex::notify() {
-
     ConditionImpl::notify( this->properties->condition );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void Mutex::notifyAll() {
-
     ConditionImpl::notifyAll( this->properties->condition );
 }

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=1042231&r1=1042230&r2=1042231&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 Sat Dec
 4 20:04:18 2010
@@ -50,8 +50,16 @@ namespace concurrent{
 
         Mutex();
 
+        Mutex( const std::string& name );
+
         virtual ~Mutex();
 
+        std::string getName() const;
+
+        std::string toString() const;
+
+    public:  // Synchronizable API Implementation
+
         virtual void lock();
 
         virtual bool tryLock();



Mime
View raw message