diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2019-10-29 12:35:06 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2019-11-12 15:35:26 -0800 |
commit | 64e1e022cedf6776c5dffd488ca2e766adca5dc3 (patch) | |
tree | 9391261422d31946cf184a5fbb599649b48625aa /src | |
parent | d61f2bb076d8f17840a8e79f1583d7f6e3e6d09a (diff) |
Use thread-safe atomic in perfmon seeder
Also switch to chrono based types.
Diffstat (limited to 'src')
-rw-r--r-- | src/randomenv.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/randomenv.cpp b/src/randomenv.cpp index 05be090d93..603c88eaab 100644 --- a/src/randomenv.cpp +++ b/src/randomenv.cpp @@ -19,6 +19,7 @@ #endif #include <algorithm> +#include <atomic> #include <chrono> #include <climits> #include <thread> @@ -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; |