Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 46098 invoked from network); 2 Feb 2008 21:49:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Feb 2008 21:49:09 -0000 Received: (qmail 15764 invoked by uid 500); 2 Feb 2008 21:49:00 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 15734 invoked by uid 500); 2 Feb 2008 21:49:00 -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 15725 invoked by uid 99); 2 Feb 2008 21:49:00 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 02 Feb 2008 13:49:00 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 02 Feb 2008 21:48:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 39E441A9832; Sat, 2 Feb 2008 13:48:48 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r617903 - in /activemq/activemq-cpp/decaf/trunk/src/main/decaf: lang/System.cpp lang/System.h util/Queue.h util/logging/LogWriter.cpp util/logging/LogWriter.h Date: Sat, 02 Feb 2008 21:48:47 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080202214848.39E441A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Sat Feb 2 13:48:46 2008 New Revision: 617903 URL: http://svn.apache.org/viewvc?rev=617903&view=rev Log: http://issues.apache.org/activemq/browse/AMQCPP-103 Working on the Windows Build, changed the way some of the static memebers are created, moving them from static members to methods that create a static instance internally and then are called when needed. This has the benefit of only creating the static instances when the code that needs them is actually used and not when its not. Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/lang/System.cpp activemq/activemq-cpp/decaf/trunk/src/main/decaf/lang/System.h activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/Queue.h activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.cpp activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.h Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/lang/System.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/lang/System.cpp?rev=617903&r1=617902&r2=617903&view=diff ============================================================================== --- activemq/activemq-cpp/decaf/trunk/src/main/decaf/lang/System.cpp (original) +++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/lang/System.cpp Sat Feb 2 13:48:46 2008 @@ -40,10 +40,13 @@ using namespace decaf::lang::exceptions; //////////////////////////////////////////////////////////////////////////////// -AprPool System::aprPool; +System::System() { +} //////////////////////////////////////////////////////////////////////////////// -System::System() { +AprPool& System::getAprPool() { + static AprPool aprPool; + return aprPool; } //////////////////////////////////////////////////////////////////////////////// @@ -52,8 +55,8 @@ apr_status_t result = APR_SUCCESS; // Clear the value, errors are thrown out as an exception - result = apr_env_delete( name.c_str(), aprPool.getAprPool() ); - aprPool.cleanup(); + result = apr_env_delete( name.c_str(), getAprPool().getAprPool() ); + getAprPool().cleanup(); if( result != APR_SUCCESS ) { @@ -73,7 +76,7 @@ apr_status_t result = APR_SUCCESS; // Read the value, errors are thrown out as an exception - result = apr_env_get( &value, name.c_str(), aprPool.getAprPool() ); + result = apr_env_get( &value, name.c_str(), getAprPool().getAprPool() ); if( result != APR_SUCCESS ) { @@ -91,7 +94,7 @@ } std::string envVal( value ); - aprPool.cleanup(); + getAprPool().cleanup(); return value; } @@ -103,8 +106,8 @@ apr_status_t result = APR_SUCCESS; // Write the value, errors are thrown out as an exception - result = apr_env_set( name.c_str(), value.c_str(), aprPool.getAprPool() ); - aprPool.cleanup(); + result = apr_env_set( name.c_str(), value.c_str(), getAprPool().getAprPool() ); + getAprPool().cleanup(); if( result != APR_SUCCESS ) { Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/lang/System.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/lang/System.h?rev=617903&r1=617902&r2=617903&view=diff ============================================================================== --- activemq/activemq-cpp/decaf/trunk/src/main/decaf/lang/System.h (original) +++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/lang/System.h Sat Feb 2 13:48:46 2008 @@ -28,10 +28,6 @@ namespace lang{ class DECAF_API System { - private: - - static internal::AprPool aprPool; - public: System(); @@ -89,6 +85,11 @@ * @returns a vector of env name=value paris. */ static std::vector< std::string > getEnvArray(); + + /** + * Gets the one and only APR Pool instance + */ + static internal::AprPool& getAprPool(); }; Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/Queue.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/Queue.h?rev=617903&r1=617902&r2=617903&view=diff ============================================================================== --- activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/Queue.h (original) +++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/Queue.h Sat Feb 2 13:48:46 2008 @@ -74,7 +74,7 @@ */ T& front() { if( queue.empty() ) { - return safe; + return getSafeValue(); } return queue.front(); @@ -86,7 +86,7 @@ */ const T& front() const { if( queue.empty() ) { - return safe; + return getSafeValue(); } return queue.front(); @@ -98,7 +98,7 @@ */ T& back() { if( queue.empty() ) { - return safe; + return getSafeValue(); } return queue.back(); @@ -110,7 +110,7 @@ */ const T& back() const { if( queue.empty() ) { - return safe; + return getSafeValue(); } return queue.back(); @@ -138,7 +138,7 @@ */ T pop() { if( queue.empty() ) { - return safe; + return getSafeValue(); } // Pop the element into a temp, since we need to remain locked. @@ -245,7 +245,10 @@ * when there is nothing to fetch from the queue. * @return Reference to this Queues safe object */ - static const T& getSafeValue() { return safe; } + T& getSafeValue() { + static T safe; + return safe; + } private: @@ -255,14 +258,7 @@ // Object used for sync util::concurrent::Mutex mutex; - // Safe value used when pop, front or back are - // called and the queue is empty. - static T safe; - }; - - //-----{ Static Init }----------------------------------------------------// - template T Queue::safe; }} Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.cpp?rev=617903&r1=617902&r2=617903&view=diff ============================================================================== --- activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.cpp (original) +++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.cpp Sat Feb 2 13:48:46 2008 @@ -30,9 +30,6 @@ using namespace decaf::util::logging; //////////////////////////////////////////////////////////////////////////////// -concurrent::Mutex LogWriter::mutex; - -//////////////////////////////////////////////////////////////////////////////// LogWriter::LogWriter() { } @@ -46,7 +43,7 @@ const std::string& prefix, const std::string& message) { - synchronized( &mutex ) { + synchronized( &getMutex() ) { cout << prefix << " " << message << " - tid: " << Thread::getId() << endl; } @@ -55,7 +52,7 @@ //////////////////////////////////////////////////////////////////////////////// void LogWriter::log(const std::string& message ) { - synchronized(&mutex) { + synchronized(&getMutex()) { cout << message << " - tid: " << Thread::getId() << endl; } } @@ -69,3 +66,8 @@ return instance; } +//////////////////////////////////////////////////////////////////////////////// +Mutex& LogWriter::getMutex() { + static concurrent::Mutex mutex; + return mutex; +}; \ No newline at end of file Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.h?rev=617903&r1=617902&r2=617903&view=diff ============================================================================== --- activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.h (original) +++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/util/logging/LogWriter.h Sat Feb 2 13:48:46 2008 @@ -23,55 +23,56 @@ namespace util{ namespace logging{ - class DECAF_API LogWriter - { - public: - - LogWriter(void); - virtual ~LogWriter(void); - - /** - * Writes a message to the output destination - * @param file - * @param line - * @param prefix - * @param message - */ - virtual void log(const std::string& file, - const int line, - const std::string& prefix, - const std::string& message); - - /** - * Writes a message to the output destination - * @param message - */ - virtual void log(const std::string& message); - - public: // Static methods - - /** - * Get the singleton instance - */ - static LogWriter& getInstance(); - - /** - * Returns a Checked out instance of this Writer - */ - static void returnInstance(); - - /** - * Forcefully Delete the Instance of this LogWriter - * even if there are outstanding references. - */ - static void destroy(); + class DECAF_API LogWriter { + public: - private: + LogWriter(void); + virtual ~LogWriter(void); - // Syncronization mutex - static concurrent::Mutex mutex; + /** + * Writes a message to the output destination + * @param file + * @param line + * @param prefix + * @param message + */ + virtual void log( const std::string& file, + const int line, + const std::string& prefix, + const std::string& message ); + + /** + * Writes a message to the output destination + * @param message + */ + virtual void log(const std::string& message); + + public: // Static methods + + /** + * Get the singleton instance + */ + static LogWriter& getInstance(); + + /** + * Returns a Checked out instance of this Writer + */ + static void returnInstance(); + + /** + * Forcefully Delete the Instance of this LogWriter + * even if there are outstanding references. + */ + static void destroy(); + + private: + + /** + * Gets the one and only mutex for this instance. + */ + concurrent::Mutex& getMutex(); - }; + }; }}}