qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r748723 - in /qpid/trunk/qpid/cpp/src/qpid: assert.cpp cluster/ConnectionMap.cpp cluster/ConnectionMap.h
Date Fri, 27 Feb 2009 22:27:12 GMT
Author: aconway
Date: Fri Feb 27 22:27:11 2009
New Revision: 748723

URL: http://svn.apache.org/viewvc?rev=748723&view=rev
Log:
Add lock to cluster::ConnectionMap, make it thread safe.

Modified:
    qpid/trunk/qpid/cpp/src/qpid/assert.cpp
    qpid/trunk/qpid/cpp/src/qpid/cluster/ConnectionMap.cpp
    qpid/trunk/qpid/cpp/src/qpid/cluster/ConnectionMap.h

Modified: qpid/trunk/qpid/cpp/src/qpid/assert.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/assert.cpp?rev=748723&r1=748722&r2=748723&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/assert.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/assert.cpp Fri Feb 27 22:27:11 2009
@@ -35,7 +35,7 @@
 #ifdef NDEBUG
     throw framing::InternalErrorException(msg.str());
 #else
-    std::cerr << msg << std::endl;
+    std::cerr << msg.str() << std::endl;
     abort();
 #endif
 }

Modified: qpid/trunk/qpid/cpp/src/qpid/cluster/ConnectionMap.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/cluster/ConnectionMap.cpp?rev=748723&r1=748722&r2=748723&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/cluster/ConnectionMap.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/cluster/ConnectionMap.cpp Fri Feb 27 22:27:11 2009
@@ -22,30 +22,29 @@
 #include "Cluster.h"
 #include "qpid/framing/reply_exceptions.h"
 #include "qpid/log/Statement.h"
+#include "qpid/assert.h"
 
 namespace qpid {
 namespace cluster {
 
 using framing::InternalErrorException;
+typedef sys::Mutex::ScopedLock Lock;
 
 void ConnectionMap::insert(ConnectionPtr p) {
+    Lock l(lock);
     std::pair<Map::iterator, bool> ib = map.insert(Map::value_type(p->getId(), p));
-    if (!ib.second) {
-        assert(0);
-        throw InternalErrorException(QPID_MSG("Duplicate connection replica: " << p->getId()));
-    }
+    QPID_ASSERT(ib.second);
 }
 
 void ConnectionMap::erase(const ConnectionId& id) {
+    Lock l(lock);
     Map::iterator i = map.find(id);
-    if (i == map.end()) {
-        assert(0);
-        QPID_LOG(warning, "Erase non-existent connection replica: " << id);
-    }
+    QPID_ASSERT(i != map.end());
     map.erase(i);
 }
 
 ConnectionMap::ConnectionPtr ConnectionMap::get(const ConnectionId& id) {
+    Lock l(lock);
     Map::const_iterator i = map.find(id);
     if (i == map.end()) {
         // Deleted local connection.
@@ -56,21 +55,21 @@
         mgmtId << id;
         ConnectionPtr cp = new Connection(cluster, shadowOut, mgmtId.str(), id);
         std::pair<Map::iterator, bool> ib = map.insert(Map::value_type(id, cp)); 
-        if (!ib.second)
-            throw InternalErrorException(QPID_MSG("Duplicate entry in cluster connection
map: " << id));
+        QPID_ASSERT(ib.second);
         i = ib.first;
     }
     return i->second;
 }
 
 ConnectionMap::ConnectionPtr ConnectionMap::getLocal(const ConnectionId& id) {
+    Lock l(lock);
     if (id.getMember() != cluster.getId()) return 0;
     Map::const_iterator i = map.find(id);
-    assert(i != map.end());     // FIXME aconway 2009-02-11: remove or exception.
     return i == map.end() ? 0 : i->second;
 }
 
 ConnectionMap::Vector ConnectionMap::values() const {
+    Lock l(lock);
     Vector result(map.size());
     std::transform(map.begin(), map.end(), result.begin(),
                    boost::bind(&Map::value_type::second, _1));
@@ -78,6 +77,7 @@
 }
 
 void ConnectionMap::update(MemberId myId, const ClusterMap& cluster) {
+    Lock l(lock);
     for (Map::iterator i = map.begin(); i != map.end(); ) {
         MemberId member = i->first.getMember();
         if (member != myId && !cluster.isMember(member)) { 
@@ -90,6 +90,7 @@
 }
 
 void ConnectionMap::clear() {
+    Lock l(lock);
     map.clear();
 }
 

Modified: qpid/trunk/qpid/cpp/src/qpid/cluster/ConnectionMap.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/cluster/ConnectionMap.h?rev=748723&r1=748722&r2=748723&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/cluster/ConnectionMap.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/cluster/ConnectionMap.h Fri Feb 27 22:27:11 2009
@@ -77,6 +77,7 @@
   private:
     typedef std::map<ConnectionId, ConnectionPtr> Map;
 
+    mutable sys::Mutex lock;
     Cluster& cluster;
     NoOpConnectionOutputHandler shadowOut;
     Map map;



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message