You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2008/10/19 20:09:20 UTC

svn commit: r706049 - in /activemq/activemq-cpp/trunk/src: main/ main/activemq/support/ main/decaf/internal/ main/decaf/lang/ main/decaf/util/concurrent/ test/

Author: tabish
Date: Sun Oct 19 11:09:19 2008
New Revision: 706049

URL: http://svn.apache.org/viewvc?rev=706049&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-200

Fix issues with APR pools use and threading.

Added:
    activemq/activemq-cpp/trunk/src/main/decaf/internal/DecafRuntime.cpp   (props changed)
      - copied unchanged from r706048, activemq/activemq-cpp/branches/pools-revamp/src/main/decaf/internal/DecafRuntime.cpp
    activemq/activemq-cpp/trunk/src/main/decaf/internal/DecafRuntime.h   (props changed)
      - copied unchanged from r706048, activemq/activemq-cpp/branches/pools-revamp/src/main/decaf/internal/DecafRuntime.h
    activemq/activemq-cpp/trunk/src/main/decaf/lang/Runtime.h
      - copied unchanged from r706048, activemq/activemq-cpp/branches/pools-revamp/src/main/decaf/lang/Runtime.h
Removed:
    activemq/activemq-cpp/trunk/src/main/decaf/internal/AprRuntime.cpp
    activemq/activemq-cpp/trunk/src/main/decaf/internal/AprRuntime.h
Modified:
    activemq/activemq-cpp/trunk/src/main/Makefile.am
    activemq/activemq-cpp/trunk/src/main/activemq/support/InitDirector.cpp
    activemq/activemq-cpp/trunk/src/main/decaf/internal/AprPool.cpp
    activemq/activemq-cpp/trunk/src/main/decaf/internal/AprPool.h
    activemq/activemq-cpp/trunk/src/main/decaf/lang/Thread.cpp
    activemq/activemq-cpp/trunk/src/main/decaf/lang/Thread.h
    activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/Mutex.cpp
    activemq/activemq-cpp/trunk/src/test/main.cpp

Modified: activemq/activemq-cpp/trunk/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/Makefile.am?rev=706049&r1=706048&r2=706049&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/main/Makefile.am Sun Oct 19 11:09:19 2008
@@ -81,7 +81,7 @@
     activemq/transport/filters/TcpTransportFactory.cpp \
     activemq/transport/filters/LoggingTransport.cpp \
     activemq/transport/filters/LoggingTransportFactory.cpp \
-    decaf/internal/AprRuntime.cpp \
+    decaf/internal/DecafRuntime.cpp \
     decaf/internal/AprPool.cpp \
     decaf/internal/util/ByteArrayAdapter.cpp \
     decaf/internal/util/HexStringParser.cpp \
@@ -348,6 +348,7 @@
     decaf/lang/Thread.h \
     decaf/lang/Number.h \
     decaf/lang/Runnable.h \
+    decaf/lang/Runtime.h \
     decaf/lang/Math.h \
     decaf/lang/System.h \
     decaf/lang/Boolean.h \
@@ -425,7 +426,7 @@
     decaf/util/logging/SimpleLogger.h \
     decaf/util/logging/PropertiesChangeListener.h \
     decaf/internal/AprPool.h \
-    decaf/internal/AprRuntime.h \
+    decaf/internal/DecafRuntime.h \
     decaf/internal/util/HexStringParser.h \
     decaf/internal/util/ByteArrayAdapter.h \
     decaf/internal/nio/BufferFactory.h \

Modified: activemq/activemq-cpp/trunk/src/main/activemq/support/InitDirector.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/support/InitDirector.cpp?rev=706049&r1=706048&r2=706049&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/support/InitDirector.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/support/InitDirector.cpp Sun Oct 19 11:09:19 2008
@@ -17,7 +17,7 @@
 #include "InitDirector.h"
 
 #include <decaf/util/logging/LogWriter.h>
-#include <decaf/internal/AprPool.h>
+#include <decaf/lang/Runtime.h>
 #include <activemq/transport/IOTransportFactory.h>
 #include <activemq/transport/MockTransportFactory.h>
 #include <activemq/transport/filters/AsyncSendTransportFactory.h>
