Skip to content

Commit

Permalink
perf: NodesSnapshot, do not hold m_nodes_mutex while shuffling
Browse files Browse the repository at this point in the history
  • Loading branch information
PastaPastaPasta committed Dec 9, 2024
1 parent 84fe2be commit 8098d9d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5118,16 +5118,16 @@ bool CConnman::IsMasternodeOrDisconnectRequested(const CService& addr) {
CConnman::NodesSnapshot::NodesSnapshot(const CConnman& connman, std::function<bool(const CNode* pnode)> filter,
bool shuffle)
{
LOCK(connman.m_nodes_mutex);
m_nodes_copy.reserve(connman.m_nodes.size());
{
LOCK(connman.m_nodes_mutex);
m_nodes_copy.reserve(connman.m_nodes.size());

for (auto& node : connman.m_nodes) {
if (!filter(node))
continue;
node->AddRef();
m_nodes_copy.push_back(node);
for (auto& node : connman.m_nodes) {
if (!filter(node)) continue;
node->AddRef();
m_nodes_copy.push_back(node);
}
}

if (shuffle) {
Shuffle(m_nodes_copy.begin(), m_nodes_copy.end(), FastRandomContext{});
}
Expand Down

0 comments on commit 8098d9d

Please sign in to comment.