File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-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,18 @@ class TlsRandomNumberGenerator
26
27
TlsRandomNumberGenerator () noexcept
27
28
{
28
29
Seed ();
29
- platform::AtFork (nullptr , nullptr , OnFork);
30
+ if (flag)
31
+ {
32
+ platform::AtFork (nullptr , nullptr , OnFork);
33
+ flag = false ;
34
+ }
30
35
}
31
36
32
37
static FastRandomNumberGenerator &engine () noexcept { return engine_; }
33
38
34
39
private:
40
+ static std::atomic<bool > flag;
41
+
35
42
static thread_local FastRandomNumberGenerator engine_;
36
43
37
44
static void OnFork () noexcept { Seed (); }
@@ -44,6 +51,7 @@ class TlsRandomNumberGenerator
44
51
}
45
52
};
46
53
54
+ std::atomic<bool > TlsRandomNumberGenerator::flag{true };
47
55
thread_local FastRandomNumberGenerator TlsRandomNumberGenerator::engine_{};
48
56
} // namespace
49
57
You can’t perform that action at this time.
0 commit comments