Fix possible race condition in hashrate counting code

Use single atomic operation to switch between data points.
This commit is contained in:
SChernykh 2020-10-09 10:29:18 +02:00
parent d9b6f46a6a
commit a4550f55ea
4 changed files with 35 additions and 21 deletions

View file

@ -44,8 +44,7 @@ public:
inline const VirtualMemory *memory() const override { return nullptr; }
inline size_t id() const override { return m_id; }
inline uint64_t hashCount() const override { return m_hashCount.load(std::memory_order_relaxed); }
inline uint64_t timestamp() const override { return m_timestamp.load(std::memory_order_relaxed); }
void getHashrateData(uint64_t& hashCount, uint64_t& timeStamp) const override;
inline void jobEarlyNotification(const Job&) override {}
protected:
@ -53,8 +52,9 @@ protected:
const int64_t m_affinity;
const size_t m_id;
std::atomic<uint64_t> m_hashCount;
std::atomic<uint64_t> m_timestamp;
uint64_t m_hashCount[2] = {};
uint64_t m_timestamp[2] = {};
std::atomic<uint32_t> m_index;
uint32_t m_node = 0;
uint64_t m_count = 0;
};