Try to fix MSVC build.
This commit is contained in:
parent
88f8ddd70c
commit
781a4e667d
@ -1230,29 +1230,29 @@ public:
|
|||||||
else {
|
else {
|
||||||
RAPIDJSON_ASSERT(false); // see above note
|
RAPIDJSON_ASSERT(false); // see above note
|
||||||
|
|
||||||
// Use thread-local storage to prevent races between threads.
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
|
||||||
// MSVC 2013 or earlier does not support `thread_local` attribute even in C++11
|
|
||||||
// mode.
|
|
||||||
#define RAPIDJSON_THREAD_LOCAL __declspec(thread)
|
|
||||||
#elif RAPIDJSON_HAS_CXX11
|
|
||||||
#define RAPIDJSON_THREAD_LOCAL thread_local
|
|
||||||
#elif defined(__GNUC__) || defined(__clang__)
|
|
||||||
#define RAPIDJSON_THREAD_LOCAL __thread
|
|
||||||
#else
|
|
||||||
#define RAPIDJSON_THREAD_LOCAL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if RAPIDJSON_HAS_CXX11
|
#if RAPIDJSON_HAS_CXX11
|
||||||
// Use static buffer and placement-new to prevent destruction.
|
// Use thread-local storage to prevent races between threads.
|
||||||
alignas(GenericValue) RAPIDJSON_THREAD_LOCAL static char buffer[sizeof(GenericValue)];
|
// Use static buffer and placement-new to prevent destruction, with
|
||||||
|
// alignas() to ensure proper alignment.
|
||||||
|
alignas(GenericValue) thread_local static char buffer[sizeof(GenericValue)];
|
||||||
return *new (buffer) GenericValue();
|
return *new (buffer) GenericValue();
|
||||||
|
#elif defined(_MSC_VER) && _MSC_VER < 1900
|
||||||
|
// There's no way to solve both thread locality and proper alignment
|
||||||
|
// simultaneously.
|
||||||
|
__declspec(thread) static char buffer[sizeof(GenericValue)];
|
||||||
|
return *new (buffer) GenericValue();
|
||||||
|
#elif defined(__GNUC__) || defined(__clang__)
|
||||||
|
// This will generate -Wexit-time-destructors in clang, but that's
|
||||||
|
// better than having under-alignment.
|
||||||
|
__thread static GenericValue buffer;
|
||||||
|
return buffer;
|
||||||
#else
|
#else
|
||||||
// This will generate -Wexit-time-destructors in clang.
|
// Don't know what compiler this is, so don't know how to ensure
|
||||||
RAPIDJSON_THREAD_LOCAL static GenericValue buffer;
|
// thread-locality.
|
||||||
|
static GenericValue buffer;
|
||||||
return buffer;
|
return buffer;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <typename SourceAllocator>
|
template <typename SourceAllocator>
|
||||||
const GenericValue& operator[](const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this)[name]; }
|
const GenericValue& operator[](const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this)[name]; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user