From 7eec4d742c15528564e74341415c546d08681984 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 22 Nov 2022 09:57:50 +0100 Subject: [PATCH] P2PServer: removed an unnecessary lock --- src/p2p_server.cpp | 9 ++++----- src/p2p_server.h | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index 1d8835b..6ae4bb7 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -86,7 +86,6 @@ P2PServer::P2PServer(p2pool* pool) set_max_outgoing_peers(params.m_maxOutgoingPeers); set_max_incoming_peers(params.m_maxIncomingPeers); - uv_mutex_init_checked(&m_rngLock); uv_mutex_init_checked(&m_blockLock); uv_mutex_init_checked(&m_peerListLock); uv_mutex_init_checked(&m_broadcastLock); @@ -142,7 +141,6 @@ P2PServer::~P2PServer() { shutdown_tcp(); - uv_mutex_destroy(&m_rngLock); uv_mutex_destroy(&m_blockLock); uv_mutex_destroy(&m_peerListLock); uv_mutex_destroy(&m_broadcastLock); @@ -365,10 +363,9 @@ void P2PServer::update_peer_connections() void P2PServer::update_peer_list() { - const uint64_t cur_time = seconds_since_epoch(); - MutexLock lock(m_clientsListLock); + const uint64_t cur_time = seconds_since_epoch(); for (P2PClient* client = static_cast(m_connectedClientsList->m_next); client != m_connectedClientsList; client = static_cast(client->m_next)) { if (client->is_good() && (cur_time >= client->m_nextOutgoingPeerListRequest)) { send_peer_list_request(client, cur_time); @@ -934,7 +931,9 @@ void P2PServer::on_broadcast() uint64_t P2PServer::get_random64() { - MutexLock lock(m_rngLock); + if (!server_event_loop_thread) { + LOGERR(1, "get_random64() was called from another thread, this is not thread safe"); + } return m_rng(); } diff --git a/src/p2p_server.h b/src/p2p_server.h index 5a63ea2..a1fff51 100644 --- a/src/p2p_server.h +++ b/src/p2p_server.h @@ -189,7 +189,6 @@ private: void remove_peer_from_list(P2PClient* client); void remove_peer_from_list(const raw_ip& ip); - uv_mutex_t m_rngLock; std::mt19937_64 m_rng; uv_mutex_t m_blockLock;