Skip to content

Commit 99ebb1f

Browse files
committed
Merge pull request #1983 from apple/eliminate-global-constructor-from-runtime
2 parents 61248de + 9ee833a commit 99ebb1f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

stdlib/public/stubs/LibcShims.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,21 @@ size_t _swift_stdlib_malloc_size(const void *ptr) {
6666
#error No malloc_size analog known for this platform/libc.
6767
#endif
6868

69-
static std::mt19937 MersenneRandom;
69+
static std::mt19937 &getGlobalMT19937() {
70+
static std::mt19937 MersenneRandom;
71+
return MersenneRandom;
72+
}
7073

71-
__swift_uint32_t _swift_stdlib_cxx11_mt19937(void) {
72-
return MersenneRandom();
74+
__swift_uint32_t _swift_stdlib_cxx11_mt19937() {
75+
return getGlobalMT19937()();
7376
}
7477

7578
__swift_uint32_t
7679
_swift_stdlib_cxx11_mt19937_uniform(__swift_uint32_t upper_bound) {
7780
if (upper_bound > 0)
7881
upper_bound--;
7982
std::uniform_int_distribution<__swift_uint32_t> RandomUniform(0, upper_bound);
80-
return RandomUniform(MersenneRandom);
83+
return RandomUniform(getGlobalMT19937());
8184
}
8285

8386
} // namespace swift

0 commit comments

Comments
 (0)