From 858463ceba92803c27e5942b313ee0685d172bc7 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Fri, 9 Oct 2020 11:50:11 +0200 Subject: [PATCH] Change to fetch_xor to make code simpler --- src/backend/common/Worker.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend/common/Worker.cpp b/src/backend/common/Worker.cpp index d2269300..a8dd24ab 100644 --- a/src/backend/common/Worker.cpp +++ b/src/backend/common/Worker.cpp @@ -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];