Skip to content

Commit

Permalink
telemetry: Add mutex to avoid push during recalc and other races
Browse files Browse the repository at this point in the history
  • Loading branch information
Spudz76 committed Sep 24, 2018
1 parent dfcb774 commit f03319c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions xmrstak/misc/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ telemetry::telemetry(size_t iThd)

double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread)
{
std::unique_lock<std::mutex> lk(mtx);
uint64_t iTimeNow = get_timestamp_ms();

uint64_t iEarliestHashCnt = 0;
Expand Down Expand Up @@ -98,6 +99,7 @@ double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread)

void telemetry::push_perf_value(size_t iThd, uint64_t iHashCount, uint64_t iTimestamp)
{
std::unique_lock<std::mutex> lk(mtx);
size_t iTop = iBucketTop[iThd];
ppHashCounts[iThd][iTop] = iHashCount;
ppTimestamps[iThd][iTop] = iTimestamp;
Expand Down
2 changes: 2 additions & 0 deletions xmrstak/misc/telemetry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdint>
#include <cstring>
#include <mutex>

namespace xmrstak
{
Expand All @@ -14,6 +15,7 @@ class telemetry
double calc_telemetry_data(size_t iLastMillisec, size_t iThread);

private:
mutable std::mutex mtx;
constexpr static size_t iBucketSize = 2 << 11; //Power of 2 to simplify calculations
constexpr static size_t iBucketMask = iBucketSize - 1;
uint32_t* iBucketTop;
Expand Down

0 comments on commit f03319c

Please sign in to comment.