Skip to content

Commit f0f0291

Browse files
sipaFuzzbawls
authored andcommitted
Use thread-safe atomic in perfmon seeder
Also switch to chrono based types.
1 parent 948bb36 commit f0f0291

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/randomenv.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#endif
2020

2121
#include <algorithm>
22+
#include <atomic>
2223
#include <chrono>
2324
#include <climits>
2425
#include <thread>
@@ -73,10 +74,11 @@ void RandAddSeedPerfmon(CSHA512& hasher)
7374
// Seed with the entire set of perfmon data
7475

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

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

0 commit comments

Comments
 (0)