]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - pdns/auth-packetcache.cc
Merge pull request #9070 from rgacogne/boost-173
[thirdparty/pdns.git] / pdns / auth-packetcache.cc
index 094c1f63ba1c15aae7fdca130378d57c797d3ed7..759864e58888323b83981edccd7e210e9c004ad7 100644 (file)
@@ -46,18 +46,24 @@ AuthPacketCache::AuthPacketCache(size_t mapsCount): d_maps(mapsCount), d_lastcle
 AuthPacketCache::~AuthPacketCache()
 {
   try {
-    vector<WriteLock*> locks;
+    vector<WriteLock> locks;
     for(auto& mc : d_maps) {
-      locks.push_back(new WriteLock(&mc.d_mut));
-    }
-    for(auto wl : locks) {
-      delete wl;
+      locks.push_back(WriteLock(mc.d_mut));
     }
+    locks.clear();
   }
   catch(...) {
   }
 }
 
+void AuthPacketCache::MapCombo::reserve(size_t numberOfEntries)
+{
+#if BOOST_VERSION >= 105600
+  WriteLock wl(&d_mut);
+  d_map.get<HashTag>().reserve(numberOfEntries);
+#endif /* BOOST_VERSION >= 105600 */
+}
+
 bool AuthPacketCache::get(DNSPacket& p, DNSPacket& cached)
 {
   if(!d_ttl) {
@@ -162,7 +168,7 @@ void AuthPacketCache::insert(DNSPacket& q, DNSPacket& r, unsigned int maxTTL)
     }
 
     /* no existing entry found to refresh */
-    mc.d_map.insert(entry);
+    mc.d_map.insert(std::move(entry));
 
     if (*d_statnumentries >= d_maxEntries) {
       /* remove the least recently inserted or replaced entry */
@@ -170,7 +176,7 @@ void AuthPacketCache::insert(DNSPacket& q, DNSPacket& r, unsigned int maxTTL)
       sidx.pop_front();
     }
     else {
-      (*d_statnumentries)++;
+      ++(*d_statnumentries);
     }
   }
 }
@@ -240,11 +246,7 @@ uint64_t AuthPacketCache::purge(const string &match)
                           
 void AuthPacketCache::cleanup()
 {
-  uint64_t maxCached = d_maxEntries;
-  uint64_t cacheSize = *d_statnumentries;
-  uint64_t totErased = 0;
-
-  totErased = pruneLockedCollectionsVector<SequencedTag>(d_maps, maxCached, cacheSize);
+  uint64_t totErased = pruneLockedCollectionsVector<SequencedTag>(d_maps);
   *d_statnumentries -= totErased;
 
   DLOG(g_log<<"Done with cache clean, cacheSize: "<<(*d_statnumentries)<<", totErased"<<totErased<<endl);