Skip to content

Commit

Permalink
Merge pull request #8 from hd4r/hashrate_calc_threadsafe
Browse files Browse the repository at this point in the history
Make hashrate calculation thread-safe
  • Loading branch information
effectsToCause committed Oct 9, 2017
2 parents eba1c07 + 1b2b793 commit 652f074
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,25 +544,28 @@ void Miner(CWallet *pwallet)

// Hash meter
static int64_t nHashCounter;
if (nHPSTimerStart == 0)
{
nHPSTimerStart = GetTimeMillis();
nHashCounter = 0;
}
else
nHashCounter += nHashesDone;
if (GetTimeMillis() - nHPSTimerStart > timeElapsed)
{
static CCriticalSection cs;
{
LOCK(cs);
if (GetTimeMillis() - nHPSTimerStart > timeElapsed)
if (nHPSTimerStart == 0)
{
dHashesPerMin = 60000.0 * nHashCounter / (GetTimeMillis() - nHPSTimerStart);
nHPSTimerStart = GetTimeMillis();
nHashCounter = 0;
updateHashrate(dHashesPerMin);
printf("Total local hashrate %6.0f hashes/min\n", hashrate);
}
else
nHashCounter += nHashesDone;

if (GetTimeMillis() - nHPSTimerStart > timeElapsed)
{
if (GetTimeMillis() - nHPSTimerStart > timeElapsed)
{
dHashesPerMin = 60000.0 * nHashCounter / (GetTimeMillis() - nHPSTimerStart);
nHPSTimerStart = GetTimeMillis();
nHashCounter = 0;
updateHashrate(dHashesPerMin);
printf("Total local hashrate %6.0f hashes/min\n", hashrate);
}
}
}
}
Expand Down

0 comments on commit 652f074

Please sign in to comment.