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 2013/02/16 23:26:55 UTC
svn commit: r1446967 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads:
CompositeTaskRunner.cpp DedicatedTaskRunner.cpp
Author: tabish
Date: Sat Feb 16 22:26:54 2013
New Revision: 1446967
URL: http://svn.apache.org/r1446967
Log:
Make the timed shutdown more deterministic
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/CompositeTaskRunner.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/DedicatedTaskRunner.cpp
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/CompositeTaskRunner.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/CompositeTaskRunner.cpp?rev=1446967&r1=1446966&r2=1446967&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/CompositeTaskRunner.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/CompositeTaskRunner.cpp Sat Feb 16 22:26:54 2013
@@ -39,7 +39,7 @@ CompositeTaskRunner::CompositeTaskRunner
////////////////////////////////////////////////////////////////////////////////
CompositeTaskRunner::~CompositeTaskRunner() {
- try{
+ try {
this->shutdown();
this->thread->join();
this->thread.reset(NULL);
@@ -79,12 +79,12 @@ void CompositeTaskRunner::shutdown(long
shutDown = true;
pending = true;
mutex.notifyAll();
+ }
- // Wait till the thread stops ( no need to wait if shutdown
- // is called from thread that is shutting down)
- if (Thread::currentThread() != this->thread.get() && !threadTerminated) {
- mutex.wait(timeout);
- }
+ // Wait till the thread stops ( no need to wait if shutdown
+ // is called from thread that is shutting down)
+ if (Thread::currentThread() != this->thread.get() && !threadTerminated) {
+ this->thread->join(timeout);
}
}
@@ -130,14 +130,14 @@ void CompositeTaskRunner::run() {
}
}
- if( !this->iterate() ) {
+ if (!this->iterate()) {
// wait to be notified.
synchronized(&mutex) {
if (shutDown) {
return;
}
- while (!pending) {
+ while (!pending && !shutDown) {
mutex.wait();
}
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/DedicatedTaskRunner.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/DedicatedTaskRunner.cpp?rev=1446967&r1=1446966&r2=1446967&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/DedicatedTaskRunner.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/DedicatedTaskRunner.cpp Sat Feb 16 22:26:54 2013
@@ -82,12 +82,12 @@ void DedicatedTaskRunner::shutdown(long
shutDown = true;
pending = true;
mutex.notifyAll();
+ }
- // Wait till the thread stops ( no need to wait if shutdown
- // is called from thread that is shutting down)
- if (Thread::currentThread() != this->thread.get() && !threadTerminated) {
- mutex.wait(timeout);
- }
+ // Wait till the thread stops ( no need to wait if shutdown
+ // is called from thread that is shutting down)
+ if (Thread::currentThread() != this->thread.get() && !threadTerminated) {
+ this->thread->join(timeout);
}
}
@@ -145,7 +145,7 @@ void DedicatedTaskRunner::run() {
if (shutDown) {
return;
}
- while (!pending) {
+ while (!pending && !shutDown) {
mutex.wait();
}
}