Permalink
Browse files

Work around a thread_local bug in MinGW with the WIN32 threading model

  • Loading branch information...
mniip committed May 12, 2018
1 parent 1963713 commit 99f725888cff96f02b49e41f74ccf4076fee099c
Showing with 21 additions and 3 deletions.
  1. +21 −3 src/common/String.cpp
@@ -296,15 +296,19 @@ String numberString(numberChars);
static thread_local struct LocaleImpl
{
std::basic_stringstream<char> stream;
std::basic_stringstream<wchar_t> wstream;
std::basic_stringstream<char> &stream;
std::basic_stringstream<wchar_t> &wstream;
LocaleImpl()
LocaleImpl():
stream(*new std::basic_stringstream<char>()),
wstream(*new std::basic_stringstream<wchar_t>())
{
stream.imbue(std::locale::classic());
wstream.imbue(std::locale::classic());
}
~LocaleImpl();
inline void PrepareStream(ByteStringBuilder &b)
{
stream.flags(b.flags);
@@ -373,6 +377,20 @@ static thread_local struct LocaleImpl
}
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();
}
ByteString ByteStringBuilder::Build() const
{
return ByteString(buffer.begin(), buffer.end());

0 comments on commit 99f7258

Please sign in to comment.