From ff29448503e399f789aae534afb430d207813fbe Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Thu, 31 Jan 2019 19:25:52 +0300 Subject: [PATCH] Improve mutex for online_reps::sample () (#1672) * Improve mutex for online_reps::sample () * Better unordered_set naming --- nano/node/node.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 8ad33d0bc6..07a69270f6 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -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 reps_copy; + { + std::lock_guard 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 lock (mutex);