activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1338478 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core: ActiveMQConnection.cpp kernels/ActiveMQSessionKernel.cpp
Date Mon, 14 May 2012 22:53:56 GMT
Author: tabish
Date: Mon May 14 22:53:56 2012
New Revision: 1338478

URL: http://svn.apache.org/viewvc?rev=1338478&view=rev
Log:
Using LinkedList requires that the close logic removes the elements from the list in the iterator
to avoid concurrent modification on calling dispose()

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp?rev=1338478&r1=1338477&r2=1338478&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
Mon May 14 22:53:56 2012
@@ -532,7 +532,8 @@ void ActiveMQConnection::close() {
         }
 
         // Get the complete list of active sessions and call dispose() which should not trigger
-        // any messages back to the broker.
+        // any messages back to the broker, remove each before the dispose call to avoid
a
+        // concurrent modification of the list.
         long long lastDeliveredSequenceId = 0;
         synchronized(&this->config->activeSessions) {
             std::auto_ptr< Iterator<Pointer<ActiveMQSessionKernel> > >
iter(this->config->activeSessions.iterator());
@@ -540,6 +541,7 @@ void ActiveMQConnection::close() {
             // Dispose of all the Session resources we know are still open.
             while (iter->hasNext()) {
                 Pointer<ActiveMQSessionKernel> session = iter->next();
+                iter->remove();
                 try{
                     session->dispose();
                     lastDeliveredSequenceId =
@@ -584,16 +586,13 @@ void ActiveMQConnection::cleanup() {
     try {
 
         synchronized(&this->config->activeSessions) {
-            // Get the complete list of active sessions.
             std::auto_ptr< Iterator< Pointer<ActiveMQSessionKernel> > >
iter( this->config->activeSessions.iterator() );
-
-            // Dispose of all the Session resources we know are still open.
             while (iter->hasNext()) {
                 Pointer<ActiveMQSessionKernel> session = iter->next();
+                iter->remove();
                 try{
                     session->dispose();
                 } catch( cms::CMSException& ex ){
-                    /* Absorb */
                 }
             }
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp?rev=1338478&r1=1338477&r2=1338478&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp
Mon May 14 22:53:56 2012
@@ -363,13 +363,16 @@ void ActiveMQSessionKernel::dispose() {
         }
 
         // Dispose of all Producers, the dispose method skips the RemoveInfo command.
-        std::auto_ptr<Iterator<Pointer<ActiveMQProducerKernel> > > producerIter(this->config->producers.iterator());
+        synchronized(&this->config->producers) {
+            std::auto_ptr<Iterator<Pointer<ActiveMQProducerKernel> > >
producerIter(this->config->producers.iterator());
 
-        while (producerIter->hasNext()) {
-            try{
-                producerIter->next()->dispose();
-            } catch (cms::CMSException& ex) {
-                /* Absorb */
+            while (producerIter->hasNext()) {
+                Pointer<ActiveMQProducerKernel> producer = producerIter->next();
+                producerIter->remove();
+                try {
+                    producer->dispose();
+                } catch (cms::CMSException& ex) {
+                }
             }
         }
     }



Mime
View raw message