Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 52083 invoked from network); 6 Dec 2009 18:25:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 6 Dec 2009 18:25:51 -0000 Received: (qmail 36842 invoked by uid 500); 6 Dec 2009 18:25:51 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 36785 invoked by uid 500); 6 Dec 2009 18:25:51 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 36773 invoked by uid 99); 6 Dec 2009 18:25:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 06 Dec 2009 18:25:51 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 06 Dec 2009 18:25:48 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 09EAA23888D1; Sun, 6 Dec 2009 18:25:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r887732 - in /activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main: activemq/core/ActiveMQSession.cpp decaf/lang/Thread.cpp decaf/lang/Thread.h Date: Sun, 06 Dec 2009 18:25:26 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091206182527.09EAA23888D1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Sun Dec 6 18:25:26 2009 New Revision: 887732 URL: http://svn.apache.org/viewvc?rev=887732&view=rev Log: http://issues.apache.org/activemq/browse/AMQCPP-271 Fix the Threads class to work with Foreign Thread instances. Move the close marker in session to after the close of the session resources. Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/lang/Thread.cpp activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/lang/Thread.h Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp?rev=887732&r1=887731&r2=887732&view=diff ============================================================================== --- activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp (original) +++ activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp Sun Dec 6 18:25:26 2009 @@ -118,9 +118,6 @@ try { - // Now indicate that this session is closed. - closed = true; - // Stop the dispatch executor. stop(); @@ -158,6 +155,9 @@ } } + // Now indicate that this session is closed. + closed = true; + // Remove this sessions from the connection this->connection->removeSession( this ); Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/lang/Thread.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/lang/Thread.cpp?rev=887732&r1=887731&r2=887732&view=diff ============================================================================== --- activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/lang/Thread.cpp (original) +++ activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/lang/Thread.cpp Sun Dec 6 18:25:26 2009 @@ -31,6 +31,8 @@ #include #include +#include + #if HAVE_PTHREAD_H #include #endif @@ -169,6 +171,7 @@ namespace{ Thread* mainThread = NULL; + std::vector foreignThreads; #ifdef HAVE_PTHREAD_H @@ -224,51 +227,67 @@ //////////////////////////////////////////////////////////////////////////////// void Thread::initThreading() { - mainThread = new Thread( "Main Thread" ); + // We mark the thread where Decaf's Init routine is called from as our Main Thread. + mainThread = Thread::createForeignThreadInstance( "Main Thread" ); +} - mainThread->properties->state = Thread::RUNNABLE; - mainThread->properties->priority = Thread::NORM_PRIORITY; - mainThread->properties->parent = mainThread; +//////////////////////////////////////////////////////////////////////////////// +void Thread::shutdownThreading() { - #ifdef HAVE_PTHREAD_H + // Clear the Main Thread instance pointer, this indicates we are Shutdown. + mainThread = NULL; - mainThread->properties->handle = pthread_self(); + // Destroy any Foreign Thread Facades that were created during runtime. + std::vector::iterator iter = foreignThreads.begin(); + for( ; iter != foreignThreads.end(); ++iter ) { + delete *iter; + } + foreignThreads.clear(); - // Create the Key used to store the Current Thread data - pthread_key_create( ¤tThreadKey, NULL ); - pthread_setspecific( currentThreadKey, mainThread ); + #ifdef HAVE_PTHREAD_H - #else + // Destroy the current Thread key now, no longer needed. + pthread_key_delete( currentThreadKey ); - mainThread->properties->handle = ::GetCurrentThread(); + #else - // Create the key used to store the Current Thread data - currentThreadKey = ::TlsAlloc(); - ::TlsSetValue( currentThreadKey, mainThread ); + // Destroy our TLS resources before we shutdown. + ::TlsFree( currentThreadKey ); #endif } //////////////////////////////////////////////////////////////////////////////// -void Thread::shutdownThreading() { +Thread* Thread::createForeignThreadInstance( const std::string& name ) { + + Thread* foreignThread = new Thread( name ); + + foreignThread->properties->state = Thread::RUNNABLE; + foreignThread->properties->priority = Thread::NORM_PRIORITY; + foreignThread->properties->parent = NULL; #ifdef HAVE_PTHREAD_H - // Destroy the Main Thread instance. - delete mainThread; + foreignThread->properties->handle = pthread_self(); - // Destroy the current Thread key now, no longer needed. - pthread_key_delete( currentThreadKey ); + // Create the Key used to store the Current Thread data + pthread_key_create( ¤tThreadKey, NULL ); + pthread_setspecific( currentThreadKey, foreignThread ); #else - // Destroy the Main Thread instance. - delete mainThread; + foreignThread->properties->handle = ::GetCurrentThread(); - // Destroy our TLS resources before we shutdown. - ::TlsFree( currentThreadKey ); + // Create the key used to store the Current Thread data + currentThreadKey = ::TlsAlloc(); + ::TlsSetValue( currentThreadKey, foreignThread ); #endif + + // Store the Facade for later deletion + foreignThreads.push_back( foreignThread ); + + return foreignThread; } //////////////////////////////////////////////////////////////////////////////// @@ -573,6 +592,11 @@ //////////////////////////////////////////////////////////////////////////////// Thread* Thread::currentThread() { + if( mainThread == NULL ) { + throw RuntimeException( + __FILE__, __LINE__, "The Decaf Threading API is in a Shutdown State." ); + } + void* result = NULL; #ifdef HAVE_PTHREAD_H @@ -585,9 +609,11 @@ #endif + // This is a foreign Thread (Not Created By Decaf) lets create a stand in Thread + // instance so that other threads in Decaf can join it and wait on it. if( result == NULL ) { - throw RuntimeException( - __FILE__, __LINE__, "Failed to find the Current Thread pointer in the TLS." ); + result = Thread::createForeignThreadInstance( + std::string( "ForeignThread-" ) + Integer::toString( Thread::getId() ) ); } return (Thread*)result; Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/lang/Thread.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/lang/Thread.h?rev=887732&r1=887731&r2=887732&view=diff ============================================================================== --- activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/lang/Thread.h (original) +++ activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/lang/Thread.h Sun Dec 6 18:25:26 2009 @@ -359,6 +359,9 @@ // Initialize the Threads internal state void initialize( Runnable* task, const std::string& name ); + // Create a Thread Facade for threads not created by the Decaf Library. + static Thread* createForeignThreadInstance( const std::string& name ); + // Called by the Decaf Runtime at startup to allow the Platform Threading // code to initialize any necessary Threading constructs needed to support // the features of this class.