Make target interval more explicit

This commit is contained in:
Piotr Wójcik 2024-03-24 13:48:42 +01:00
commit 8c32228ef7
3 changed files with 5 additions and 12 deletions

View file

@ -7,12 +7,7 @@ namespace nano
class interval
{
public:
explicit interval (std::chrono::milliseconds target) :
target{ target }
{
}
bool elapsed ()
bool elapsed (auto target)
{
auto const now = std::chrono::steady_clock::now ();
if (now - last >= target)
@ -24,7 +19,6 @@ public:
}
private:
std::chrono::milliseconds const target;
std::chrono::steady_clock::time_point last{ std::chrono::steady_clock::now () };
};
}

View file

@ -27,7 +27,7 @@ public:
nano::lock_guard<nano::mutex> guard{ mutex };
if (cleanup_interval.elapsed ())
if (cleanup_interval.elapsed (cleanup_cutoff))
{
cleanup ();
}
@ -75,6 +75,6 @@ private:
private:
mutable nano::mutex mutex;
std::unordered_map<Key, std::weak_ptr<Value>> values;
nano::interval cleanup_interval{ cleanup_cutoff };
nano::interval cleanup_interval;
};
}

View file

@ -123,8 +123,7 @@ std::chrono::steady_clock::time_point nano::vote_cache_entry::last_vote () const
nano::vote_cache::vote_cache (vote_cache_config const & config_a, nano::stats & stats_a) :
config{ config_a },
stats{ stats_a },
cleanup_interval{ config_a.age_cutoff / 2 }
stats{ stats_a }
{
}
@ -239,7 +238,7 @@ std::vector<nano::vote_cache::top_entry> nano::vote_cache::top (const nano::uint
{
nano::lock_guard<nano::mutex> lock{ mutex };
if (cleanup_interval.elapsed ())
if (cleanup_interval.elapsed (config.age_cutoff / 2))
{
cleanup ();
}