summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorCarl C. Trieloff <cctrieloff@apache.org>2011-03-14 16:30:12 +0000
committerCarl C. Trieloff <cctrieloff@apache.org>2011-03-14 16:30:12 +0000
commit0eb58a5ff1f5dbdd4f9b85e083207bdef041e9bf (patch)
treef57d6deb09c3af011d9c1ee61284eeaa8ba7c12b /cpp/src
parent44315b319809b3d0b51a8843ad349913050d5e66 (diff)
downloadqpid-python-0eb58a5ff1f5dbdd4f9b85e083207bdef041e9bf.tar.gz
QPID-3138 some cosmetic cleanup & correction for IVE
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1081450 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/broker/TopicExchange.cpp26
-rw-r--r--cpp/src/qpid/broker/TopicExchange.h32
2 files changed, 34 insertions, 24 deletions
diff --git a/cpp/src/qpid/broker/TopicExchange.cpp b/cpp/src/qpid/broker/TopicExchange.cpp
index f3baf00d1f..4447790766 100644
--- a/cpp/src/qpid/broker/TopicExchange.cpp
+++ b/cpp/src/qpid/broker/TopicExchange.cpp
@@ -221,7 +221,7 @@ TopicExchange::TopicExchange(const std::string& _name, bool _durable,
bool TopicExchange::bind(Queue::shared_ptr queue, const string& routingKey, const FieldTable* args)
{
- ClearCache cc(&cacheLock,&bindingCache); // clear the cache on function exit.
+ ClearCache cc(&cacheLock,&bindingCache); // clear the cache on function exit.
string fedOp(args ? args->getAsString(qpidFedOp) : fedOpBind);
string fedTags(args ? args->getAsString(qpidFedTags) : "");
string fedOrigin(args ? args->getAsString(qpidFedOrigin) : "");
@@ -282,6 +282,7 @@ bool TopicExchange::bind(Queue::shared_ptr queue, const string& routingKey, cons
}
}
+ cc.clearCache(); // clear the cache before we IVE route.
routeIVE();
if (propagate)
propagateFedOp(routingKey, fedTags, fedOp, fedOrigin);
@@ -289,7 +290,7 @@ bool TopicExchange::bind(Queue::shared_ptr queue, const string& routingKey, cons
}
bool TopicExchange::unbind(Queue::shared_ptr queue, const string& constRoutingKey, const FieldTable* /*args*/){
- ClearCache cc(&cacheLock,&bindingCache); // clear the cache on function exit.
+ ClearCache cc(&cacheLock,&bindingCache); // clear the cache on function exit.
RWlock::ScopedWlock l(lock);
string routingKey = normalize(constRoutingKey);
BindingKey* bk = bindingTree.getBindingKey(routingKey);
@@ -336,23 +337,24 @@ void TopicExchange::route(Deliverable& msg, const string& routingKey, const Fiel
{
// Note: PERFORMANCE CRITICAL!!!
BindingList b;
- std::map<std::string, BindingList>::iterator it;
- { // only lock the cache for read
+ std::map<std::string, BindingList>::iterator it;
+ { // only lock the cache for read
RWlock::ScopedRlock cl(cacheLock);
- it = bindingCache.find(routingKey);
- }
+ it = bindingCache.find(routingKey);
+ if (it != bindingCache.end()) {
+ b = it->second;
+ }
+ }
PreRoute pr(msg, this);
- if (it == bindingCache.end()) // no cache hit
+ if (!b.get()) // no cache hit
{
RWlock::ScopedRlock l(lock);
b = BindingList(new std::vector<boost::shared_ptr<qpid::broker::Exchange::Binding> >);
BindingsFinderIter bindingsFinder(b);
bindingTree.iterateMatch(routingKey, bindingsFinder);
- RWlock::ScopedWlock cwl(cacheLock);
- bindingCache[routingKey] = b; // update cache
- }else {
- b = it->second;
- }
+ RWlock::ScopedWlock cwl(cacheLock);
+ bindingCache[routingKey] = b; // update cache
+ }
doRoute(msg, b);
}
diff --git a/cpp/src/qpid/broker/TopicExchange.h b/cpp/src/qpid/broker/TopicExchange.h
index 3d2b3a95a9..79a9b0b021 100644
--- a/cpp/src/qpid/broker/TopicExchange.h
+++ b/cpp/src/qpid/broker/TopicExchange.h
@@ -136,18 +136,26 @@ class TopicExchange : public virtual Exchange {
unsigned long nBindings;
qpid::sys::RWlock lock; // protects bindingTree and nBindings
qpid::sys::RWlock cacheLock; // protects cache
- std::map<std::string, BindingList> bindingCache; // cache of matched routes.
- class ClearCache {
- private:
- qpid::sys::RWlock* cacheLock;
- std::map<std::string, BindingList>* bindingCache;
- public:
- ClearCache(qpid::sys::RWlock* l, std::map<std::string, BindingList>* bc): cacheLock(l),bindingCache(bc) {};
- ~ClearCache(){
- qpid::sys::RWlock::ScopedWlock l(*cacheLock);
- bindingCache->clear();
- };
- };
+ std::map<std::string, BindingList> bindingCache; // cache of matched routes.
+ class ClearCache {
+ private:
+ qpid::sys::RWlock* cacheLock;
+ std::map<std::string, BindingList>* bindingCache;
+ bool cleared;
+ public:
+ ClearCache(qpid::sys::RWlock* l, std::map<std::string, BindingList>* bc): cacheLock(l),
+ bindingCache(bc),cleared(false) {};
+ void clearCache() {
+ qpid::sys::RWlock::ScopedWlock l(*cacheLock);
+ if (!cleared) {
+ bindingCache->clear();
+ cleared =true;
+ }
+ };
+ ~ClearCache(){
+ clearCache();
+ };
+ };
bool isBound(Queue::shared_ptr queue, const std::string& pattern);
class ReOriginIter;