Author: tabish
Date: Thu Sep 17 23:29:27 2009
New Revision: 816411
URL: http://svn.apache.org/viewvc?rev=816411&view=rev
Log:
Clean up the code now to remove all commented out APR code and correct the
comments to reflect the new implementation.
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=816411&r1=816410&r2=816411&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
Thu Sep 17 23:29:27 2009
@@ -17,13 +17,6 @@
#include <decaf/util/concurrent/Mutex.h>
-//#include <apr_errno.h>
-//#include <apr_time.h>
-//#include <apr_thread_mutex.h>
-//#include <apr_thread_cond.h>
-//
-//#include <decaf/internal/AprPool.h>
-
#include <decaf/internal/util/concurrent/MutexImpl.h>
#include <decaf/internal/util/concurrent/ConditionImpl.h>
@@ -45,26 +38,13 @@
class MutexProperties {
public:
- MutexProperties() {
-// this->mutex = NULL;
-// this->lock_owner = 0;
-// this->lock_count = 0;
- }
-
- // Our one and only APR Pool
-// internal::AprPool aprPool;
+ MutexProperties() {}
- // The mutex object.
+ // The Platform Mutex object and an associated Condition Object
+ // for use in the wait / notify pattern.
std::auto_ptr<MutexHandle> mutex;
std::auto_ptr<ConditionHandle> condition;
- // List of waiting threads
-// std::list<apr_thread_cond_t*> eventQ;
-//
-// // Lock Status Members
-// volatile long long lock_owner;
-// volatile long long lock_count;
-
};
}}}
@@ -77,178 +57,51 @@
// Allocate the OS Mutex Implementation.
this->properties->mutex.reset( MutexImpl::create() );
this->properties->condition.reset( ConditionImpl::create(
this->properties->mutex.get() ) );
-// apr_thread_mutex_create( &( properties->mutex ),
-// APR_THREAD_MUTEX_NESTED,
-// properties->aprPool.getAprPool() );
}
////////////////////////////////////////////////////////////////////////////////
Mutex::~Mutex() {
-
- // Unlock the mutex, the destruction of the AprPool will take care
- // of cleaning up the apr_thread_mutex_t allocated in the ctor.
- //unlock();
+ unlock();
}
////////////////////////////////////////////////////////////////////////////////
void Mutex::lock() throw( lang::Exception ) {
MutexImpl::lock( this->properties->mutex.get() );
-// long long threadId = lang::Thread::getId();
-//
-// if( threadId == properties->lock_owner ) {
-// properties->lock_count++;
-// } else {
-// apr_thread_mutex_lock( properties->mutex );
-// properties->lock_owner = threadId;
-// properties->lock_count = 1;
-// }
}
////////////////////////////////////////////////////////////////////////////////
bool Mutex::tryLock() throw( lang::Exception ) {
-
return MutexImpl::trylock( this->properties->mutex.get() );
-
-// 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 ) {
-
MutexImpl::unlock( this->properties->mutex.get() );
-
-// if( properties->lock_owner == 0 ) {
-// return;
-// }
-//
-// if( !isLockOwner() ) {
-// throw lang::Exception(
-// __FILE__, __LINE__,
-// "Mutex::unlock - Failed, not Lock Owner!" );
-// }
-//
-// properties->lock_count--;
-//
-// if( properties->lock_count == 0 ) {
-// properties->lock_owner = 0;
-// apr_thread_mutex_unlock( properties->mutex );
-// }
}
////////////////////////////////////////////////////////////////////////////////
void Mutex::wait() throw( lang::Exception ) {
-
- // Delegate to the timed version
- // wait( WAIT_INFINITE, 0 );
ConditionImpl::wait( this->properties->condition.get() );
}
////////////////////////////////////////////////////////////////////////////////
void Mutex::wait( long long millisecs ) throw( lang::Exception ) {
-
wait( millisecs, 0 );
-
-// if( !isLockOwner() ) {
-// throw lang::Exception(
-// __FILE__, __LINE__,
-// "Mutex::wait - Failed, not Lock Owner!");
-// }
-//
-// // 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->properties->lock_owner;
-// long long lock_count = this->properties->lock_count;
-//
-// 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, 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.
-// properties->eventQ.push_back( waitEvent );
-//
-// if( millisecs != WAIT_INFINITE ) {
-// apr_interval_time_t wait = millisecs * 1000;
-// apr_thread_cond_timedwait( waitEvent, properties->mutex, wait );
-// } else {
-// apr_thread_cond_wait( waitEvent, properties->mutex );
-// }
-//
-// // Be Sure that the event is now removed
-// properties->eventQ.remove( waitEvent );
-//
-// // Destroy our wait event now, the notify method will have removed it
-// // from the event queue.
-// apr_thread_cond_destroy( waitEvent );
-// apr_pool_destroy( subPool );
-//
-// // restore the owner
-// this->properties->lock_owner = lock_owner;
-// this->properties->lock_count = lock_count;
}
////////////////////////////////////////////////////////////////////////////////
void Mutex::wait( long long millisecs, int nanos DECAF_UNUSED ) throw(
lang::Exception ) {
- // For now delegate to the single arg version.
- // this->wait( millisecs );
-
ConditionImpl::wait( this->properties->condition.get(), millisecs, nanos );
}
////////////////////////////////////////////////////////////////////////////////
-void Mutex::notify() throw( lang::Exception )
-{
+void Mutex::notify() throw( lang::Exception ) {
ConditionImpl::notify( this->properties->condition.get() );
-
-// if( !isLockOwner() ) {
-// throw lang::Exception(
-// __FILE__, __LINE__,
-// "Mutex::Notify - Failed, not Lock Owner!" );
-// }
-//
-// if( !properties->eventQ.empty() ) {
-// apr_thread_cond_t* event = properties->eventQ.front();
-// properties->eventQ.remove( event );
-// apr_thread_cond_signal( event );
-// }
}
////////////////////////////////////////////////////////////////////////////////
-void Mutex::notifyAll() throw( lang::Exception )
-{
+void Mutex::notifyAll() throw( lang::Exception ) {
ConditionImpl::notifyAll( this->properties->condition.get() );
-
-// if( !isLockOwner() ) {
-// throw lang::Exception(
-// __FILE__, __LINE__,
-// "Mutex::NotifyAll - Failed, not Lock Owner!" );
-// }
-//
-// 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=816411&r1=816410&r2=816411&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
Thu Sep 17 23:29:27 2009
@@ -32,9 +32,11 @@
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.
+ * Mutex object that offers recursive support on all platforms as well as
+ * providing the ability to use the standard wait / notify pattern used in
+ * languages like Java.
+ *
+ * @since 1.0
*/
class DECAF_API Mutex : public Synchronizable {
private: