Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
omoerbeek committed Jun 26, 2024
1 parent 6a27dba commit 206a6b9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
39 changes: 20 additions & 19 deletions pdns/cachecleaner.hh
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ void pruneCollection(T& collection, size_t maxCached, size_t scanFraction = 1000
template <typename S, typename T>
void moveCacheItemToFrontOrBack(T& collection, typename T::iterator& iter, bool front)
{
typedef typename T::template index<S>::type sequence_t;
sequence_t& sidx = collection.template get<S>();
typename sequence_t::iterator si = collection.template project<S>(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<S>();
auto siter = collection.template project<S>(iter);
if (front) {
sidx.relocate(sidx.begin(), siter); // at the beginning of the delete queue
}
else {
sidx.relocate(sidx.end(), siter); // back
}
}

template <typename S, typename T>
Expand All @@ -108,8 +109,8 @@ uint64_t pruneLockedCollectionsVector(std::vector<T>& 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;
Expand Down Expand Up @@ -240,8 +241,8 @@ uint64_t purgeLockedCollectionsVector(std::vector<T>& 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();
}
Expand All @@ -256,8 +257,8 @@ uint64_t purgeLockedCollectionsVector(std::vector<T>& 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<N>(*map);
auto iter = idx.lower_bound(dprefix);
auto start = iter;
Expand All @@ -275,10 +276,10 @@ uint64_t purgeLockedCollectionsVector(std::vector<T>& maps, const std::string& m
}

template <typename N, typename T>
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<N>(*map);
auto range = idx.equal_range(qname);
if (range.first != range.second) {
Expand All @@ -290,12 +291,12 @@ uint64_t purgeExactLockedCollection(T& mc, const DNSName& qname)
}

template <typename S, typename Index>
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<S>(i, inserted.first);
i.replace(inserted.first, x);
moveCacheItemToBack<S>(index, inserted.first);
index.replace(inserted.first, value);
return false;
}
return true;
Expand Down
24 changes: 19 additions & 5 deletions pdns/lock.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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))
{
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion pdns/sholder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public:
++d_generation;
}

typedef T value_type;
using value_type = T;

private:
unsigned int getGeneration() const
Expand Down

0 comments on commit 206a6b9

Please sign in to comment.