Change to fetch_xor to make code simpler

This commit is contained in:
SChernykh 2020-10-09 11:50:11 +02:00
parent a4550f55ea
commit 858463ceba

View file

@ -43,8 +43,8 @@ xmrig::Worker::Worker(size_t id, int64_t affinity, int priority) :
void xmrig::Worker::storeStats()
{
// Get next index which is unused now
const uint32_t index = (m_index.load(std::memory_order_relaxed) + 1) & 1;
// Get index which is unused now
const uint32_t index = m_index.load(std::memory_order_relaxed) ^ 1;
// Fill in the data for that index
m_hashCount[index] = m_count;
@ -52,13 +52,13 @@ void xmrig::Worker::storeStats()
// Switch to that index
// All data will be in memory by the time it completes thanks to std::memory_order_seq_cst
m_index.fetch_add(1, std::memory_order_seq_cst);
m_index.fetch_xor(1, std::memory_order_seq_cst);
}
void xmrig::Worker::getHashrateData(uint64_t& hashCount, uint64_t& timeStamp) const
{
const uint32_t index = m_index.load(std::memory_order_relaxed) & 1;
const uint32_t index = m_index.load(std::memory_order_relaxed);
hashCount = m_hashCount[index];
timeStamp = m_timestamp[index];