From 206a6b9c588f697575450b55c07e012de8f71eec Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Wed, 26 Jun 2024 11:53:57 +0200 Subject: [PATCH] Tidy --- pdns/cachecleaner.hh | 39 ++++++++++++++++++++------------------- pdns/lock.hh | 24 +++++++++++++++++++----- pdns/sholder.hh | 2 +- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/pdns/cachecleaner.hh b/pdns/cachecleaner.hh index aaf798152aa3..13160036366b 100644 --- a/pdns/cachecleaner.hh +++ b/pdns/cachecleaner.hh @@ -81,13 +81,14 @@ void pruneCollection(T& collection, size_t maxCached, size_t scanFraction = 1000 template void moveCacheItemToFrontOrBack(T& collection, typename T::iterator& iter, bool front) { - typedef typename T::template index::type sequence_t; - sequence_t& sidx = collection.template get(); - typename sequence_t::iterator si = collection.template project(iter); - if (front) - sidx.relocate(sidx.begin(), si); // at the beginning of the delete queue - else - sidx.relocate(sidx.end(), si); // back + auto& sidx = collection.template get(); + auto siter = collection.template project(iter); + if (front) { + sidx.relocate(sidx.begin(), siter); // at the beginning of the delete queue + } + else { + sidx.relocate(sidx.end(), siter); // back + } } template @@ -108,8 +109,8 @@ uint64_t pruneLockedCollectionsVector(std::vector& maps) uint64_t totErased = 0; time_t now = time(nullptr); - for (auto& mc : maps) { - auto map = mc.d_map.write_lock(); + for (auto& shard : maps) { + auto map = shard.d_map.write_lock(); uint64_t lookAt = (map->size() + 9) / 10; // Look at 10% of this shard uint64_t erased = 0; @@ -240,8 +241,8 @@ uint64_t purgeLockedCollectionsVector(std::vector& maps) { uint64_t delcount = 0; - for (auto& mc : maps) { - auto map = mc.d_map.write_lock(); + for (auto& shard : maps) { + auto map = shard.d_map.write_lock(); delcount += map->size(); map->clear(); } @@ -256,8 +257,8 @@ uint64_t purgeLockedCollectionsVector(std::vector& maps, const std::string& m std::string prefix(match); prefix.resize(prefix.size() - 1); DNSName dprefix(prefix); - for (auto& mc : maps) { - auto map = mc.d_map.write_lock(); + for (auto& shard : maps) { + auto map = shard.d_map.write_lock(); auto& idx = boost::multi_index::get(*map); auto iter = idx.lower_bound(dprefix); auto start = iter; @@ -275,10 +276,10 @@ uint64_t purgeLockedCollectionsVector(std::vector& maps, const std::string& m } template -uint64_t purgeExactLockedCollection(T& mc, const DNSName& qname) +uint64_t purgeExactLockedCollection(T& shard, const DNSName& qname) { uint64_t delcount = 0; - auto map = mc.d_map.write_lock(); + auto map = shard.d_map.write_lock(); auto& idx = boost::multi_index::get(*map); auto range = idx.equal_range(qname); if (range.first != range.second) { @@ -290,12 +291,12 @@ uint64_t purgeExactLockedCollection(T& mc, const DNSName& qname) } template -bool lruReplacingInsert(Index& i, const typename Index::value_type& x) +bool lruReplacingInsert(Index& index, const typename Index::value_type& value) { - auto inserted = i.insert(x); + auto inserted = index.insert(value); if (!inserted.second) { - moveCacheItemToBack(i, inserted.first); - i.replace(inserted.first, x); + moveCacheItemToBack(index, inserted.first); + index.replace(inserted.first, value); return false; } return true; diff --git a/pdns/lock.hh b/pdns/lock.hh index 9a289660e63e..c413ceeab4d9 100644 --- a/pdns/lock.hh +++ b/pdns/lock.hh @@ -82,9 +82,11 @@ class ReadWriteLock { public: ReadWriteLock() = default; + ~ReadWriteLock() = default; ReadWriteLock(const ReadWriteLock& rhs) = delete; ReadWriteLock(ReadWriteLock&& rhs) = delete; + ReadWriteLock& operator=(ReadWriteLock&&) = delete; ReadWriteLock& operator=(const ReadWriteLock& rhs) = delete; std::shared_mutex& getLock() @@ -109,8 +111,11 @@ public: { } + ~ReadLock() = default; ReadLock(const ReadLock& rhs) = delete; ReadLock& operator=(const ReadLock& rhs) = delete; + ReadLock& operator=(ReadLock&&) = delete; + ReadLock(ReadLock&& rhs) noexcept : d_lock(std::move(rhs.d_lock)) { @@ -138,8 +143,11 @@ public: { } + ~WriteLock() = default; WriteLock(const WriteLock& rhs) = delete; WriteLock& operator=(const WriteLock& rhs) = delete; + WriteLock& operator=(WriteLock&&) = delete; + WriteLock(WriteLock&& rhs) noexcept : d_lock(std::move(rhs.d_lock)) { @@ -167,10 +175,13 @@ public: { } + ~TryReadLock() = default; TryReadLock(const TryReadLock& rhs) = delete; + TryReadLock(TryReadLock&&) = delete; TryReadLock& operator=(const TryReadLock& rhs) = delete; + TryReadLock& operator=(TryReadLock&&) = delete; - bool gotIt() const + [[nodiscard]] bool gotIt() const { return d_lock.owns_lock(); } @@ -197,10 +208,13 @@ public: { } + ~TryWriteLock() = default; TryWriteLock(const TryWriteLock& rhs) = delete; + TryWriteLock(TryWriteLock&&) = delete; TryWriteLock& operator=(const TryWriteLock& rhs) = delete; + TryWriteLock& operator=(TryWriteLock&&) = delete; - bool gotIt() const + [[nodiscard]] bool gotIt() const { return d_lock.owns_lock(); } @@ -268,7 +282,7 @@ public: return d_lock.owns_lock(); } - bool owns_lock() const noexcept + [[nodiscard]] bool owns_lock() const noexcept { return d_lock.owns_lock(); } @@ -373,7 +387,7 @@ public: return d_lock.owns_lock(); } - bool owns_lock() const noexcept + [[nodiscard]] bool owns_lock() const noexcept { return d_lock.owns_lock(); } @@ -437,7 +451,7 @@ public: return d_lock.owns_lock(); } - bool owns_lock() const noexcept + [[nodiscard]] bool owns_lock() const noexcept { return d_lock.owns_lock(); } diff --git a/pdns/sholder.hh b/pdns/sholder.hh index 74727c56736c..f26dd250bdff 100644 --- a/pdns/sholder.hh +++ b/pdns/sholder.hh @@ -132,7 +132,7 @@ public: ++d_generation; } - typedef T value_type; + using value_type = T; private: unsigned int getGeneration() const