mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
perf: NodesSnapshot, do not hold m_nodes_mutex while shuffling
This commit is contained in:
parent
7c00c868d8
commit
c005011e84
16
src/net.cpp
16
src/net.cpp
@ -5118,16 +5118,16 @@ bool CConnman::IsMasternodeOrDisconnectRequested(const CService& addr) {
|
|||||||
CConnman::NodesSnapshot::NodesSnapshot(const CConnman& connman, std::function<bool(const CNode* pnode)> filter,
|
CConnman::NodesSnapshot::NodesSnapshot(const CConnman& connman, std::function<bool(const CNode* pnode)> filter,
|
||||||
bool shuffle)
|
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) {
|
for (auto& node : connman.m_nodes) {
|
||||||
if (!filter(node))
|
if (!filter(node)) continue;
|
||||||
continue;
|
node->AddRef();
|
||||||
node->AddRef();
|
m_nodes_copy.push_back(node);
|
||||||
m_nodes_copy.push_back(node);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shuffle) {
|
if (shuffle) {
|
||||||
Shuffle(m_nodes_copy.begin(), m_nodes_copy.end(), FastRandomContext{});
|
Shuffle(m_nodes_copy.begin(), m_nodes_copy.end(), FastRandomContext{});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user