File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 5
5
#include " src/common/random.h"
6
6
#include " src/common/platform/fork.h"
7
7
8
+ #include < atomic>
8
9
#include < cstring>
9
10
#include < random>
10
11
@@ -26,12 +27,17 @@ class TlsRandomNumberGenerator
26
27
TlsRandomNumberGenerator () noexcept
27
28
{
28
29
Seed ();
29
- platform::AtFork (nullptr , nullptr , OnFork);
30
+ if (!flag.test_and_set ())
31
+ {
32
+ platform::AtFork (nullptr , nullptr , OnFork);
33
+ }
30
34
}
31
35
32
36
static FastRandomNumberGenerator &engine () noexcept { return engine_; }
33
37
34
38
private:
39
+ static std::atomic_flag flag;
40
+
35
41
static thread_local FastRandomNumberGenerator engine_;
36
42
37
43
static void OnFork () noexcept { Seed (); }
@@ -44,6 +50,7 @@ class TlsRandomNumberGenerator
44
50
}
45
51
};
46
52
53
+ std::atomic_flag TlsRandomNumberGenerator::flag;
47
54
thread_local FastRandomNumberGenerator TlsRandomNumberGenerator::engine_{};
48
55
} // namespace
49
56
You can’t perform that action at this time.
0 commit comments