Skip to content

Eliminate a global constructor from the runtime #1983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions stdlib/public/stubs/LibcShims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,21 @@ size_t _swift_stdlib_malloc_size(const void *ptr) {
#error No malloc_size analog known for this platform/libc.
#endif

static std::mt19937 MersenneRandom;
static std::mt19937 &getGlobalMT19937() {
static std::mt19937 MersenneRandom;
return MersenneRandom;
}

__swift_uint32_t _swift_stdlib_cxx11_mt19937(void) {
return MersenneRandom();
__swift_uint32_t _swift_stdlib_cxx11_mt19937() {
return getGlobalMT19937()();
}

__swift_uint32_t
_swift_stdlib_cxx11_mt19937_uniform(__swift_uint32_t upper_bound) {
if (upper_bound > 0)
upper_bound--;
std::uniform_int_distribution<__swift_uint32_t> RandomUniform(0, upper_bound);
return RandomUniform(MersenneRandom);
return RandomUniform(getGlobalMT19937());
}

} // namespace swift
Expand Down