Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hinted_scheduler stop #4079

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions nano/node/hinted_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
5 changes: 3 additions & 2 deletions nano/node/hinted_scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ class hinted_scheduler final
};

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
*/
Expand All @@ -54,7 +55,7 @@ class hinted_scheduler final
private:
config const config_m;

bool stopped;
bool stopped{ false };
nano::condition_variable condition;
mutable nano::mutex mutex;
std::thread thread;
Expand Down