Repository: activemq-cpp
Updated Branches:
  refs/heads/3.8.x b7542f28c -> b8aabbf63


https://issues.apache.org/jira/browse/AMQCPP-556

apply fix for deadlock on session stop()


Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/b8aabbf6
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/b8aabbf6
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/b8aabbf6

Branch: refs/heads/3.8.x
Commit: b8aabbf6365c37bfd4ae03b575361bd69cdb3717
Parents: b7542f2
Author: Timothy Bish <tabish...@gmail.com>
Authored: Mon Dec 1 14:35:32 2014 -0500
Committer: Timothy Bish <tabish...@gmail.com>
Committed: Mon Dec 1 14:38:37 2014 -0500

----------------------------------------------------------------------
 .../main/activemq/core/ActiveMQSessionExecutor.cpp | 17 ++++++++++-------
 .../core/kernels/ActiveMQSessionKernel.cpp         | 14 ++++++++++++++
 2 files changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/b8aabbf6/activemq-cpp/src/main/activemq/core/ActiveMQSessionExecutor.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/activemq/core/ActiveMQSessionExecutor.cpp 
b/activemq-cpp/src/main/activemq/core/ActiveMQSessionExecutor.cpp
index 48a919c..e8477c6 100644
--- a/activemq-cpp/src/main/activemq/core/ActiveMQSessionExecutor.cpp
+++ b/activemq-cpp/src/main/activemq/core/ActiveMQSessionExecutor.cpp
@@ -100,6 +100,9 @@ void ActiveMQSessionExecutor::wakeup() {
     Pointer<TaskRunner> taskRunner;
     synchronized(messageQueue.get()) {
         if (this->taskRunner == NULL) {
+            if (!messageQueue->isRunning()) {
+                return;
+            }
             this->taskRunner.reset(new DedicatedTaskRunner(this));
             this->taskRunner->start();
         }
@@ -124,21 +127,21 @@ void ActiveMQSessionExecutor::start() {
 
////////////////////////////////////////////////////////////////////////////////
 void ActiveMQSessionExecutor::stop() {
 
-    if (messageQueue->isRunning()) {
-        messageQueue->stop();
-        Pointer<TaskRunner> taskRunner;
+    Pointer<TaskRunner> taskRunner;
+    synchronized(messageQueue.get()) {
+        if (messageQueue->isRunning()) {
+            messageQueue->stop();
 
-        synchronized(messageQueue.get()) {
             taskRunner = this->taskRunner;
 
             if (taskRunner != NULL) {
                 this->taskRunner.reset(NULL);
             }
         }
+    }
 
-        if (taskRunner != NULL) {
-            taskRunner->shutdown();
-        }
+    if (taskRunner != NULL) {
+        taskRunner->shutdown();
     }
 }
 

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/b8aabbf6/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp
----------------------------------------------------------------------
diff --git 
a/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp 
b/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp
index 0f320e8..fad69a8 100644
--- a/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp
+++ b/activemq-cpp/src/main/activemq/core/kernels/ActiveMQSessionKernel.cpp
@@ -1100,6 +1100,20 @@ void ActiveMQSessionKernel::start() {
 
////////////////////////////////////////////////////////////////////////////////
 void ActiveMQSessionKernel::stop() {
 
+    this->config->consumerLock.readLock().lock();
+    try {
+        Pointer<Iterator< Pointer<ActiveMQConsumerKernel> > > 
iter(this->config->consumers.iterator());
+
+        while (iter->hasNext()) {
+            Pointer<ActiveMQConsumerKernel> consumer = iter->next();
+            consumer->stop();
+        }
+        this->config->consumerLock.readLock().unlock();
+    } catch (Exception& ex) {
+        this->config->consumerLock.readLock().unlock();
+        throw;
+    }
+
     if (this->executor.get() != NULL) {
         this->executor->stop();
     }

Reply via email to