Return-Path: Delivered-To: apmail-qpid-commits-archive@www.apache.org Received: (qmail 26106 invoked from network); 14 Mar 2011 16:30:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Mar 2011 16:30:36 -0000 Received: (qmail 43421 invoked by uid 500); 14 Mar 2011 16:30:36 -0000 Delivered-To: apmail-qpid-commits-archive@qpid.apache.org Received: (qmail 43392 invoked by uid 500); 14 Mar 2011 16:30:36 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 43385 invoked by uid 99); 14 Mar 2011 16:30:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Mar 2011 16:30:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Mon, 14 Mar 2011 16:30:35 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 400B3238890D; Mon, 14 Mar 2011 16:30:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1081450 - in /qpid/trunk/qpid/cpp/src/qpid/broker: TopicExchange.cpp TopicExchange.h Date: Mon, 14 Mar 2011 16:30:13 -0000 To: commits@qpid.apache.org From: cctrieloff@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110314163013.400B3238890D@eris.apache.org> Author: cctrieloff Date: Mon Mar 14 16:30:12 2011 New Revision: 1081450 URL: http://svn.apache.org/viewvc?rev=1081450&view=rev Log: QPID-3138 some cosmetic cleanup & correction for IVE Modified: qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.cpp qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.h Modified: qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.cpp?rev=1081450&r1=1081449&r2=1081450&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.cpp Mon Mar 14 16:30:12 2011 @@ -221,7 +221,7 @@ TopicExchange::TopicExchange(const std:: 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_p } } + 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_p } 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& m { // Note: PERFORMANCE CRITICAL!!! BindingList b; - std::map::iterator it; - { // only lock the cache for read + std::map::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 >); 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); } Modified: qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.h URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.h?rev=1081450&r1=1081449&r2=1081450&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.h (original) +++ qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.h Mon Mar 14 16:30:12 2011 @@ -136,18 +136,26 @@ class TopicExchange : public virtual Exc unsigned long nBindings; qpid::sys::RWlock lock; // protects bindingTree and nBindings qpid::sys::RWlock cacheLock; // protects cache - std::map bindingCache; // cache of matched routes. - class ClearCache { - private: - qpid::sys::RWlock* cacheLock; - std::map* bindingCache; - public: - ClearCache(qpid::sys::RWlock* l, std::map* bc): cacheLock(l),bindingCache(bc) {}; - ~ClearCache(){ - qpid::sys::RWlock::ScopedWlock l(*cacheLock); - bindingCache->clear(); - }; - }; + std::map bindingCache; // cache of matched routes. + class ClearCache { + private: + qpid::sys::RWlock* cacheLock; + std::map* bindingCache; + bool cleared; + public: + ClearCache(qpid::sys::RWlock* l, std::map* 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; --------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:commits-subscribe@qpid.apache.org