From 9e7666d12fc7a7772e8e8eee1db6e51a23a97335 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sat, 28 May 2022 20:47:49 +0200 Subject: [PATCH] Fixed data races --- src/block_template.cpp | 2 +- src/block_template.h | 3 +-- src/p2p_server.h | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/block_template.cpp b/src/block_template.cpp index 9dd0738..68d1317 100644 --- a/src/block_template.cpp +++ b/src/block_template.cpp @@ -115,7 +115,7 @@ BlockTemplate& BlockTemplate::operator=(const BlockTemplate& b) m_extraNonceOffsetInTemplate = b.m_extraNonceOffsetInTemplate; m_numTransactionHashes = b.m_numTransactionHashes; m_prevId = b.m_prevId; - m_height = b.m_height; + m_height = b.m_height.load(); m_difficulty = b.m_difficulty; m_seedHash = b.m_seedHash; m_timestamp = b.m_timestamp; diff --git a/src/block_template.h b/src/block_template.h index 1b988a0..5b02fba 100644 --- a/src/block_template.h +++ b/src/block_template.h @@ -50,7 +50,6 @@ public: void update_tx_keys(); FORCEINLINE uint64_t height() const { return m_height; } - FORCEINLINE uint64_t timestamp() const { return m_timestamp; } FORCEINLINE difficulty_type difficulty() const { return m_difficulty; } void submit_sidechain_block(uint32_t template_id, uint32_t nonce, uint32_t extra_nonce); @@ -83,7 +82,7 @@ private: size_t m_numTransactionHashes; hash m_prevId; - uint64_t m_height; + std::atomic m_height; difficulty_type m_difficulty; hash m_seedHash; diff --git a/src/p2p_server.h b/src/p2p_server.h index 35cc3e0..9e70054 100644 --- a/src/p2p_server.h +++ b/src/p2p_server.h @@ -133,7 +133,7 @@ public: void print_status() override; void show_peers(); - size_t peer_list_size() const { return m_peerList.size(); } + size_t peer_list_size() const { MutexLock lock(m_peerListLock); return m_peerList.size(); } uint32_t max_outgoing_peers() const { return m_maxOutgoingPeers; } uint32_t max_incoming_peers() const { return m_maxIncomingPeers; } @@ -181,7 +181,7 @@ private: uint64_t m_peerId; - uv_mutex_t m_peerListLock; + mutable uv_mutex_t m_peerListLock; struct Peer { @@ -194,7 +194,7 @@ private: std::vector m_peerList; std::vector m_peerListMonero; - uint64_t m_peerListLastSaved; + std::atomic m_peerListLastSaved; struct Broadcast {