Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Apparently referencing the thread_local global invokes the
__tls_get_addr helper that reconstructs the object...
  • Loading branch information
mniip committed May 12, 2018
1 parent 99f7258 commit 11d7735
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/common/String.cpp
Expand Up @@ -294,14 +294,16 @@ char const numberChars[] = "-.+0123456789ABCDEFXabcdefx";
ByteString numberByteString(numberChars);
String numberString(numberChars);

static thread_local std::basic_stringstream<char> *LocaleImplStream;
static thread_local std::basic_stringstream<wchar_t> *LocaleImplWStream;
static thread_local struct LocaleImpl
{
std::basic_stringstream<char> &stream;
std::basic_stringstream<wchar_t> &wstream;

LocaleImpl():
stream(*new std::basic_stringstream<char>()),
wstream(*new std::basic_stringstream<wchar_t>())
stream(*(LocaleImplStream = new std::basic_stringstream<char>())),
wstream(*(LocaleImplWStream = new std::basic_stringstream<wchar_t>()))
{
stream.imbue(std::locale::classic());
wstream.imbue(std::locale::classic());
Expand Down Expand Up @@ -380,15 +382,11 @@ LocaleImpl;
// This specific implementation of destruction seems to help against the
// currently broken WIN32 threading model on MinGW. The real destructor is
// called by the runtime as cdecl but the compiled code expects thiscall.
static destroyLocaleImpl()
{
delete &LocaleImpl.stream;
delete &LocaleImpl.wstream;
}

LocaleImpl::~LocaleImpl()
{
destroyLocaleImpl();
delete LocaleImplStream;
delete LocaleImplWStream;
}

ByteString ByteStringBuilder::Build() const
Expand Down

0 comments on commit 11d7735

Please sign in to comment.