Skip to content

Commit

Permalink
Use thread-safe atomic in perfmon seeder
Browse files Browse the repository at this point in the history
Also switch to chrono based types.
  • Loading branch information
sipa authored and Fuzzbawls committed May 6, 2021
1 parent 948bb36 commit f0f0291
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/randomenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#endif

#include <algorithm>
#include <atomic>
#include <chrono>
#include <climits>
#include <thread>
Expand Down Expand Up @@ -73,10 +74,11 @@ void RandAddSeedPerfmon(CSHA512& hasher)
// Seed with the entire set of perfmon data

// This can take up to 2 seconds, so only do it every 10 minutes
static int64_t nLastPerfmon;
if (GetTime() < nLastPerfmon + 10 * 60)
return;
nLastPerfmon = GetTime();
static std::atomic<std::chrono::seconds> last_perfmon{std::chrono::seconds{0}};
auto last_time = last_perfmon.load();
auto current_time = GetTime<std::chrono::seconds>();
if (current_time < last_time + std::chrono::minutes{10}) return;
last_perfmon = current_time;

std::vector<unsigned char> vData(250000, 0);
long ret = 0;
Expand Down

0 comments on commit f0f0291

Please sign in to comment.