From 64e1e022cedf6776c5dffd488ca2e766adca5dc3 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 29 Oct 2019 12:35:06 -0700 Subject: [PATCH] Use thread-safe atomic in perfmon seeder Also switch to chrono based types. --- src/randomenv.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/randomenv.cpp b/src/randomenv.cpp index 05be090d932..603c88eaabe 100644 --- a/src/randomenv.cpp +++ b/src/randomenv.cpp @@ -19,6 +19,7 @@ #endif #include +#include #include #include #include @@ -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 last_perfmon{std::chrono::seconds{0}}; + auto last_time = last_perfmon.load(); + auto current_time = GetTime(); + if (current_time < last_time + std::chrono::minutes{10}) return; + last_perfmon = current_time; std::vector vData(250000, 0); long ret = 0;