@@ -37,8 +37,7 @@
 InitDirector::InitDirector() {
 
     if( refCount == 0 ) {
-        decaf::internal::AprPool initPools;
-        initPools.getAprPool();
+        decaf::lang::Runtime::getRuntime();
         connector::stomp::StompConnectorFactory::getInstance();
         connector::openwire::OpenWireConnectorFactory::getInstance();
         transport::filters::TcpTransportFactory::getInstance();

Modified: activemq/activemq-cpp/trunk/src/main/decaf/internal/AprPool.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/AprPool.cpp?rev=706049&r1=706048&r2=706049&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/AprPool.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/AprPool.cpp Sun Oct 19 11:09:19 2008
@@ -16,6 +16,7 @@
  */
 
 #include "AprPool.h"
+#include <decaf/lang/Runtime.h>
 
 using namespace decaf;
 using namespace decaf::internal;
@@ -36,7 +37,7 @@
 void AprPool::allocatePool() const {
 
     if( aprPool == NULL ) {
-        apr_pool_create( &aprPool, NULL );
+        apr_pool_create_unmanaged( &aprPool );
     }
 }
 
@@ -61,10 +62,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 apr_pool_t* AprPool::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 there is a Runtime instance created.
+    decaf::lang::Runtime::getRuntime();
 
     // Ensure that the pool has been allocated.
     allocatePool();

Modified: activemq/activemq-cpp/trunk/src/main/decaf/internal/AprPool.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/AprPool.h?rev=706049&r1=706048&r2=706049&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/AprPool.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/AprPool.h Sun Oct 19 11:09:19 2008
@@ -19,7 +19,6 @@
 #define _DECAF_INTERNAL_APRPOOL_H_
 
 #include <decaf/util/Config.h>
-#include <decaf/internal/AprRuntime.h>
 
 #include <apr_pools.h>
 

Modified: activemq/activemq-cpp/trunk/src/main/decaf/lang/Thread.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/lang/Thread.cpp?rev=706049&r1=706048&r2=706049&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/lang/Thread.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/lang/Thread.cpp Sun Oct 19 11:09:19 2008
@@ -20,6 +20,7 @@
 #include <apr_time.h>
 #include <apr_portable.h>
 
+#include <decaf/internal/DecafRuntime.h>
 #include <decaf/lang/Exception.h>
 #include <decaf/lang/exceptions/RuntimeException.h>
 
@@ -57,12 +58,14 @@
             "Thread::start - Thread already started");
     }
 
+    DecafRuntime* runtime = dynamic_cast<DecafRuntime*>( Runtime::getRuntime() );
+
     apr_status_t err = apr_thread_create(
         &this->threadHandle,
         NULL,
         runCallback,
         this,
-        pool.getAprPool() );
+        runtime->getGlobalPool() );
 
     if( err != APR_SUCCESS ) {
         throw Exception(

Modified: activemq/activemq-cpp/trunk/src/main/decaf/lang/Thread.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/lang/Thread.h?rev=706049&r1=706048&r2=706049&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/lang/Thread.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/lang/Thread.h Sun Oct 19 11:09:19 2008
@@ -23,7 +23,6 @@
 #include <stdexcept>
 #include <assert.h>
 
-#include <decaf/internal/AprPool.h>
 #include <apr_thread_proc.h>
 
 namespace decaf{
@@ -45,11 +44,6 @@
         Runnable* task;
 
         /**
-         * APR Pool to allocate thread from
-         */
-        decaf::internal::AprPool pool;
-
-        /**
          * APR Thread Handle
          */
         apr_thread_t* threadHandle;

Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/Mutex.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/Mutex.cpp?rev=706049&r1=706048&r2=706049&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/Mutex.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/util/concurrent/Mutex.cpp Sun Oct 19 11:09:19 2008
@@ -36,10 +36,9 @@
 ////////////////////////////////////////////////////////////////////////////////
 Mutex::~Mutex() {
 
-    // Unlock the 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();
-
-    apr_thread_mutex_destroy( mutex );
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/src/test/main.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/main.cpp?rev=706049&r1=706048&r2=706049&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/main.cpp (original)
+++ activemq/activemq-cpp/trunk/src/test/main.cpp Sun Oct 19 11:09:19 2008
@@ -20,9 +20,13 @@
 #include <cppunit/BriefTestProgressListener.h>
 #include <cppunit/TestResult.h>
 #include <activemq/util/Config.h>
+#include <decaf/lang/Runtime.h>
 
 int main( int argc AMQCPP_UNUSED, char **argv AMQCPP_UNUSED)
 {
+    // ensure that we start the runtime.
+    decaf::lang::Runtime::getRuntime();
+
     CppUnit::TextUi::TestRunner runner;
     CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
     runner.addTest( registry.makeTest() );
@@ -30,7 +34,7 @@
     // Shows a message as each test starts
     CppUnit::BriefTestProgressListener listener;
     runner.eventManager().addListener( &listener );
-    
+
     bool wasSuccessful = runner.run( "", false );
     return !wasSuccessful;
 }