Fixed data races

pull/238/head
SChernykh 2023-02-27 19:23:14 +01:00
parent 2807f9a51c
commit 0ce1558f54
4 changed files with 8 additions and 6 deletions

View File

@ -668,9 +668,8 @@ void p2pool::update_block_template()
{
MinerData data = miner_data();
if (m_updateSeed) {
if (m_updateSeed.exchange(false)) {
m_hasher->set_seed_async(data.seed_hash);
m_updateSeed = false;
}
m_blockTemplate->update(data, *m_mempool, &m_params->m_wallet);
stratum_on_block();

View File

@ -119,7 +119,7 @@ private:
SideChain* m_sideChain;
RandomX_Hasher_Base* m_hasher;
BlockTemplate* m_blockTemplate;
bool m_updateSeed;
std::atomic<bool> m_updateSeed;
Mempool* m_mempool;
mutable uv_rwlock_t m_mainchainLock;

View File

@ -1228,11 +1228,14 @@ void StratumServer::api_update_local_stats(uint64_t timestamp)
}
// Rate limit to no more than once in 60 seconds.
if (timestamp < m_apiLastUpdateTime + 60) {
uint64_t t = m_apiLastUpdateTime.load();
if (timestamp < t + 60) {
return;
}
m_apiLastUpdateTime = timestamp;
if (!m_apiLastUpdateTime.compare_exchange_strong(t, timestamp)) {
return;
}
uint64_t hashes_15m, hashes_1h, hashes_24h, total_hashes;
int64_t dt_15m, dt_1h, dt_24h;

View File

@ -188,7 +188,7 @@ private:
uint32_t m_totalFoundShares;
uint32_t m_totalFailedShares;
uint64_t m_apiLastUpdateTime;
std::atomic<uint64_t> m_apiLastUpdateTime;
void update_hashrate_data(uint64_t hashes, uint64_t timestamp);
void api_update_local_stats(uint64_t timestamp);