From: Kees Monshouwer Date: Mon, 26 Sep 2016 18:30:20 +0000 (+0200) Subject: remove unnecessary locking in packetcache X-Git-Tag: dnsdist-1.1.0-beta2~108^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04139820afcd728555d57baabb66b2341069e4d1;p=thirdparty%2Fpdns.git remove unnecessary locking in packetcache --- diff --git a/pdns/packetcache.cc b/pdns/packetcache.cc index 8a8f65a6ca..ddb625cd11 100644 --- a/pdns/packetcache.cc +++ b/pdns/packetcache.cc @@ -390,25 +390,10 @@ map PacketCache::getCounts() return ret; } -int PacketCache::size() -{ - uint64_t ret=0; - for(auto& mc : d_maps) { - ReadLock l(&mc.d_mut); - ret+=mc.d_map.size(); - } - return ret; -} /** readlock for figuring out which iterators to delete, upgrade to writelock when actually cleaning */ void PacketCache::cleanup() { - d_statnumentries->store(0); - for(auto& mc : d_maps) { - ReadLock l(&mc.d_mut); - - *d_statnumentries+=mc.d_map.size(); - } unsigned int maxCached=::arg().asNum("max-cache-entries"); unsigned int toTrim=0; @@ -429,7 +414,7 @@ void PacketCache::cleanup() // cerr<<"cacheSize: "<::type sequence_t; @@ -450,16 +435,12 @@ void PacketCache::cleanup() if(lookedAt > lookAt / d_maps.size()) break; } - //totErased += erased; + totErased += erased; } // if(totErased) // cerr<<"erased: "<store(0); - for(auto& mc : d_maps) { - ReadLock l(&mc.d_mut); - *d_statnumentries+=mc.d_map.size(); - } + *d_statnumentries-=totErased; DLOG(L<<"Done with cache clean"<& entry, int zoneID=-1); - int size(); //!< number of entries in the cache + int size() { return *d_statnumentries; } //!< number of entries in the cache void cleanupIfNeeded() { if(!(++d_ops % 300000)) {