Make target interval more explicit
This commit is contained in:
parent
f6ad9d7800
commit
8c32228ef7
3 changed files with 5 additions and 12 deletions
|
|
@ -7,12 +7,7 @@ namespace nano
|
||||||
class interval
|
class interval
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit interval (std::chrono::milliseconds target) :
|
bool elapsed (auto target)
|
||||||
target{ target }
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool elapsed ()
|
|
||||||
{
|
{
|
||||||
auto const now = std::chrono::steady_clock::now ();
|
auto const now = std::chrono::steady_clock::now ();
|
||||||
if (now - last >= target)
|
if (now - last >= target)
|
||||||
|
|
@ -24,7 +19,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::chrono::milliseconds const target;
|
|
||||||
std::chrono::steady_clock::time_point last{ std::chrono::steady_clock::now () };
|
std::chrono::steady_clock::time_point last{ std::chrono::steady_clock::now () };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,7 @@ public:
|
||||||
|
|
||||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||||
|
|
||||||
if (cleanup_interval.elapsed ())
|
if (cleanup_interval.elapsed (cleanup_cutoff))
|
||||||
{
|
{
|
||||||
cleanup ();
|
cleanup ();
|
||||||
}
|
}
|
||||||
|
|
@ -75,6 +75,6 @@ private:
|
||||||
private:
|
private:
|
||||||
mutable nano::mutex mutex;
|
mutable nano::mutex mutex;
|
||||||
std::unordered_map<Key, std::weak_ptr<Value>> values;
|
std::unordered_map<Key, std::weak_ptr<Value>> values;
|
||||||
nano::interval cleanup_interval{ cleanup_cutoff };
|
nano::interval cleanup_interval;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -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) :
|
nano::vote_cache::vote_cache (vote_cache_config const & config_a, nano::stats & stats_a) :
|
||||||
config{ config_a },
|
config{ config_a },
|
||||||
stats{ stats_a },
|
stats{ stats_a }
|
||||||
cleanup_interval{ config_a.age_cutoff / 2 }
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -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 };
|
nano::lock_guard<nano::mutex> lock{ mutex };
|
||||||
|
|
||||||
if (cleanup_interval.elapsed ())
|
if (cleanup_interval.elapsed (config.age_cutoff / 2))
|
||||||
{
|
{
|
||||||
cleanup ();
|
cleanup ();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue