]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
remove unnecessary locking in packetcache
authorKees Monshouwer <mind04@monshouwer.org>
Mon, 26 Sep 2016 18:30:20 +0000 (20:30 +0200)
committermind04 <mind04@monshouwer.org>
Mon, 26 Sep 2016 18:37:05 +0000 (20:37 +0200)
pdns/packetcache.cc
pdns/packetcache.hh

index 8a8f65a6ca759fa9fe2d10aa0de74049eab83146..ddb625cd11940e2ea4ffa0988ea036a2fac5c508 100644 (file)
@@ -390,25 +390,10 @@ map<char,int> 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: "<<cacheSize<<", lookAt: "<<lookAt<<", toTrim: "<<toTrim<<endl;
   time_t now=time(0);
   DLOG(L<<"Starting cache clean"<<endl);
-  //unsigned int totErased=0;
+  unsigned int totErased=0;
   for(auto& mc : d_maps) {
     WriteLock wl(&mc.d_mut);
     typedef cmap_t::nth_index<1>::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: "<<totErased<<endl;
   
-  d_statnumentries->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"<<endl);
 }
index 172524ab3b96f10d33cfe75e39d306bc73768e97..22e455a48cde033fb668fa2b970086ed69c138ac 100644 (file)
@@ -68,7 +68,7 @@ public:
   bool getEntry(const DNSName &qname, const QType& qtype, CacheEntryType cet, vector<DNSZoneRecord>& 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)) {