Skip to content
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

Remove thread_local in dllexported function #1990

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 7 additions & 11 deletions lib/src/Utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1272,24 +1272,20 @@ std::string secureRandomString(size_t size)

// batch up to 32 bytes of random data for efficiency. Calling
// secureRandomBytes can be expensive.
auto randByte = []() {
thread_local trantor::utils::Hash256 hash;
thread_local size_t i = 0;
if (i == 0)
trantor::utils::Hash256 hash;
for (size_t i = 0; i < size; ++i)
{
auto j = i % sizeof(hash);
if (j == 0)
{
bool ok = trantor::utils::secureRandomBytes(&hash, sizeof(hash));
if (!ok)
throw std::runtime_error(
"Failed to generate random bytes for secureRandomString");
}
unsigned char *hashBytes = reinterpret_cast<unsigned char *>(&hash);
auto ret = hashBytes[i];
i = (i + 1) % sizeof(hash);
return ret;
};

for (size_t i = 0; i < size; ++i)
ret[i] = chars[randByte() % 64];
ret[i] = chars[hashBytes[j] % 64];
}
return ret;
}

Expand Down
Loading