Skip to content

Commit

Permalink
Merge #2368: [Rand] Use thread-safe atomic in perfmon seeder
Browse files Browse the repository at this point in the history
f0f0291 Use thread-safe atomic in perfmon seeder (Pieter Wuille)

Pull request description:

  Follow-up to #2278 now that #2300 has been merged. This pulls in one of the aforementioned commits (bitcoin@64e1e02) that was purposely left out of #2278

ACKs for top commit:
  furszy:
    utACK f0f0291
  random-zebra:
    utACK f0f0291 and merging...

Tree-SHA512: 2071bc007701acf1cdb2ab758ea3cddea14bc7c447d32095647e7f21e45dbd274bba01939c5f71ec54952577ad1536924e5fcce1928a1e645b91f99f2f714f90
  • Loading branch information
random-zebra committed May 6, 2021
2 parents dcf22ba + f0f0291 commit cc88a6f
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 cc88a6f

Please sign in to comment.