activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r690258 - in /activemq/activemq-cpp/trunk/src/main/activemq: connector/openwire/ core/ transport/filters/
Date Fri, 29 Aug 2008 13:55:41 GMT
Author: tabish
Date: Fri Aug 29 06:55:40 2008
New Revision: 690258

URL: http://svn.apache.org/viewvc?rev=690258&view=rev
Log:
Make use of Atomic object where possible to reduce locking.

Modified:
    activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.h
    activemq/activemq-cpp/trunk/src/main/activemq/core/ActiveMQConnectionFactory.h
    activemq/activemq-cpp/trunk/src/main/activemq/transport/filters/ResponseCorrelator.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/transport/filters/ResponseCorrelator.h

Modified: activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.cpp?rev=690258&r1=690257&r2=690258&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.cpp
(original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.cpp
Fri Aug 29 06:55:40 2008
@@ -38,7 +38,7 @@
     wireInfoSentDownLatch(1),
     readyCountDownLatch(1)
 {
-    this->firstTime = true;
+    this->firstTime.set( true );
     this->openWireFormat = openWireFormat;
     this->closed = true;
 }
@@ -224,13 +224,10 @@
     // Start the delegate transport object.
     next->start();
 
-    if( firstTime == true ) {
+    if( firstTime.compareAndSet( true, false ) ) {
 
         try {
 
-            // The First Time is now over with
-            firstTime = false;
-
             // We first send the WireFormat that we'd prefer.
             next->oneway( openWireFormat->getPreferedWireFormatInfo() );
 

Modified: activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.h?rev=690258&r1=690257&r2=690258&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.h
(original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormatNegotiator.h
Fri Aug 29 06:55:40 2008
@@ -25,6 +25,7 @@
 #include <decaf/util/concurrent/Mutex.h>
 #include <decaf/util/concurrent/CountDownLatch.h>
 #include <decaf/util/concurrent/Concurrent.h>
+#include <decaf/util/concurrent/atomic/AtomicBoolean.h>
 
 namespace activemq{
 namespace connector{
@@ -41,7 +42,7 @@
         /**
          * Have we started already?
          */
-        bool firstTime;
+        decaf::util::concurrent::atomic::AtomicBoolean firstTime;
 
         /**
          * Latch objects to count down till we receive the wireFormat info

Modified: activemq/activemq-cpp/trunk/src/main/activemq/core/ActiveMQConnectionFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/core/ActiveMQConnectionFactory.h?rev=690258&r1=690257&r2=690258&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/core/ActiveMQConnectionFactory.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/core/ActiveMQConnectionFactory.h Fri Aug
29 06:55:40 2008
@@ -25,8 +25,7 @@
 namespace activemq{
 namespace core{
 
-    class AMQCPP_API ActiveMQConnectionFactory : public cms::ConnectionFactory
-    {
+    class AMQCPP_API ActiveMQConnectionFactory : public cms::ConnectionFactory {
     private:
 
         // The user name this factory will use to connect
@@ -41,7 +40,7 @@
 
     public:
 
-           ActiveMQConnectionFactory();
+        ActiveMQConnectionFactory();
 
         /**
          * Constructor
@@ -53,7 +52,7 @@
                                    const std::string& username = "",
                                    const std::string& password = "" );
 
-           virtual ~ActiveMQConnectionFactory() {}
+        virtual ~ActiveMQConnectionFactory() {}
 
         /**
          * Creates a connection with the default user identity. The

Modified: activemq/activemq-cpp/trunk/src/main/activemq/transport/filters/ResponseCorrelator.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/filters/ResponseCorrelator.cpp?rev=690258&r1=690257&r2=690258&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/filters/ResponseCorrelator.cpp
(original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/filters/ResponseCorrelator.cpp
Fri Aug 29 06:55:40 2008
@@ -25,30 +25,12 @@
 using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
-unsigned int ResponseCorrelator::getNextCommandId()
-    throw ( activemq::exceptions::ActiveMQException ){
-
-    try{
-
-        synchronized( &commandIdMutex ){
-            return ++nextCommandId;
-        }
-
-        // Should never get here, but some compilers aren't
-        // smart enough to figure out we'll never get here.
-        return 0;
-    }
-    AMQ_CATCH_RETHROW( exceptions::ActiveMQException )
-    AMQ_CATCH_EXCEPTION_CONVERT( Exception, ActiveMQException )
-    AMQ_CATCHALL_THROW( exceptions::ActiveMQException )
-}
-
-////////////////////////////////////////////////////////////////////////////////
 ResponseCorrelator::ResponseCorrelator( Transport* next, bool own )
 :
     TransportFilter( next, own ) {
 
-    nextCommandId = 0;
+    //nextCommandId = 0;
+    nextCommandId.set(1);
     // Start in the closed state.
     closed = true;
 }
@@ -68,7 +50,7 @@
     throw( CommandIOException, decaf::lang::exceptions::UnsupportedOperationException ) {
 
     try{
-        command->setCommandId( getNextCommandId() );
+        command->setCommandId( nextCommandId.getAndIncrement() );
         command->setResponseRequired( false );
 
         if( closed || next == NULL ){
@@ -90,7 +72,7 @@
     throw( CommandIOException, decaf::lang::exceptions::UnsupportedOperationException ) {
 
     try{
-        command->setCommandId( getNextCommandId() );
+        command->setCommandId( nextCommandId.getAndIncrement() );
         command->setResponseRequired( true );
 
         // Add a future response object to the map indexed by this
@@ -147,7 +129,7 @@
     throw( CommandIOException, decaf::lang::exceptions::UnsupportedOperationException ) {
 
     try{
-        command->setCommandId( getNextCommandId() );
+        command->setCommandId( nextCommandId.getAndIncrement() );
         command->setResponseRequired( true );
 
         // Add a future response object to the map indexed by this

Modified: activemq/activemq-cpp/trunk/src/main/activemq/transport/filters/ResponseCorrelator.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/filters/ResponseCorrelator.h?rev=690258&r1=690257&r2=690258&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/filters/ResponseCorrelator.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/filters/ResponseCorrelator.h Fri
Aug 29 06:55:40 2008
@@ -24,6 +24,7 @@
 #include <activemq/transport/Command.h>
 #include <decaf/util/concurrent/Mutex.h>
 #include <decaf/util/concurrent/Concurrent.h>
+#include <decaf/util/concurrent/atomic/AtomicInteger.h>
 #include <map>
 #include <stdio.h>
 
@@ -43,7 +44,7 @@
         /**
          * The next command id for sent commands.
          */
-        unsigned int nextCommandId;
+        decaf::util::concurrent::atomic::AtomicInteger nextCommandId;
 
         /**
          * Map of request ids to future response objects.
@@ -51,11 +52,6 @@
         std::map<unsigned int, FutureResponse*> requestMap;
 
         /**
-         * Sync object for accessing the next command id variable.
-         */
-        decaf::util::concurrent::Mutex commandIdMutex;
-
-        /**
          * Sync object for accessing the request map.
          */
         decaf::util::concurrent::Mutex mapMutex;
@@ -65,13 +61,6 @@
          */
         bool closed;
 
-    private:
-
-        /**
-         * Returns the next available command id.
-         */
-        unsigned int getNextCommandId() throw ( exceptions::ActiveMQException );
-
     public:
 
         /**



Mime
View raw message