Author: tabish
Date: Mon Nov 12 05:46:36 2007
New Revision: 594128
URL: http://svn.apache.org/viewvc?rev=594128&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103
Attempting to further fix the APR init problem
Modified:
activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/AprPool.cpp
activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/AprPool.h
activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/concurrent/Mutex.cpp
activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/concurrent/Mutex.h
activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.cpp
Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/AprPool.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/AprPool.cpp?rev=594128&r1=594127&r2=594128&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/AprPool.cpp
(original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/AprPool.cpp Mon
Nov 12 05:46:36 2007
@@ -20,24 +20,21 @@
using namespace decaf;
using namespace decaf::internal;
-// Initialize the static AprRuntime object.
-AprRuntime AprPool::aprRuntime;
-
////////////////////////////////////////////////////////////////////////////////
AprPool::AprPool() {
- aprPool = NULL;
+ aprPool = NULL;
}
////////////////////////////////////////////////////////////////////////////////
AprPool::~AprPool() {
-
+
// Destroy the pool if it was allocated.
destroyPool();
}
////////////////////////////////////////////////////////////////////////////////
void AprPool::allocatePool() const {
-
+
if( aprPool == NULL ) {
apr_pool_create( &aprPool, NULL );
}
@@ -45,17 +42,17 @@
////////////////////////////////////////////////////////////////////////////////
void AprPool::destroyPool() {
-
+
if( aprPool != NULL ) {
apr_pool_destroy( aprPool );
}
-
+
aprPool = NULL;
}
////////////////////////////////////////////////////////////////////////////////
void AprPool::cleanup() {
-
+
if( aprPool != NULL ) {
apr_pool_clear( aprPool );
}
Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/AprPool.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/AprPool.h?rev=594128&r1=594127&r2=594128&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/AprPool.h
(original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/AprPool.h Mon Nov
12 05:46:36 2007
@@ -38,12 +38,7 @@
* Internal APR pool
*/
mutable apr_pool_t* aprPool;
-
- /**
- * Manages the initialization of APR.
- */
- static AprRuntime aprRuntime;
-
+
public:
AprPool();
@@ -54,10 +49,15 @@
* @returns the internal APR pool
*/
apr_pool_t* getAprPool() const {
-
+
+ // Creates a single static instance that will on the first call
+ // init apr and remain in memory until we shutdown and then free
+ // the apr resources.
+ static AprRuntime aprRuntime;
+
// Ensure that the pool has been allocated.
allocatePool();
-
+
return aprPool;
}
@@ -69,12 +69,12 @@
void cleanup();
private:
-
+
/**
* Allocates the pool if it isn't already allocated.
*/
void allocatePool() const;
-
+
/**
* Destroys the pool if it has been allocated.
*/
Modified:
activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/concurrent/Mutex.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/concurrent/Mutex.cpp?rev=594128&r1=594127&r2=594128&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/concurrent/Mutex.cpp
(original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/concurrent/Mutex.cpp
Mon Nov 12 05:46:36 2007
@@ -21,14 +21,14 @@
#include <apr_time.h>
using namespace decaf;
+using namespace decaf::internal;
using namespace decaf::util;
using namespace decaf::util::concurrent;
////////////////////////////////////////////////////////////////////////////////
Mutex::Mutex() {
- apr_pool_create( &pool, NULL );
- apr_thread_mutex_create( &mutex, APR_THREAD_MUTEX_NESTED, pool );
+ apr_thread_mutex_create( &mutex, APR_THREAD_MUTEX_NESTED,
aprPool.getAprPool() );
this->lock_owner = 0;
this->lock_count = 0;
}
@@ -40,7 +40,7 @@
unlock();
apr_thread_mutex_destroy( mutex );
- apr_pool_destroy( pool );
+ apr_pool_destroy( aprPool.getAprPool() );
}
////////////////////////////////////////////////////////////////////////////////
@@ -79,16 +79,15 @@
}
////////////////////////////////////////////////////////////////////////////////
-void Mutex::wait() throw( lang::Exception )
-{
+void Mutex::wait() throw( lang::Exception ) {
// Delegate to the timed version
wait( WAIT_INFINITE );
}
////////////////////////////////////////////////////////////////////////////////
void Mutex::wait( unsigned long millisecs )
- throw( lang::Exception )
-{
+ throw( lang::Exception ) {
+
if( !isLockOwner() ) {
throw lang::Exception(
__FILE__, __LINE__,
@@ -106,7 +105,7 @@
// Create this threads wait event
apr_thread_cond_t* waitEvent = NULL;
- apr_thread_cond_create( &waitEvent, pool );
+ apr_thread_cond_create( &waitEvent, aprPool.getAprPool() );
// Store the event in the queue so that a notify can
// call it and wake up the thread.
Modified:
activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/concurrent/Mutex.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/concurrent/Mutex.h?rev=594128&r1=594127&r2=594128&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/concurrent/Mutex.h
(original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/concurrent/Mutex.h
Mon Nov 12 05:46:36 2007
@@ -22,8 +22,8 @@
#include <decaf/util/concurrent/Concurrent.h>
#include <decaf/lang/Thread.h>
#include <decaf/util/Config.h>
+#include <decaf/internal/AprPool.h>
-#include <apr_pools.h>
#include <apr_thread_mutex.h>
#include <apr_thread_cond.h>
@@ -43,8 +43,8 @@
class DECAF_API Mutex : public Synchronizable {
private:
- // APR Pool Allocator
- apr_pool_t* pool;
+ // Our one and only APR Pool
+ internal::AprPool aprPool;
// The mutex object.
apr_thread_mutex_t* mutex;
Modified:
activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.cpp?rev=594128&r1=594127&r2=594128&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.cpp
(original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.cpp
Mon Nov 12 05:46:36 2007
@@ -33,40 +33,36 @@
concurrent::Mutex LogWriter::mutex;
////////////////////////////////////////////////////////////////////////////////
-LogWriter::LogWriter(void)
-{
+LogWriter::LogWriter() {
}
////////////////////////////////////////////////////////////////////////////////
-LogWriter::~LogWriter(void)
-{
+LogWriter::~LogWriter() {
}
////////////////////////////////////////////////////////////////////////////////
-void LogWriter::log(const std::string& file DECAF_UNUSED,
- const int line DECAF_UNUSED,
- const std::string& prefix,
- const std::string& message)
-{
- synchronized(&mutex)
- {
+void LogWriter::log( const std::string& file DECAF_UNUSED,
+ const int line DECAF_UNUSED,
+ const std::string& prefix,
+ const std::string& message) {
+
+ synchronized( &mutex ) {
cout << prefix << " "
<< message << " - tid: " << Thread::getId() << endl;
}
}
////////////////////////////////////////////////////////////////////////////////
-void LogWriter::log(const std::string& message)
-{
- synchronized(&mutex)
- {
+void LogWriter::log(const std::string& message ) {
+
+ synchronized(&mutex) {
cout << message << " - tid: " << Thread::getId() << endl;
}
}
////////////////////////////////////////////////////////////////////////////////
-LogWriter& LogWriter::getInstance(void)
-{
+LogWriter& LogWriter::getInstance() {
+
// This one instance
static LogWriter instance;