Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 39559 invoked from network); 4 Dec 2010 20:05:51 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 4 Dec 2010 20:05:51 -0000 Received: (qmail 25688 invoked by uid 500); 4 Dec 2010 20:05:51 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 25657 invoked by uid 500); 4 Dec 2010 20:05:51 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 25650 invoked by uid 99); 4 Dec 2010 20:05:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Dec 2010 20:05:51 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Dec 2010 20:05:50 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9271023888CF; Sat, 4 Dec 2010 20:04:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101204200418.9271023888CF@eris.apache.org> 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 #include +#include #include @@ -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();