Fix hinted_scheduler
stop (#4079)
This commit is contained in:
parent
081ba95884
commit
cc81a45df0
2 changed files with 17 additions and 16 deletions
|
@ -8,33 +8,34 @@ nano::hinted_scheduler::hinted_scheduler (config const & config_a, nano::node &
|
|||
inactive_vote_cache{ inactive_vote_cache_a },
|
||||
active{ active_a },
|
||||
online_reps{ online_reps_a },
|
||||
stats{ stats_a },
|
||||
stopped{ false }
|
||||
stats{ stats_a }
|
||||
{
|
||||
}
|
||||
|
||||
nano::hinted_scheduler::~hinted_scheduler ()
|
||||
{
|
||||
stop ();
|
||||
if (thread.joinable ()) // Ensure thread was started
|
||||
{
|
||||
thread.join ();
|
||||
}
|
||||
// Thread must be stopped before destruction
|
||||
debug_assert (!thread.joinable ());
|
||||
}
|
||||
|
||||
void nano::hinted_scheduler::start ()
|
||||
{
|
||||
debug_assert (!thread.joinable ());
|
||||
thread = std::thread{
|
||||
[this] () { run (); }
|
||||
};
|
||||
|
||||
thread = std::thread{ [this] () {
|
||||
nano::thread_role::set (nano::thread_role::name::election_hinting);
|
||||
run ();
|
||||
} };
|
||||
}
|
||||
|
||||
void nano::hinted_scheduler::stop ()
|
||||
{
|
||||
nano::unique_lock<nano::mutex> lock{ mutex };
|
||||
stopped = true;
|
||||
{
|
||||
nano::lock_guard<nano::mutex> lock{ mutex };
|
||||
stopped = true;
|
||||
}
|
||||
notify ();
|
||||
nano::join_or_pass (thread);
|
||||
}
|
||||
|
||||
void nano::hinted_scheduler::notify ()
|
||||
|
@ -91,7 +92,6 @@ bool nano::hinted_scheduler::run_one (nano::uint128_t const & minimum_tally)
|
|||
|
||||
void nano::hinted_scheduler::run ()
|
||||
{
|
||||
nano::thread_role::set (nano::thread_role::name::election_hinting);
|
||||
nano::unique_lock<nano::mutex> lock{ mutex };
|
||||
while (!stopped)
|
||||
{
|
||||
|
@ -124,6 +124,6 @@ void nano::hinted_scheduler::run ()
|
|||
|
||||
nano::uint128_t nano::hinted_scheduler::tally_threshold () const
|
||||
{
|
||||
const auto min_tally = (online_reps.trended () / 100) * node.config.election_hint_weight_percent;
|
||||
auto min_tally = (online_reps.trended () / 100) * node.config.election_hint_weight_percent;
|
||||
return min_tally;
|
||||
}
|
||||
|
|
|
@ -27,11 +27,12 @@ public: // Config
|
|||
};
|
||||
|
||||
public:
|
||||
explicit hinted_scheduler (config const &, nano::node &, nano::vote_cache &, nano::active_transactions &, nano::online_reps &, nano::stats &);
|
||||
hinted_scheduler (config const &, nano::node &, nano::vote_cache &, nano::active_transactions &, nano::online_reps &, nano::stats &);
|
||||
~hinted_scheduler ();
|
||||
|
||||
void start ();
|
||||
void stop ();
|
||||
|
||||
/*
|
||||
* Notify about changes in AEC vacancy
|
||||
*/
|
||||
|
@ -54,7 +55,7 @@ private: // Dependencies
|
|||
private:
|
||||
config const config_m;
|
||||
|
||||
bool stopped;
|
||||
bool stopped{ false };
|
||||
nano::condition_variable condition;
|
||||
mutable nano::mutex mutex;
|
||||
std::thread thread;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue