Skip to content

Commit

Permalink
Improve mutex for online_reps::sample () (#1672)
Browse files Browse the repository at this point in the history
* Improve mutex for online_reps::sample ()

* Better unordered_set naming
  • Loading branch information
SergiySW committed Jan 31, 2019
1 parent 7237e48 commit ff29448
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nano/node/node.cpp
Expand Up @@ -3424,11 +3424,15 @@ void nano::online_reps::sample ()
}
// Calculate current active rep weight
nano::uint128_t current;
for (auto & i : reps)
std::unordered_set<nano::account> reps_copy;
{
std::lock_guard<std::mutex> lock (mutex);
reps_copy.swap (reps);
}
for (auto & i : reps_copy)
{
current += ledger.weight (transaction, i);
}
reps.clear ();
ledger.store.online_weight_put (transaction, std::chrono::system_clock::now ().time_since_epoch ().count (), current);
auto trend_l (trend (transaction));
std::lock_guard<std::mutex> lock (mutex);
Expand Down

0 comments on commit ff29448

Please sign in to comment.